]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Windows gdb+gdbserver: Share exit status logic
authorPedro Alves <pedro@palves.net>
Wed, 20 May 2026 10:45:57 +0000 (11:45 +0100)
committerPedro Alves <pedro@palves.net>
Fri, 12 Jun 2026 13:57:21 +0000 (14:57 +0100)
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

gdb/nat/windows-nat.c
gdb/nat/windows-nat.h
gdb/windows-nat.c
gdbserver/win32-low.cc

index b093acda342b4cb4bc1fd12f71a2718fcbb566a2..92f9394ca6db69ce58350b800e2ca74bffe5b34d 100644 (file)
@@ -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)
 {
index 2b23978712623f6f66b8322a3bf67ac110f0c3a4..d842fa850e60c013edd7d556448ef567c04242a2 100644 (file)
@@ -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
index a7cf8692d41cad469491505a810b9aca957eef0f..1f82dee0e49327a1c48df852a106d73c2cc07862 100644 (file)
@@ -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;
 
index 1931c66871f2c6d4579da5a41ac8e13142a5b3f1..511e034cb71557d679625eef66388d17670612dd 100644 (file)
@@ -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;