Re: [hatari-devel] Hatari debug mode

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

On 17.8.2025 23.19, Christian Zietz wrote:
Shouldn't Hatari skip "freopen()" calls if allocConsole() fails (=
returns zero)?

It probably wouldn't hurt implementing it in that way.

Just to make sure everything works as expected before pushing, could you try the updated (attached) patch too?


	- Eero
From c05ac5a0961b807af935246f1f0a9f6fe6406f88 Mon Sep 17 00:00:00 2001
From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
Date: Mon, 28 Jul 2025 02:30:58 +0300
Subject: [PATCH] Open Windows console automatically for Debugger

---
 doc/release-notes.txt |  1 +
 src/debug/debugui.c   |  4 ++++
 src/gui-win/opencon.c | 13 +++++++++----
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/doc/release-notes.txt b/doc/release-notes.txt
index 75aa341d..974140ed 100644
--- a/doc/release-notes.txt
+++ b/doc/release-notes.txt
@@ -24,6 +24,7 @@ Emulation improvements:
 
 Emulator improvements:
 - Debugger:
+  - Open Windows console automatically for debugger
   - Debugger input file commands can be split to multiple lines
     by adding '\' to end of line to continue it
   - Increase max lenght of accepted debugger file commands to 4k
diff --git a/src/debug/debugui.c b/src/debug/debugui.c
index a2702e6b..d8b43ec2 100644
--- a/src/debug/debugui.c
+++ b/src/debug/debugui.c
@@ -1231,6 +1231,10 @@ void DebugUI(debug_reason_t reason)
 
 	if (welcome)
 	{
+#ifdef WIN32
+		/* in case user forgot -W option */
+		Win_ForceCon();
+#endif
 		fputs(welcome, stderr);
 		welcome = NULL;
 	}
diff --git a/src/gui-win/opencon.c b/src/gui-win/opencon.c
index 60147444..60683436 100644
--- a/src/gui-win/opencon.c
+++ b/src/gui-win/opencon.c
@@ -24,10 +24,15 @@ static void Win_OpenInternal(void)
 		return;
 	opened = true;
 
-	AllocConsole();
-	freopen("CON", "w", stdout);
-	freopen("CON", "r", stdin);
-	freopen("CON", "w", stderr);
+	/* Fails if process already has a console, returns true on success:
+	 * https://learn.microsoft.com/en-us/windows/console/allocconsole
+	 */
+	if (AllocConsole())
+	{
+		freopen("CON", "w", stdout);
+		freopen("CON", "r", stdin);
+		freopen("CON", "w", stderr);
+	}
 }
 
 void Win_OpenCon(void)
-- 
2.39.5



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/