From 559e7e5056e0671f2f248e1f9c2af849bfe3e64b Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 6 Jan 2020 11:51:54 +0000 Subject: Improve process exit status macros on MinGW When a Windows program is terminated by a fatal exception, its exit code is the value of that exception, as defined by the various EXCEPTION_* symbols in the Windows API headers. This commit emulates WTERMSIG etc. by translating the fatal exception codes to more-or-less equivalent Posix signals. gdb/ChangeLog: 2020-01-06 Eli Zaretskii Pedro Alves * Makefile.in (COMMON_SFILES): Add gdbsupport/gdb_wait.c. * windows-tdep.c: New enumeration of WINDOWS_SIG* signals. (windows_gdb_signal_to_target): New function, uses the above enumeration to convert GDB internal signal codes to equivalent Windows codes. (windows_init_abi): Call set_gdbarch_gdb_signal_to_target. * windows-nat.c: Include "gdb_wait.h". (get_windows_debug_event): Extract the fatal exception from the exit status and convert to the equivalent Posix signal number. * cli/cli-cmds.c (exit_status_set_internal_vars): Account for the possibility that WTERMSIG returns GDB_SIGNAL_UNKNOWN. * gdbsupport/gdb_wait.c: New file, implements windows_status_to_termsig. * gdbsupport/gdb_wait.h (WIFEXITED, WIFSIGNALED, WEXITSTATUS) (WTERMSIG) [__MINGW32__]: Separate definitions for MinGW. gdb/gdbserver/ChangeLog: 2020-01-06 Eli Zaretskii Pedro Alves * win32-low.c (get_child_debug_event): Extract the fatal exception from the exit status and convert to the equivalent Posix signal number. (win32_wait): Allow TARGET_WAITKIND_SIGNALLED status as well. * Makefile.in (OBS, SFILES): Add gdb_wait.[co]. --- gdb/cli/cli-cmds.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'gdb/cli') diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 0b55a12..c2ba3a4 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -800,6 +800,18 @@ exit_status_set_internal_vars (int exit_status) clear_internalvar (var_signal); if (WIFEXITED (exit_status)) set_internalvar_integer (var_code, WEXITSTATUS (exit_status)); +#ifdef __MINGW32__ + else if (WIFSIGNALED (exit_status) && WTERMSIG (exit_status) == -1) + { + /* The -1 condition can happen on MinGW, if we don't recognize + the fatal exception code encoded in the exit status; see + gdbsupport/gdb_wait.c. We don't want to lose information in + the exit status in that case. Record it as a normal exit + with the full exit status, including the higher 0xC0000000 + bits. */ + set_internalvar_integer (var_code, exit_status); + } +#endif else if (WIFSIGNALED (exit_status)) set_internalvar_integer (var_signal, WTERMSIG (exit_status)); else -- cgit v1.1