From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 07/11] Windows gdb+gdbserver: Share exit status logic
Date: Mon, 25 May 2026 20:18:25 +0100 [thread overview]
Message-ID: <20260525191829.984105-8-pedro@palves.net> (raw)
In-Reply-To: <20260525191829.984105-1-pedro@palves.net>
Move the exit status logic added by commit 559e7e5056 ("Improve
process exit status macros on MinGW") from both GDB and GDBserver to a
shared routine used by both.
The next patch extends this routine with Cygwin-specific decoding.
Change-Id: I4bf08c6beff0d1688064a81d49bbdd615643735e
commit-id: 586becd8
---
gdb/nat/windows-nat.c | 24 ++++++++++++++++++++++++
gdb/nat/windows-nat.h | 6 ++++++
gdb/windows-nat.c | 15 +++------------
gdbserver/win32-low.cc | 16 +++-------------
4 files changed, 36 insertions(+), 25 deletions(-)
diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c
index b093acda342..92f9394ca6d 100644
--- a/gdb/nat/windows-nat.c
+++ b/gdb/nat/windows-nat.c
@@ -18,6 +18,8 @@
#include "nat/windows-nat.h"
#include "gdbsupport/common-debug.h"
+#include "gdbsupport/gdb_signals.h"
+#include "gdbsupport/gdb_wait.h"
#include "target/target.h"
#undef GetModuleFileNameEx
@@ -694,6 +696,28 @@ windows_process_info::add_all_dlls ()
/* See nat/windows-nat.h. */
+target_waitstatus
+windows_process_info::exit_process_to_target_status
+ (const EXIT_PROCESS_DEBUG_INFO &info)
+{
+ DWORD exit_code = info.dwExitCode;
+ target_waitstatus tstatus;
+
+ /* If the exit status looks like a fatal exception, but we don't
+ recognize the exception's code, make the original exit status
+ value available, to avoid losing information. */
+ int exit_signal
+ = WIFSIGNALED (exit_code) ? WTERMSIG (exit_code) : -1;
+ if (exit_signal == -1)
+ tstatus.set_exited (exit_code);
+ else
+ tstatus.set_signalled (gdb_signal_from_host (exit_signal));
+
+ return tstatus;
+}
+
+/* See nat/windows-nat.h. */
+
std::string
event_code_to_string (DWORD event_code)
{
diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
index 52378765438..d2e6adb4f40 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -315,6 +315,12 @@ struct windows_process_info
});
}
+ /* Convert an EXIT_PROCESS_DEBUG_EVENT payload to a target wait
+ status. */
+
+ target_waitstatus exit_process_to_target_status
+ (const EXIT_PROCESS_DEBUG_INFO &info);
+
private:
/* Handle MS_VC_EXCEPTION when processing a stop. MS_VC_EXCEPTION is
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index a284438bd36..26333238cfa 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -62,7 +62,6 @@
#include "complaints.h"
#include "gdbsupport/gdb_tilde_expand.h"
#include "gdbsupport/pathstuff.h"
-#include "gdbsupport/gdb_wait.h"
#include "gdbsupport/symbol.h"
#include "inf-loop.h"
@@ -1610,17 +1609,9 @@ windows_nat_target::get_windows_debug_event
}
else if (windows_process->saw_create == 1)
{
- DWORD exit_status = current_event->u.ExitProcess.dwExitCode;
- /* If the exit status looks like a fatal exception, but we
- don't recognize the exception's code, make the original
- exit status value available, to avoid losing
- information. */
- int exit_signal
- = WIFSIGNALED (exit_status) ? WTERMSIG (exit_status) : -1;
- if (exit_signal == -1)
- ourstatus->set_exited (exit_status);
- else
- ourstatus->set_signalled (gdb_signal_from_host (exit_signal));
+ *ourstatus
+ = (windows_process->exit_process_to_target_status
+ (current_event->u.ExitProcess));
thread_id = current_event->dwThreadId;
diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc
index 6f1cf5ed025..550994b0bf2 100644
--- a/gdbserver/win32-low.cc
+++ b/gdbserver/win32-low.cc
@@ -33,7 +33,6 @@
#include <process.h>
#include "gdbsupport/gdb_tilde_expand.h"
#include "gdbsupport/common-inferior.h"
-#include "gdbsupport/gdb_wait.h"
using namespace windows_nat;
@@ -1061,18 +1060,9 @@ get_child_debug_event (DWORD *continue_status,
break;
case EXIT_PROCESS_DEBUG_EVENT:
- {
- DWORD exit_status = current_event->u.ExitProcess.dwExitCode;
- /* If the exit status looks like a fatal exception, but we
- don't recognize the exception's code, make the original
- exit status value available, to avoid losing information. */
- int exit_signal
- = WIFSIGNALED (exit_status) ? WTERMSIG (exit_status) : -1;
- if (exit_signal == -1)
- ourstatus->set_exited (exit_status);
- else
- ourstatus->set_signalled (gdb_signal_from_host (exit_signal));
- }
+ *ourstatus
+ = (windows_process.exit_process_to_target_status
+ (current_event->u.ExitProcess));
continue_last_debug_event (DBG_CONTINUE, debug_threads);
break;
--
2.53.0
next prev parent reply other threads:[~2026-05-25 19:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 19:18 [PATCH v2 00/11] Fix a few Cygwin/MinGW problems Pedro Alves
2026-05-25 19:18 ` [PATCH v2 01/11] Adjust gdb.base/exitsignal.exp for MinGW, trigger fault Pedro Alves
2026-05-25 19:18 ` [PATCH v2 02/11] Adjust gdb.base/exitsignal.exp for MinGW, second-chance SIGSEGV Pedro Alves
2026-05-26 11:18 ` Eli Zaretskii
2026-05-27 12:56 ` Pedro Alves
2026-05-25 19:18 ` [PATCH v2 03/11] Adjust gdb.base/exitsignal.exp for MinGW, separate program names Pedro Alves
2026-05-27 21:59 ` Thiago Jung Bauermann
2026-06-12 14:00 ` Pedro Alves
2026-05-25 19:18 ` [PATCH v2 04/11] gdb.base/exitsignal.exp: Exit with non-zero Pedro Alves
2026-05-25 19:18 ` [PATCH v2 05/11] gdb.base/exitsignal.exp: Test attaching too Pedro Alves
2026-05-25 19:18 ` [PATCH v2 06/11] gdb/testsuite: Add mechanism to compile Windows native programs on Cygwin Pedro Alves
2026-05-25 19:18 ` Pedro Alves [this message]
2026-05-25 19:18 ` [PATCH v2 08/11] Windows gdb+gdbserver: Decode Cygwin ExitProcess codes Pedro Alves
2026-05-26 11:31 ` Eli Zaretskii
2026-05-27 13:58 ` Pedro Alves
2026-05-27 14:12 ` Eli Zaretskii
2026-05-27 22:00 ` Thiago Jung Bauermann
2026-05-25 19:18 ` [PATCH v2 09/11] Adjust gdb.python/py-events.exp for Cygwin/MinGW, thread IDs Pedro Alves
2026-05-25 19:18 ` [PATCH v2 10/11] Adjust gdb.python/py-events.exp for Cygwin/MinGW, no fork Pedro Alves
2026-05-25 19:18 ` [PATCH v2 11/11] Adjust gdb.python/py-events.exp for Cygwin/MinGW, "info proc" => "inferior" Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260525191829.984105-8-pedro@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox