* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
[not found] <271718487.11947642.1578332826544.ref@mail.yahoo.com>
@ 2020-01-06 17:47 ` Hannes Domani via gdb-patches
2020-01-06 18:23 ` Eli Zaretskii
0 siblings, 1 reply; 26+ messages in thread
From: Hannes Domani via gdb-patches @ 2020-01-06 17:47 UTC (permalink / raw)
To: Gdb-patches
While locally fixing a merge-conflict I noticed the following:
Am Freitag, 3. Januar 2020, 20:59:45 MEZ hat Pedro Alves <palves@redhat.com> Folgendes geschrieben:
> Here's the updated patch. I confirmed that it builds on MinGW-W64
> using my Fedora's cross cross compiler, but I didn't try to run
> the resulting GDB (since I'm not on Windows).
> diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
> index ca9b81df298..58f8838b885 100644
> --- a/gdb/windows-tdep.c
> +++ b/gdb/windows-tdep.c
> @@ -35,6 +35,57 @@
> #include "solib-target.h"
> #include "gdbcore.h"
>
> +/* Windows signal numbers differ between MinGW flavors and between
> + those and Cygwin. The below enumeration was gleaned from the
> + respective headers; the ones marked with MinGW64/Cygwin are defined
> + only by MinGW64 and Cygwin, not by mingw.org's MinGW. FIXME: We
> + should really have distinct MinGW vs Cygwin OSABIs, and two
> + separate enums, selected at runtime. */
> +
> +enum
> + {
> + WINDOWS_SIGHUP = 1, /* MinGW64/Cygwin */
> + WINDOWS_SIGINT = 2,
> + WINDOWS_SIGQUIT = 3, /* MinGW64/Cygwin */
> + WINDOWS_SIGILL = 4,
> + WINDOWS_SIGTRAP = 5, /* MinGW64/Cygwin */
> +#ifdef __CYGWIN__
> + WINDOWS_SGABRT = 6,
> +#else
> + WINDOWS_SIGIOT = 6, /* MinGW64 */
> +#endif
> + WINDOWS_SIGEMT = 7, /* MinGW64/Cygwin */
> + WINDOWS_SIGFPE = 8,
> + WINDOWS_SIGKILL = 9, /* MinGW64/Cygwin */
> + WINDOWS_SIGBUS = 10, /* MinGW64/Cygwin */
> + WINDOWS_SIGSEGV = 11,
> + WINDOWS_SIGSYS = 12, /* MinGW64/Cygwin */
> + WINDOWS_SIGPIPE = 13,/* MinGW64/Cygwin */
> + WINDOWS_SIGALRM = 14,/* MinGW64/Cygwin */
> + WINDOWS_SIGTERM = 15,
> +#ifdef __CYGWIN__
> + WINDOWS_SIGURG = 16,
> + WINDOWS_SIGSTOP = 17,
> + WINDOWS_SIGTSTP = 18,
> + WINDOWS_SIGCONT = 19,
> + WINDOWS_SIGCHLD = 20,
> + WINDOWS_SIGTTIN = 21,
> + WINDOWS_SIGTTOU = 22,
> + WINDOWS_SIGIO = 23,
> + WINDOWS_SIGXCPU = 24,
> + WINDOWS_SIGXFSZ = 25,
> + WINDOWS_SIGVTALRM = 26,
> + WINDOWS_SIGPROF = 27,
> + WINDOWS_SIGWINCH = 28,
> + WINDOWS_SIGLOST = 29,
> + WINDOWS_SIGUSR1 = 30,
> + WINDOWS_SIGUSR2 = 31
> +#else
> + WINDOWS_SIGBREAK = 21,
> + WINDOWS_SIGABRT = 22
> +#endif
> + };
For __CYGWIN__ it's WINDOWS_SGABRT, otherwise it's WINDOWS_SIGABRT.
> +
> struct cmd_list_element *info_w32_cmdlist;
>
> typedef struct thread_information_block_32
> @@ -461,6 +512,83 @@ init_w32_command_list (void)
> }
> }
>
> +/* Implementation of `gdbarch_gdb_signal_to_target'. */
> +
> +static int
> +windows_gdb_signal_to_target (struct gdbarch *gdbarch, enum gdb_signal signal)
> +{
> + switch (signal)
> + {
> + case GDB_SIGNAL_0:
> + return 0;
> + case GDB_SIGNAL_HUP:
> + return WINDOWS_SIGHUP;
> + case GDB_SIGNAL_INT:
> + return WINDOWS_SIGINT;
> + case GDB_SIGNAL_QUIT:
> + return WINDOWS_SIGQUIT;
> + case GDB_SIGNAL_ILL:
> + return WINDOWS_SIGILL;
> + case GDB_SIGNAL_TRAP:
> + return WINDOWS_SIGTRAP;
> + case GDB_SIGNAL_ABRT:
> + return WINDOWS_SIGABRT;
I don't think this compiles for cygwin.
> + case GDB_SIGNAL_EMT:
> + return WINDOWS_SIGEMT;
> + case GDB_SIGNAL_FPE:
> + return WINDOWS_SIGFPE;
> + case GDB_SIGNAL_KILL:
> + return WINDOWS_SIGKILL;
> + case GDB_SIGNAL_BUS:
> + return WINDOWS_SIGBUS;
> + case GDB_SIGNAL_SEGV:
> + return WINDOWS_SIGSEGV;
> + case GDB_SIGNAL_SYS:
> + return WINDOWS_SIGSYS;
> + case GDB_SIGNAL_PIPE:
> + return WINDOWS_SIGPIPE;
> + case GDB_SIGNAL_ALRM:
> + return WINDOWS_SIGALRM;
> + case GDB_SIGNAL_TERM:
> + return WINDOWS_SIGTERM;
> +#ifdef __CYGWIN__
> + case GDB_SIGNAL_URG:
> + return WINDOWS_SIGURG;
> + case GDB_SIGNAL_STOP:
> + return WINDOWS_SIGSTOP;
> + case GDB_SIGNAL_TSTP:
> + return WINDOWS_SIGTSTP;
> + case GDB_SIGNAL_CONT:
> + return WINDOWS_SIGCONT;
> + case GDB_SIGNAL_CHLD:
> + return WINDOWS_SIGCHLD;
> + case GDB_SIGNAL_TTIN:
> + return WINDOWS_SIGTTIN;
> + case GDB_SIGNAL_TTOU:
> + return WINDOWS_SIGTTOU;
> + case GDB_SIGNAL_IO:
> + return WINDOWS_SIGIO;
> + case GDB_SIGNAL_XCPU:
> + return WINDOWS_SIGXCPU;
> + case GDB_SIGNAL_XFSZ:
> + return WINDOWS_SIGXFSZ;
> + case GDB_SIGNAL_VTALRM:
> + return WINDOWS_SIGVTALRM;
> + case GDB_SIGNAL_PROF:
> + return WINDOWS_SIGPROF;
> + case GDB_SIGNAL_WINCH:
> + return WINDOWS_SIGWINCH;
> + case GDB_SIGNAL_PWR:
> + return WINDOWS_SIGLOST;
> + case GDB_SIGNAL_USR1:
> + return WINDOWS_SIGUSR1;
> + case GDB_SIGNAL_USR2:
> + return WINDOWS_SIGUSR2;
> +#endif /* __CYGWIN__ */
> + }
> + return -1;
> +}
> +
> /* To be called from the various GDB_OSABI_CYGWIN handlers for the
> various Windows architectures and machine types. */
>
> @@ -477,6 +605,8 @@ windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
> set_gdbarch_iterate_over_objfiles_in_search_order
> (gdbarch, windows_iterate_over_objfiles_in_search_order);
>
> + set_gdbarch_gdb_signal_to_target (gdbarch, windows_gdb_signal_to_target);
> +
> set_solib_ops (gdbarch, &solib_target_so_ops);
> }
>
>
> base-commit: 44f81a76542dbeada2541a05de191ae0ac0fbc2c
> --
> 2.14.5
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2020-01-06 17:47 ` [RFAv3 2/6] Improve process exit status macros on MinGW Hannes Domani via gdb-patches
@ 2020-01-06 18:23 ` Eli Zaretskii
0 siblings, 0 replies; 26+ messages in thread
From: Eli Zaretskii @ 2020-01-06 18:23 UTC (permalink / raw)
To: Hannes Domani; +Cc: gdb-patches
> Date: Mon, 6 Jan 2020 17:47:06 +0000 (UTC)
> From: "Hannes Domani via gdb-patches" <gdb-patches@sourceware.org>
>
> While locally fixing a merge-conflict I noticed the following:
Thanks, pushed the below as obvious.
commit 89a65580f4522f81ef7e4e49298b24f3ebc14355
Author: Eli Zaretskii <eliz@gnu.org>
AuthorDate: Mon Jan 6 20:22:15 2020 +0200
Commit: Eli Zaretskii <eliz@gnu.org>
CommitDate: Mon Jan 6 20:22:15 2020 +0200
Fix a typo in gdb/windows-tdep.c
gdb/ChangeLog
2020-01-06 Eli Zaretskii <eliz@gnu.org>
* windows-tdep.c: Fix a typo in WINDOWS_SIGABRT.
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ad7c33f..177b505 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2020-01-06 Eli Zaretskii <eliz@gnu.org>
+
+ * windows-tdep.c: Fix a typo in WINDOWS_SIGABRT.
+
2020-01-06 Hannes Domani <ssbssa@yahoo.de>
* source.c (print_source_lines_base): Set last_line_listed.
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index 58f8838..b6e5b9f 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -50,7 +50,7 @@ enum
WINDOWS_SIGILL = 4,
WINDOWS_SIGTRAP = 5, /* MinGW64/Cygwin */
#ifdef __CYGWIN__
- WINDOWS_SGABRT = 6,
+ WINDOWS_SIGABRT = 6,
#else
WINDOWS_SIGIOT = 6, /* MinGW64 */
#endif
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2020-01-06 19:38 ` Hannes Domani via gdb-patches
@ 2020-01-06 19:55 ` Eli Zaretskii
0 siblings, 0 replies; 26+ messages in thread
From: Eli Zaretskii @ 2020-01-06 19:55 UTC (permalink / raw)
To: Hannes Domani; +Cc: gdb-patches
> Date: Mon, 6 Jan 2020 19:38:50 +0000 (UTC)
> From: "Hannes Domani via gdb-patches" <gdb-patches@sourceware.org>
>
> > Does the below help?
> >
> > diff --git a/gdb/gdbsupport/gdb_wait.c b/gdb/gdbsupport/gdb_wait.c
> > index 037ba64..6facc48 100644
> > --- a/gdb/gdbsupport/gdb_wait.c
> > +++ b/gdb/gdbsupport/gdb_wait.c
> > @@ -34,7 +34,7 @@
> >Â Â Â Â false positives is justified by the utility of reporting the
> >    terminating signal in the "normal" cases. */
> >
> > -# include "gdb/signals.h"Â Â Â /* for enum gdb_signal */
> > +# include <signal.h>
> >
> >
> > # define WIN32_LEAN_AND_MEAN
> > # include <windows.h>Â Â Â Â Â Â Â /* for EXCEPTION_* constants */
>
> Yes, this works.
Thanks, pushed.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2020-01-06 19:34 ` Eli Zaretskii
@ 2020-01-06 19:38 ` Hannes Domani via gdb-patches
2020-01-06 19:55 ` Eli Zaretskii
0 siblings, 1 reply; 26+ messages in thread
From: Hannes Domani via gdb-patches @ 2020-01-06 19:38 UTC (permalink / raw)
To: Gdb-patches
Am Montag, 6. Januar 2020, 20:34:40 MEZ hat Eli Zaretskii <eliz@gnu.org> Folgendes geschrieben:
> > Date: Mon, 6 Jan 2020 18:59:36 +0000 (UTC)
> > From: "Hannes Domani via gdb-patches" <gdb-patches@sourceware.org>
> >
> > C:/src/repos/binutils-gdb.git/gdb/gdbsupport/gdb_wait.c: In function 'int windows_status_to_termsig(long unsigned int)':
> > C:/src/repos/binutils-gdb.git/gdb/gdbsupport/gdb_wait.c:56:37: error: 'SIGSEGV' was not declared in this scope
> > 56 | {EXCEPTION_ACCESS_VIOLATION, SIGSEGV},
> > | ^~~~~~~
>
> Does the below help?
>
> diff --git a/gdb/gdbsupport/gdb_wait.c b/gdb/gdbsupport/gdb_wait.c
> index 037ba64..6facc48 100644
> --- a/gdb/gdbsupport/gdb_wait.c
> +++ b/gdb/gdbsupport/gdb_wait.c
> @@ -34,7 +34,7 @@
> false positives is justified by the utility of reporting the
> terminating signal in the "normal" cases. */
>
> -# include "gdb/signals.h" /* for enum gdb_signal */
> +# include <signal.h>
>
>
> # define WIN32_LEAN_AND_MEAN
> # include <windows.h> /* for EXCEPTION_* constants */
Yes, this works.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2020-01-06 18:59 ` Hannes Domani via gdb-patches
@ 2020-01-06 19:34 ` Eli Zaretskii
2020-01-06 19:38 ` Hannes Domani via gdb-patches
0 siblings, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2020-01-06 19:34 UTC (permalink / raw)
To: Hannes Domani; +Cc: gdb-patches
> Date: Mon, 6 Jan 2020 18:59:36 +0000 (UTC)
> From: "Hannes Domani via gdb-patches" <gdb-patches@sourceware.org>
>
> C:/src/repos/binutils-gdb.git/gdb/gdbsupport/gdb_wait.c: In function 'int windows_status_to_termsig(long unsigned int)':
> C:/src/repos/binutils-gdb.git/gdb/gdbsupport/gdb_wait.c:56:37: error: 'SIGSEGV' was not declared in this scope
>   56 |     {EXCEPTION_ACCESS_VIOLATION,  SIGSEGV},
> Â Â Â Â Â |Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ^~~~~~~
Does the below help?
diff --git a/gdb/gdbsupport/gdb_wait.c b/gdb/gdbsupport/gdb_wait.c
index 037ba64..6facc48 100644
--- a/gdb/gdbsupport/gdb_wait.c
+++ b/gdb/gdbsupport/gdb_wait.c
@@ -34,7 +34,7 @@
false positives is justified by the utility of reporting the
terminating signal in the "normal" cases. */
-# include "gdb/signals.h" /* for enum gdb_signal */
+# include <signal.h>
# define WIN32_LEAN_AND_MEAN
# include <windows.h> /* for EXCEPTION_* constants */
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2020-01-06 18:51 ` Pedro Alves
@ 2020-01-06 19:26 ` Eli Zaretskii
0 siblings, 0 replies; 26+ messages in thread
From: Eli Zaretskii @ 2020-01-06 19:26 UTC (permalink / raw)
To: Pedro Alves; +Cc: philippe.waroquiers, gdb-patches
> Cc: philippe.waroquiers@skynet.be, gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Mon, 6 Jan 2020 18:51:20 +0000
>
> > Fair enough. How about the below?
>
> LGTM.
Thanks, pushed.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2020-01-03 19:59 ` Pedro Alves
2020-01-03 20:08 ` Pedro Alves
2020-01-03 20:34 ` Eli Zaretskii
@ 2020-01-06 18:59 ` Hannes Domani via gdb-patches
2020-01-06 19:34 ` Eli Zaretskii
2 siblings, 1 reply; 26+ messages in thread
From: Hannes Domani via gdb-patches @ 2020-01-06 18:59 UTC (permalink / raw)
To: Gdb-patches
Am Freitag, 3. Januar 2020, 20:59:45 MEZ hat Pedro Alves <palves@redhat.com> Folgendes geschrieben:
> See the new version in the new patch. It's the same, except it
> returns host signals SIGSEGV, SIGILL, etc., and -1 on "unknown".
> Here's the updated patch. I confirmed that it builds on MinGW-W64
> using my Fedora's cross cross compiler, but I didn't try to run
> the resulting GDB (since I'm not on Windows).
>
> WDYT? Does it work for you? I think this should have a NEWS
> entry, BTW.
I just tried to compile current master (with a native mingw-w64 compiler), and have this failure:
C:/src/repos/binutils-gdb.git/gdb/gdbsupport/gdb_wait.c: In function 'int windows_status_to_termsig(long unsigned int)':
C:/src/repos/binutils-gdb.git/gdb/gdbsupport/gdb_wait.c:56:37: error: 'SIGSEGV' was not declared in this scope
56 | {EXCEPTION_ACCESS_VIOLATION, SIGSEGV},
| ^~~~~~~
C:/src/repos/binutils-gdb.git/gdb/gdbsupport/gdb_wait.c:59:40: error: 'SIGILL' was not declared in this scope
59 | {EXCEPTION_ILLEGAL_INSTRUCTION, SIGILL},
| ^~~~~~
C:/src/repos/binutils-gdb.git/gdb/gdbsupport/gdb_wait.c:62:41: error: 'SIGFPE' was not declared in this scope
62 | {EXCEPTION_FLT_DENORMAL_OPERAND, SIGFPE},
| ^~~~~~
C:/src/repos/binutils-gdb.git/gdb/gdbsupport/gdb_wait.c:73:27: error: 'SIGTERM' was not declared in this scope
73 | {CONTROL_C_EXIT, SIGTERM}
| ^~~~~~~
Once I add #include <signal.h>, it works again.
Am I the only one with this problem?
Regards
Hannes Domani
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2020-01-06 16:17 ` Eli Zaretskii
@ 2020-01-06 18:51 ` Pedro Alves
2020-01-06 19:26 ` Eli Zaretskii
0 siblings, 1 reply; 26+ messages in thread
From: Pedro Alves @ 2020-01-06 18:51 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: philippe.waroquiers, gdb-patches
On 1/6/20 4:17 PM, Eli Zaretskii wrote:
>> Cc: philippe.waroquiers@skynet.be, gdb-patches@sourceware.org
>> From: Pedro Alves <palves@redhat.com>
>> Date: Mon, 6 Jan 2020 11:57:42 +0000
>>
>>>> I think this should have a NEWS entry, BTW.
>>>
>>> It's a kind of a bugfix, so I didn't think it was NEWS-worthy.
>>
>> My thinking is that users that might have been scripting
>> around $_exitcode may need to adjust to look at $_exitsignal.
>
> Fair enough. How about the below?
LGTM.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2020-01-06 11:57 ` Pedro Alves
@ 2020-01-06 16:17 ` Eli Zaretskii
2020-01-06 18:51 ` Pedro Alves
0 siblings, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2020-01-06 16:17 UTC (permalink / raw)
To: Pedro Alves; +Cc: philippe.waroquiers, gdb-patches
> Cc: philippe.waroquiers@skynet.be, gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Mon, 6 Jan 2020 11:57:42 +0000
>
> >> I think this should have a NEWS entry, BTW.
> >
> > It's a kind of a bugfix, so I didn't think it was NEWS-worthy.
>
> My thinking is that users that might have been scripting
> around $_exitcode may need to adjust to look at $_exitsignal.
Fair enough. How about the below?
diff --git a/gdb/NEWS b/gdb/NEWS
index f51a989..11e4221 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
*** Changes since GDB 9
+* Debugging MS-Windows processes now sets $_exitsignal when the
+ inferior is terminated by a signal, instead of setting $_exitcode.
+
* Multithreaded symbol loading has now been enabled by default on systems
that support it (see entry for GDB 9, below), providing faster
performance for programs with many symbols.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2020-01-03 20:34 ` Eli Zaretskii
@ 2020-01-06 11:57 ` Pedro Alves
2020-01-06 16:17 ` Eli Zaretskii
0 siblings, 1 reply; 26+ messages in thread
From: Pedro Alves @ 2020-01-06 11:57 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: philippe.waroquiers, gdb-patches
On 1/3/20 8:34 PM, Eli Zaretskii wrote:
>> Cc: gdb-patches@sourceware.org
>> From: Pedro Alves <palves@redhat.com>
>> Date: Fri, 3 Jan 2020 19:59:22 +0000
>>
>> Here's the updated patch. I confirmed that it builds on MinGW-W64
>> using my Fedora's cross cross compiler, but I didn't try to run
>> the resulting GDB (since I'm not on Windows).
>
> LGTM, thanks. Feel free to push.
Pushed.
>
>> I think this should have a NEWS entry, BTW.
>
> It's a kind of a bugfix, so I didn't think it was NEWS-worthy.
My thinking is that users that might have been scripting
around $_exitcode may need to adjust to look at $_exitsignal.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2020-01-03 19:59 ` Pedro Alves
2020-01-03 20:08 ` Pedro Alves
@ 2020-01-03 20:34 ` Eli Zaretskii
2020-01-06 11:57 ` Pedro Alves
2020-01-06 18:59 ` Hannes Domani via gdb-patches
2 siblings, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2020-01-03 20:34 UTC (permalink / raw)
To: Pedro Alves; +Cc: philippe.waroquiers, gdb-patches
> Cc: gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Fri, 3 Jan 2020 19:59:22 +0000
>
> Here's the updated patch. I confirmed that it builds on MinGW-W64
> using my Fedora's cross cross compiler, but I didn't try to run
> the resulting GDB (since I'm not on Windows).
LGTM, thanks. Feel free to push.
> I think this should have a NEWS entry, BTW.
It's a kind of a bugfix, so I didn't think it was NEWS-worthy.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2020-01-03 19:59 ` Pedro Alves
@ 2020-01-03 20:08 ` Pedro Alves
2020-01-03 20:34 ` Eli Zaretskii
2020-01-06 18:59 ` Hannes Domani via gdb-patches
2 siblings, 0 replies; 26+ messages in thread
From: Pedro Alves @ 2020-01-03 20:08 UTC (permalink / raw)
To: Eli Zaretskii, philippe.waroquiers; +Cc: gdb-patches
On 1/3/20 7:59 PM, Pedro Alves wrote:
> #define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
> #define DebugActiveProcessStop dyn_DebugActiveProcessStop
> @@ -1627,8 +1628,23 @@ get_windows_debug_event (struct target_ops *ops,
> windows_delete_thread (ptid_t (current_event.dwProcessId, 0,
> current_event.dwThreadId),
> 0, true /* main_thread_p */);
> - ourstatus->kind = TARGET_WAITKIND_EXITED;
> - ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
> + 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->kind = TARGET_WAITKIND_EXITED;
> + ourstatus->value.integer = exit_status;
> + }
> + else
> + {
> + ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
> + ourstatus->value.sig = gdb_signal_from_host (WTERMSIG (w));
I notice now that this should be:
ourstatus->value.sig = gdb_signal_from_host (exit_signal);
I had fixed that on gdbserver, but not on windows-nat.c. And the reason
I didn't notice is that the build tree I was using is only building
gdbserver, not the whole of gdb + gdbserver, and I failed to notice it.
Hopefully the rest of the code will build cleanly without requiring
much more fixing.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-12-25 15:57 ` Eli Zaretskii
@ 2020-01-03 19:59 ` Pedro Alves
2020-01-03 20:08 ` Pedro Alves
` (2 more replies)
0 siblings, 3 replies; 26+ messages in thread
From: Pedro Alves @ 2020-01-03 19:59 UTC (permalink / raw)
To: Eli Zaretskii, philippe.waroquiers; +Cc: gdb-patches
On 12/25/19 3:57 PM, Eli Zaretskii wrote:
> No further comments, so I made additional changes to take care of
> Pedro's review comments, and the result is below.
Thanks. I have some comments, and while thinking through them
I updated the patch accordingly. See below.
>
> OK to commit?
>
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index acf9106..838eafd 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,26 @@
> +2019-12-25 Eli Zaretskii <eliz@gnu.org>
> +
> + * 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 (get_windows_debug_event): Extract the fatal
> + exception from the exit status and convert to the equivalent Posix
> + signal number.
> +
> + * gdbsupport/gdb_wait.c: New file, implements
> + windows_status_to_termsig.
> +
> + * gdbsupport/gdb_wait.h (WIFEXITED, WIFSIGNALED, WEXITSTATUS)
> + (WTERMSIG) [__MINGW32__]: Separate definitions for MinGW.
> +
> + * cli/cli-cmds.c (exit_status_set_internal_vars): Account for the
> + possibility that WTERMSIG returns GDB_SIGNAL_UNKNOWN.
> +
> + * Makefile.in (COMMON_SFILES): Add gdbsupport/gdb_wait.c.
> +
> 2019-12-21 George Barrett <bob@bob131.so>
>
> * solib-svr4.c (svr4_handle_solib_event): Add fallback link
> diff --git a/gdb/Makefile.in b/gdb/Makefile.in
> index fa5c820..34d0acf 100644
> --- a/gdb/Makefile.in
> +++ b/gdb/Makefile.in
> @@ -986,6 +986,7 @@ COMMON_SFILES = \
> gdbsupport/gdb-dlfcn.c \
> gdbsupport/gdb_tilde_expand.c \
> gdbsupport/gdb_vecs.c \
> + gdbsupport/gdb_wait.c \
> gdbsupport/netstuff.c \
> gdbsupport/new-op.c \
> gdbsupport/pathstuff.c \
> diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
> index 681d53c..0d1584e 100644
> --- a/gdb/cli/cli-cmds.c
> +++ b/gdb/cli/cli-cmds.c
> @@ -798,10 +798,16 @@ exit_status_set_internal_vars (int exit_status)
>
> clear_internalvar (var_code);
> clear_internalvar (var_signal);
> - if (WIFEXITED (exit_status))
> - set_internalvar_integer (var_code, WEXITSTATUS (exit_status));
> - else if (WIFSIGNALED (exit_status))
> + enum gdb_signal exit_signal
> + = WIFSIGNALED (exit_status) ? WTERMSIG (exit_status) : GDB_SIGNAL_UNKNOWN;
This is mixing host signals, and enum gdb_signal, which is bad.
It is conceivable that some system uses 143 as a real signal
number, for example.
Actually, it doesn't even compile on non-MinGW systems. On GNU/Linux:
src/gdb/cli/cli-cmds.c: In function ‘void exit_status_set_internal_vars(int)’:
src/gdb/cli/cli-cmds.c:802:33: error: invalid conversion from ‘int’ to ‘gdb_signal’ [-fpermissive]
= WIFSIGNALED (exit_status) ? WTERMSIG (exit_status) : GDB_SIGNAL_UNKNOWN;
This needs to be written in a form that doesn't mix host signals
and enum gdb_signal. I think the best is to make WTERMSIG emulation
return host signals like Posix, and return -1 in the "unknown" case.
> + /* The GDB_SIGNAL_UNKNOWN condition can happen on MinGW, if we don't
> + recognize the fatal exception code encoded in the exit status;
> + see gdb_wait.c. We don't want to lose information in the exit
> + status in that case. */
> + if (exit_signal != GDB_SIGNAL_UNKNOWN)
> set_internalvar_integer (var_signal, WTERMSIG (exit_status));
> + else if (!WIFSIGNALED (exit_status))
> + set_internalvar_integer (var_code, WEXITSTATUS (exit_status));
> else
> warning (_("unexpected shell command exit status %d"), exit_status);
IIUC, this ends up in "warning" branch in the case where we don't
recognize the exception. I think it would be better if this were consistent
with how windows-nat.c handles it. I.e., treat an unrecognized
exception as a normal exit status and record it in $_exitcode.
Like:
@@ -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
#ifdef here is OK because this code is only for handling host signals
from programs run on the same machine as GDB. It is not about handling
signals from the target system. I.e., cross-debugging isn't a
consideration here.
> }
>
> diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
> index 10d5c95..12e50b6 100644
> --- a/gdb/windows-nat.c
> +++ b/gdb/windows-nat.c
> @@ -68,6 +68,7 @@
> #include "inf-child.h"
> #include "gdbsupport/gdb_tilde_expand.h"
> #include "gdbsupport/pathstuff.h"
> +#include "gdbsupport/gdb_wait.h"
>
> #define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
> #define DebugActiveProcessStop dyn_DebugActiveProcessStop
> @@ -1620,8 +1621,22 @@ get_windows_debug_event (struct target_ops *ops,
> windows_delete_thread (ptid_t (current_event.dwProcessId, 0,
> current_event.dwThreadId),
> 0, true /* main_thread_p */);
> - ourstatus->kind = TARGET_WAITKIND_EXITED;
> - ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
> + 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. */
> + enum gdb_signal exit_signal = WIFSIGNALED (exit_status)
> + ? WTERMSIG (exit_status) : GDB_SIGNAL_UNKNOWN;
This is native code, so the "some system uses 143 as real signal"
concern doesn't apply, but we should still not use gdb_signal
to hold host signals, it's a design violation. And it probably doesn't
compile on Cygwin. Easily adjusted in a similar way to the cli/ code once
WTERMSIG returns a host signal number. We can then use gdb_signal_from_host
to convert the Windows/host's Posix signal to a gdb_signal, like all
other ports do.
> + if (exit_signal == GDB_SIGNAL_UNKNOWN)
> + {
> + ourstatus->kind = TARGET_WAITKIND_EXITED;
> + ourstatus->value.integer = exit_status;
> + }
> + else
> + {
> + ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
> + ourstatus->value.sig = exit_signal;
> + }
> thread_id = current_event.dwThreadId;
> }
> break;
> diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
> index bb69a79..c2cecce 100644
> --- a/gdb/windows-tdep.c
> +++ b/gdb/windows-tdep.c
> @@ -35,6 +35,55 @@
> #include "solib-target.h"
> #include "gdbcore.h"
>
> +/* Windows signal numbers differ between MinGW flavors and between
> + those and Cygwin. The below enumeration was gleaned from the
> + respective headers; the ones marked with MinGW64/Cygwin are defined
> + only by MinGW64 and Cygwin, not by mingw.org's MinGW. */
> +
> +enum
> + {
> + WINDOWS_SIGHUP = 1, /* MinGW64/Cygwin */
> + WINDOWS_SIGINT = 2,
> + WINDOWS_SIGQUIT = 3, /* MinGW64/Cygwin */
> + WINDOWS_SIGILL = 4,
> + WINDOWS_SIGTRAP = 5, /* MinGW64/Cygwin */
> +#ifdef __CYGWIN__
> + WINDOWS_SGABRT = 6,
> +#else
> + WINDOWS_SIGIOT = 6, /* MinGW64 */
> +#endif
> + WINDOWS_SIGEMT = 7, /* MinGW64/Cygwin */
> + WINDOWS_SIGFPE = 8,
> + WINDOWS_SIGKILL = 9, /* MinGW64/Cygwin */
> + WINDOWS_SIGBUS = 10, /* MinGW64/Cygwin */
> + WINDOWS_SIGSEGV = 11,
> + WINDOWS_SIGSYS = 12, /* MinGW64/Cygwin */
> + WINDOWS_SIGPIPE = 13,/* MinGW64/Cygwin */
> + WINDOWS_SIGALRM = 14,/* MinGW64/Cygwin */
> + WINDOWS_SIGTERM = 15,
> +#ifdef __CYGWIN__
> + WINDOWS_SIGURG = 16,
> + WINDOWS_SIGSTOP = 17,
> + WINDOWS_SIGTSTP = 18,
> + WINDOWS_SIGCONT = 19,
> + WINDOWS_SIGCHLD = 20,
> + WINDOWS_SIGTTIN = 21,
> + WINDOWS_SIGTTOU = 22,
> + WINDOWS_SIGIO = 23,
> + WINDOWS_SIGXCPU = 24,
> + WINDOWS_SIGXFSZ = 25,
> + WINDOWS_SIGVTALRM = 26,
> + WINDOWS_SIGPROF = 27,
> + WINDOWS_SIGWINCH = 28,
> + WINDOWS_SIGLOST = 29,
> + WINDOWS_SIGUSR1 = 30,
> + WINDOWS_SIGUSR2 = 31
> +#else
> + WINDOWS_SIGBREAK = 21,
> + WINDOWS_SIGABRT = 22
> +#endif
Bummer on the #ifdefs. This is still incorrect design-wise, because the
values depend on how GDB is built. We must not do that in tdep files,
so that cross debugging works correctly. I.e., a Cygwin gdb debugging
against a MinGW gdbserver should understand MinGW signals, and vice versa.
Or a Cygwin GDB debugging a MinGW program natively too.
From <https://sourceware.org/gdb/wiki/Internals/Source%20Tree%20Structure>:
"Since these files are used when you configure GDB as a cross debugger (e.g.,
a GDB that runs on x86 but is configured to debug ARM code), all code in
these files is host-independent. E.g., including host-specific headers,
assuming host endianness, etc. in these files would be incorrect."
It is a known limitation that GDB currently doesn't have separate "set osabi"
awareness for Cygwin vs MinGW, so I'll let this pass, with a FIXME note.
See <https://sourceware.org/bugzilla/show_bug.cgi?id=21500#c1>.
> + };
> +
> struct cmd_list_element *info_w32_cmdlist;
>
> typedef struct thread_information_block_32
> @@ -461,6 +510,81 @@ init_w32_command_list (void)
> }
> }
>
> +static int
> +windows_gdb_signal_to_target (struct gdbarch *gdbarch, enum gdb_signal signal)
I've added the conventional intro comment.
> +{
> + switch (signal)
> + {
> + case GDB_SIGNAL_0:
> + return 0;
> + case GDB_SIGNAL_HUP:
> + return WINDOWS_SIGHUP;
> + case GDB_SIGNAL_INT:
> + return WINDOWS_SIGINT;
> + case GDB_SIGNAL_QUIT:
> + return WINDOWS_SIGQUIT;
> + case GDB_SIGNAL_ILL:
> + return WINDOWS_SIGILL;
> + case GDB_SIGNAL_TRAP:
> + return WINDOWS_SIGTRAP;
> + case GDB_SIGNAL_ABRT:
> + return WINDOWS_SIGABRT;
> + case GDB_SIGNAL_EMT:
> + return WINDOWS_SIGEMT;
> + case GDB_SIGNAL_FPE:
> + return WINDOWS_SIGFPE;
> + case GDB_SIGNAL_KILL:
> + return WINDOWS_SIGKILL;
> + case GDB_SIGNAL_BUS:
> + return WINDOWS_SIGBUS;
> + case GDB_SIGNAL_SEGV:
> + return WINDOWS_SIGSEGV;
> + case GDB_SIGNAL_SYS:
> + return WINDOWS_SIGSYS;
> + case GDB_SIGNAL_PIPE:
> + return WINDOWS_SIGPIPE;
> + case GDB_SIGNAL_ALRM:
> + return WINDOWS_SIGALRM;
> + case GDB_SIGNAL_TERM:
> + return WINDOWS_SIGTERM;
> +#ifdef __CYGWIN__
> + case GDB_SIGNAL_URG:
> + return WINDOWS_SIGURG;
> + case GDB_SIGNAL_STOP:
> + return WINDOWS_SIGSTOP;
> + case GDB_SIGNAL_TSTP:
> + return WINDOWS_SIGTSTP;
> + case GDB_SIGNAL_CONT:
> + return WINDOWS_SIGCONT;
> + case GDB_SIGNAL_CHLD:
> + return WINDOWS_SIGCHLD;
> + case GDB_SIGNAL_TTIN:
> + return WINDOWS_SIGTTIN;
> + case GDB_SIGNAL_TTOU:
> + return WINDOWS_SIGTTOU;
> + case GDB_SIGNAL_IO:
> + return WINDOWS_SIGIO;
> + case GDB_SIGNAL_XCPU:
> + return WINDOWS_SIGXCPU;
> + case GDB_SIGNAL_XFSZ:
> + return WINDOWS_SIGXFSZ;
> + case GDB_SIGNAL_VTALRM:
> + return WINDOWS_SIGVTALRM;
> + case GDB_SIGNAL_PROF:
> + return WINDOWS_SIGPROF;
> + case GDB_SIGNAL_WINCH:
> + return WINDOWS_SIGWINCH;
> + case GDB_SIGNAL_PWR:
> + return WINDOWS_SIGLOST;
> + case GDB_SIGNAL_USR1:
> + return WINDOWS_SIGUSR1;
> + case GDB_SIGNAL_USR2:
> + return WINDOWS_SIGUSR2;
> +#endif /* __CYGWIN__ */
> + }
> + return -1;
> +}
> +
> /* To be called from the various GDB_OSABI_CYGWIN handlers for the
> various Windows architectures and machine types. */
>
> @@ -477,6 +601,8 @@ windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
> set_gdbarch_iterate_over_objfiles_in_search_order
> (gdbarch, windows_iterate_over_objfiles_in_search_order);
>
> + set_gdbarch_gdb_signal_to_target (gdbarch, windows_gdb_signal_to_target);
> +
> set_solib_ops (gdbarch, &solib_target_so_ops);
> }
>
>
> diff --git a/gdb/gdbsupport/gdb_wait.h b/gdb/gdbsupport/gdb_wait.h
> index b3b752c..e8597f9 100644
> --- a/gdb/gdbsupport/gdb_wait.h
> +++ b/gdb/gdbsupport/gdb_wait.h
> @@ -38,20 +38,33 @@
> in POSIX.1. We fail to define WNOHANG and WUNTRACED, which POSIX.1
> <sys/wait.h> defines, since our code does not use waitpid() (but
> NOTE exception for GNU/Linux below). We also fail to declare
> - wait() and waitpid(). */
> + wait() and waitpid().
> +
> + For MinGW, we use the fact that 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. See also gdb_wait.c. */
>
> #ifndef WIFEXITED
> -#define WIFEXITED(w) (((w)&0377) == 0)
> +# ifdef __MINGW32__
> +# define WIFEXITED(w) (((w) & 0xC0000000) == 0)
> +# else
> +# define WIFEXITED(w) (((w)&0377) == 0)
> +# endif
> #endif
>
> #ifndef WIFSIGNALED
> -#define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
> +# ifdef __MINGW32__
> +# define WIFSIGNALED(w) (((w) & 0xC0000000) == 0xC0000000)
> +# else
> +# define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
> +# endif
> #endif
>
> #ifndef WIFSTOPPED
> #ifdef IBM6000
>
> -/* Unfortunately, the above comment (about being compatible in all Unix
> +/* Unfortunately, the above comment (about being compatible in all Unix
> systems) is not quite correct for AIX, sigh. And AIX 3.2 can generate
> status words like 0x57c (sigtrap received after load), and gdb would
> choke on it. */
> @@ -64,11 +77,20 @@
> #endif
>
> #ifndef WEXITSTATUS
> -#define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */
> +# ifdef __MINGW32__
> +# define WEXITSTATUS(w) ((w) & ~0xC0000000)
I've noticed that this clearing of the 0xC0 bits isn't really necessary,
since you're only supposed to call this if WIFEXITED returns true.
I've left it alone but I wonder whether we shouldn't remove that, since
I can't figure out when we'd really want to strip those bits.
> +# else
> +# define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */
> +# endif
> #endif
>
> #ifndef WTERMSIG
> -#define WTERMSIG(w) ((w) & 0177)
> +# ifdef __MINGW32__
> +extern enum gdb_signal windows_status_to_termsig (unsigned long);
This here should return int.
> +# define WTERMSIG(w) windows_status_to_termsig (w)
> +# else
> +# define WTERMSIG(w) ((w) & 0177)
> +# endif
> #endif
>
> #ifndef WSTOPSIG
>
>
> diff --git a/gdb/gdbsupport/gdb_wait.c b/gdb/gdbsupport/gdb_wait.c
> new file mode 100644
> index 0000000..7096152
> --- /dev/null
> +++ b/gdb/gdbsupport/gdb_wait.c
> @@ -0,0 +1,80 @@
> +/* Support code for standard wait macros in gdb_wait.h.
> +
> + Copyright (C) 2019 Free Software Foundation, Inc.
> +
> + This file is part of GDB.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +#include "common-defs.h"
> +
> +#ifdef __MINGW32__
> +
> +/* The underlying idea is that 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. We thus emulate WTERMSIG etc. by translating the fatal
> + exception codes to more-or-less equivalent Posix signals.
> +
> + The translation below is not perfect, because a program could
> + legitimately exit normally with a status whose value happens to
> + have the high bits set, but that's extremely rare, to say the
> + least, and it is deemed such a negligibly small probability of
> + false positives is justified by the utility of reporting the
> + terminating signal in the "normal" cases. */
> +
> +# include "gdb/signals.h" /* for enum gdb_signal */
> +
> +# define WIN32_LEAN_AND_MEAN
> +# include <windows.h> /* for EXCEPTION_* constants */
> +
> +struct xlate_status
> +{
> + DWORD status; /* exit status (actually, fatal exception code) */
> + enum gdb_signal sig; /* corresponding GDB signal value */
> +};
> +
> +enum gdb_signal
> +windows_status_to_termsig (unsigned long status)
See the new version in the new patch. It's the same, except it
returns host signals SIGSEGV, SIGILL, etc., and -1 on "unknown".
> +{
> + static const xlate_status status_xlate_tbl[] =
> + {
> + {EXCEPTION_ACCESS_VIOLATION, GDB_SIGNAL_SEGV},
> + {EXCEPTION_IN_PAGE_ERROR, GDB_SIGNAL_SEGV},
> + {EXCEPTION_INVALID_HANDLE, GDB_SIGNAL_SEGV},
> + {EXCEPTION_ILLEGAL_INSTRUCTION, GDB_SIGNAL_ILL},
> + {EXCEPTION_NONCONTINUABLE_EXCEPTION, GDB_SIGNAL_ILL},
> + {EXCEPTION_ARRAY_BOUNDS_EXCEEDED, GDB_SIGNAL_SEGV},
> + {EXCEPTION_FLT_DENORMAL_OPERAND, GDB_SIGNAL_FPE},
> + {EXCEPTION_FLT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE},
> + {EXCEPTION_FLT_INEXACT_RESULT, GDB_SIGNAL_FPE},
> + {EXCEPTION_FLT_INVALID_OPERATION, GDB_SIGNAL_FPE},
> + {EXCEPTION_FLT_OVERFLOW, GDB_SIGNAL_FPE},
> + {EXCEPTION_FLT_STACK_CHECK, GDB_SIGNAL_FPE},
> + {EXCEPTION_FLT_UNDERFLOW, GDB_SIGNAL_FPE},
> + {EXCEPTION_INT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE},
> + {EXCEPTION_INT_OVERFLOW, GDB_SIGNAL_FPE},
> + {EXCEPTION_PRIV_INSTRUCTION, GDB_SIGNAL_ILL},
> + {EXCEPTION_STACK_OVERFLOW, GDB_SIGNAL_SEGV},
> + {CONTROL_C_EXIT, GDB_SIGNAL_TERM}
> + };
> +
> + for (const xlate_status &x : status_xlate_tbl)
> + if (x.status == status)
> + return x.sig;
> +
> + return GDB_SIGNAL_UNKNOWN;
> +}
> +
Here's the updated patch. I confirmed that it builds on MinGW-W64
using my Fedora's cross cross compiler, but I didn't try to run
the resulting GDB (since I'm not on Windows).
WDYT? Does it work for you? I think this should have a NEWS
entry, BTW.
From dce7b34af6c252556a83dce310eb546cc6588285 Mon Sep 17 00:00:00 2001
From: Eli Zaretskii <eliz@gnu.org>
Date: Fri, 3 Jan 2020 19:30:15 +0000
Subject: [PATCH] Improve process exit status macros on MinGW
FIXME: Missing git commit log & gdb/NEWS entry.
gdb/ChangeLog:
yyyy-mm-dd Eli Zaretskii <eliz@gnu.org>
Pedro Alves <palves@redhat.com>
* 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:
yyyy-mm-dd Eli Zaretskii <eliz@gnu.org>
Pedro Alves <palves@redhat.com>
* 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/Makefile.in | 1 +
gdb/cli/cli-cmds.c | 12 +++++
gdb/gdbserver/Makefile.in | 2 +
gdb/gdbserver/win32-low.c | 22 +++++++-
gdb/gdbsupport/gdb_wait.c | 83 +++++++++++++++++++++++++++++
gdb/gdbsupport/gdb_wait.h | 34 +++++++++---
gdb/windows-nat.c | 20 ++++++-
gdb/windows-tdep.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 294 insertions(+), 10 deletions(-)
create mode 100644 gdb/gdbsupport/gdb_wait.c
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 448a495bb3b..0bc8142d2a0 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -986,6 +986,7 @@ COMMON_SFILES = \
gdbsupport/gdb-dlfcn.c \
gdbsupport/gdb_tilde_expand.c \
gdbsupport/gdb_vecs.c \
+ gdbsupport/gdb_wait.c \
gdbsupport/netstuff.c \
gdbsupport/new-op.c \
gdbsupport/pathstuff.c \
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 0b55a1244aa..c2ba3a4238a 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
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index d39c065f6d0..1125426778b 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -217,6 +217,7 @@ SFILES = \
$(srcdir)/gdbsupport/gdb-dlfcn.c \
$(srcdir)/gdbsupport/gdb_tilde_expand.c \
$(srcdir)/gdbsupport/gdb_vecs.c \
+ $(srcdir)/gdbsupport/gdb_wait.c \
$(srcdir)/gdbsupport/netstuff.c \
$(srcdir)/gdbsupport/new-op.c \
$(srcdir)/gdbsupport/pathstuff.c \
@@ -264,6 +265,7 @@ OBS = \
gdbsupport/gdb-dlfcn.o \
gdbsupport/gdb_tilde_expand.o \
gdbsupport/gdb_vecs.o \
+ gdbsupport/gdb_wait.o \
gdbsupport/netstuff.o \
gdbsupport/new-op.o \
gdbsupport/pathstuff.o \
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index b4ee0f45c4f..340f65bbf95 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -34,6 +34,7 @@
#include <process.h>
#include "gdbsupport/gdb_tilde_expand.h"
#include "gdbsupport/common-inferior.h"
+#include "gdbsupport/gdb_wait.h"
#ifndef USE_WIN32API
#include <sys/cygwin.h>
@@ -1511,8 +1512,24 @@ get_child_debug_event (struct target_waitstatus *ourstatus)
"for pid=%u tid=%x\n",
(unsigned) current_event.dwProcessId,
(unsigned) current_event.dwThreadId));
- ourstatus->kind = TARGET_WAITKIND_EXITED;
- ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
+ {
+ 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->kind = TARGET_WAITKIND_EXITED;
+ ourstatus->value.integer = exit_status;
+ }
+ else
+ {
+ ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
+ ourstatus->value.sig = gdb_signal_from_host (exit_signal);
+ }
+ }
child_continue (DBG_CONTINUE, -1);
CloseHandle (current_process_handle);
current_process_handle = NULL;
@@ -1607,6 +1624,7 @@ win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options)
win32_clear_inferiors ();
return ptid_t (current_event.dwProcessId);
case TARGET_WAITKIND_STOPPED:
+ case TARGET_WAITKIND_SIGNALLED:
case TARGET_WAITKIND_LOADED:
OUTMSG2 (("Child Stopped with signal = %d \n",
ourstatus->value.sig));
diff --git a/gdb/gdbsupport/gdb_wait.c b/gdb/gdbsupport/gdb_wait.c
new file mode 100644
index 00000000000..037ba643db4
--- /dev/null
+++ b/gdb/gdbsupport/gdb_wait.c
@@ -0,0 +1,83 @@
+/* Support code for standard wait macros in gdb_wait.h.
+
+ Copyright (C) 2019 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "common-defs.h"
+
+#ifdef __MINGW32__
+
+/* The underlying idea is that 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. We thus emulate WTERMSIG etc. by translating the fatal
+ exception codes to more-or-less equivalent Posix signals.
+
+ The translation below is not perfect, because a program could
+ legitimately exit normally with a status whose value happens to
+ have the high bits set, but that's extremely rare, to say the
+ least, and it is deemed such a negligibly small probability of
+ false positives is justified by the utility of reporting the
+ terminating signal in the "normal" cases. */
+
+# include "gdb/signals.h" /* for enum gdb_signal */
+
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h> /* for EXCEPTION_* constants */
+
+struct xlate_status
+{
+ /* The exit status (actually, fatal exception code). */
+ DWORD status;
+
+ /* The corresponding signal value. */
+ int sig;
+};
+
+int
+windows_status_to_termsig (unsigned long status)
+{
+ static const xlate_status status_xlate_tbl[] =
+ {
+ {EXCEPTION_ACCESS_VIOLATION, SIGSEGV},
+ {EXCEPTION_IN_PAGE_ERROR, SIGSEGV},
+ {EXCEPTION_INVALID_HANDLE, SIGSEGV},
+ {EXCEPTION_ILLEGAL_INSTRUCTION, SIGILL},
+ {EXCEPTION_NONCONTINUABLE_EXCEPTION, SIGILL},
+ {EXCEPTION_ARRAY_BOUNDS_EXCEEDED, SIGSEGV},
+ {EXCEPTION_FLT_DENORMAL_OPERAND, SIGFPE},
+ {EXCEPTION_FLT_DIVIDE_BY_ZERO, SIGFPE},
+ {EXCEPTION_FLT_INEXACT_RESULT, SIGFPE},
+ {EXCEPTION_FLT_INVALID_OPERATION, SIGFPE},
+ {EXCEPTION_FLT_OVERFLOW, SIGFPE},
+ {EXCEPTION_FLT_STACK_CHECK, SIGFPE},
+ {EXCEPTION_FLT_UNDERFLOW, SIGFPE},
+ {EXCEPTION_INT_DIVIDE_BY_ZERO, SIGFPE},
+ {EXCEPTION_INT_OVERFLOW, SIGFPE},
+ {EXCEPTION_PRIV_INSTRUCTION, SIGILL},
+ {EXCEPTION_STACK_OVERFLOW, SIGSEGV},
+ {CONTROL_C_EXIT, SIGTERM}
+ };
+
+ for (const xlate_status &x : status_xlate_tbl)
+ if (x.status == status)
+ return x.sig;
+
+ return -1;
+}
+
+#endif /* __MINGW32__ */
diff --git a/gdb/gdbsupport/gdb_wait.h b/gdb/gdbsupport/gdb_wait.h
index d00b4592051..3563b9cb954 100644
--- a/gdb/gdbsupport/gdb_wait.h
+++ b/gdb/gdbsupport/gdb_wait.h
@@ -38,20 +38,33 @@
in POSIX.1. We fail to define WNOHANG and WUNTRACED, which POSIX.1
<sys/wait.h> defines, since our code does not use waitpid() (but
NOTE exception for GNU/Linux below). We also fail to declare
- wait() and waitpid(). */
+ wait() and waitpid().
+
+ For MinGW, we use the fact that 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. See also gdb_wait.c. */
#ifndef WIFEXITED
-#define WIFEXITED(w) (((w)&0377) == 0)
+# ifdef __MINGW32__
+# define WIFEXITED(w) (((w) & 0xC0000000) == 0)
+# else
+# define WIFEXITED(w) (((w)&0377) == 0)
+# endif
#endif
#ifndef WIFSIGNALED
-#define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
+# ifdef __MINGW32__
+# define WIFSIGNALED(w) (((w) & 0xC0000000) == 0xC0000000)
+# else
+# define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
+# endif
#endif
#ifndef WIFSTOPPED
#ifdef IBM6000
-/* Unfortunately, the above comment (about being compatible in all Unix
+/* Unfortunately, the above comment (about being compatible in all Unix
systems) is not quite correct for AIX, sigh. And AIX 3.2 can generate
status words like 0x57c (sigtrap received after load), and gdb would
choke on it. */
@@ -64,11 +77,20 @@
#endif
#ifndef WEXITSTATUS
-#define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */
+# ifdef __MINGW32__
+# define WEXITSTATUS(w) ((w) & ~0xC0000000)
+# else
+# define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */
+# endif
#endif
#ifndef WTERMSIG
-#define WTERMSIG(w) ((w) & 0177)
+# ifdef __MINGW32__
+extern int windows_status_to_termsig (unsigned long);
+# define WTERMSIG(w) windows_status_to_termsig (w)
+# else
+# define WTERMSIG(w) ((w) & 0177)
+# endif
#endif
#ifndef WSTOPSIG
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 2214caacb81..b4cb5eec6cc 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -68,6 +68,7 @@
#include "inf-child.h"
#include "gdbsupport/gdb_tilde_expand.h"
#include "gdbsupport/pathstuff.h"
+#include "gdbsupport/gdb_wait.h"
#define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
#define DebugActiveProcessStop dyn_DebugActiveProcessStop
@@ -1627,8 +1628,23 @@ get_windows_debug_event (struct target_ops *ops,
windows_delete_thread (ptid_t (current_event.dwProcessId, 0,
current_event.dwThreadId),
0, true /* main_thread_p */);
- ourstatus->kind = TARGET_WAITKIND_EXITED;
- ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
+ 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->kind = TARGET_WAITKIND_EXITED;
+ ourstatus->value.integer = exit_status;
+ }
+ else
+ {
+ ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
+ ourstatus->value.sig = gdb_signal_from_host (WTERMSIG (w));
+ }
thread_id = current_event.dwThreadId;
}
break;
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index ca9b81df298..58f8838b885 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -35,6 +35,57 @@
#include "solib-target.h"
#include "gdbcore.h"
+/* Windows signal numbers differ between MinGW flavors and between
+ those and Cygwin. The below enumeration was gleaned from the
+ respective headers; the ones marked with MinGW64/Cygwin are defined
+ only by MinGW64 and Cygwin, not by mingw.org's MinGW. FIXME: We
+ should really have distinct MinGW vs Cygwin OSABIs, and two
+ separate enums, selected at runtime. */
+
+enum
+ {
+ WINDOWS_SIGHUP = 1, /* MinGW64/Cygwin */
+ WINDOWS_SIGINT = 2,
+ WINDOWS_SIGQUIT = 3, /* MinGW64/Cygwin */
+ WINDOWS_SIGILL = 4,
+ WINDOWS_SIGTRAP = 5, /* MinGW64/Cygwin */
+#ifdef __CYGWIN__
+ WINDOWS_SGABRT = 6,
+#else
+ WINDOWS_SIGIOT = 6, /* MinGW64 */
+#endif
+ WINDOWS_SIGEMT = 7, /* MinGW64/Cygwin */
+ WINDOWS_SIGFPE = 8,
+ WINDOWS_SIGKILL = 9, /* MinGW64/Cygwin */
+ WINDOWS_SIGBUS = 10, /* MinGW64/Cygwin */
+ WINDOWS_SIGSEGV = 11,
+ WINDOWS_SIGSYS = 12, /* MinGW64/Cygwin */
+ WINDOWS_SIGPIPE = 13,/* MinGW64/Cygwin */
+ WINDOWS_SIGALRM = 14,/* MinGW64/Cygwin */
+ WINDOWS_SIGTERM = 15,
+#ifdef __CYGWIN__
+ WINDOWS_SIGURG = 16,
+ WINDOWS_SIGSTOP = 17,
+ WINDOWS_SIGTSTP = 18,
+ WINDOWS_SIGCONT = 19,
+ WINDOWS_SIGCHLD = 20,
+ WINDOWS_SIGTTIN = 21,
+ WINDOWS_SIGTTOU = 22,
+ WINDOWS_SIGIO = 23,
+ WINDOWS_SIGXCPU = 24,
+ WINDOWS_SIGXFSZ = 25,
+ WINDOWS_SIGVTALRM = 26,
+ WINDOWS_SIGPROF = 27,
+ WINDOWS_SIGWINCH = 28,
+ WINDOWS_SIGLOST = 29,
+ WINDOWS_SIGUSR1 = 30,
+ WINDOWS_SIGUSR2 = 31
+#else
+ WINDOWS_SIGBREAK = 21,
+ WINDOWS_SIGABRT = 22
+#endif
+ };
+
struct cmd_list_element *info_w32_cmdlist;
typedef struct thread_information_block_32
@@ -461,6 +512,83 @@ init_w32_command_list (void)
}
}
+/* Implementation of `gdbarch_gdb_signal_to_target'. */
+
+static int
+windows_gdb_signal_to_target (struct gdbarch *gdbarch, enum gdb_signal signal)
+{
+ switch (signal)
+ {
+ case GDB_SIGNAL_0:
+ return 0;
+ case GDB_SIGNAL_HUP:
+ return WINDOWS_SIGHUP;
+ case GDB_SIGNAL_INT:
+ return WINDOWS_SIGINT;
+ case GDB_SIGNAL_QUIT:
+ return WINDOWS_SIGQUIT;
+ case GDB_SIGNAL_ILL:
+ return WINDOWS_SIGILL;
+ case GDB_SIGNAL_TRAP:
+ return WINDOWS_SIGTRAP;
+ case GDB_SIGNAL_ABRT:
+ return WINDOWS_SIGABRT;
+ case GDB_SIGNAL_EMT:
+ return WINDOWS_SIGEMT;
+ case GDB_SIGNAL_FPE:
+ return WINDOWS_SIGFPE;
+ case GDB_SIGNAL_KILL:
+ return WINDOWS_SIGKILL;
+ case GDB_SIGNAL_BUS:
+ return WINDOWS_SIGBUS;
+ case GDB_SIGNAL_SEGV:
+ return WINDOWS_SIGSEGV;
+ case GDB_SIGNAL_SYS:
+ return WINDOWS_SIGSYS;
+ case GDB_SIGNAL_PIPE:
+ return WINDOWS_SIGPIPE;
+ case GDB_SIGNAL_ALRM:
+ return WINDOWS_SIGALRM;
+ case GDB_SIGNAL_TERM:
+ return WINDOWS_SIGTERM;
+#ifdef __CYGWIN__
+ case GDB_SIGNAL_URG:
+ return WINDOWS_SIGURG;
+ case GDB_SIGNAL_STOP:
+ return WINDOWS_SIGSTOP;
+ case GDB_SIGNAL_TSTP:
+ return WINDOWS_SIGTSTP;
+ case GDB_SIGNAL_CONT:
+ return WINDOWS_SIGCONT;
+ case GDB_SIGNAL_CHLD:
+ return WINDOWS_SIGCHLD;
+ case GDB_SIGNAL_TTIN:
+ return WINDOWS_SIGTTIN;
+ case GDB_SIGNAL_TTOU:
+ return WINDOWS_SIGTTOU;
+ case GDB_SIGNAL_IO:
+ return WINDOWS_SIGIO;
+ case GDB_SIGNAL_XCPU:
+ return WINDOWS_SIGXCPU;
+ case GDB_SIGNAL_XFSZ:
+ return WINDOWS_SIGXFSZ;
+ case GDB_SIGNAL_VTALRM:
+ return WINDOWS_SIGVTALRM;
+ case GDB_SIGNAL_PROF:
+ return WINDOWS_SIGPROF;
+ case GDB_SIGNAL_WINCH:
+ return WINDOWS_SIGWINCH;
+ case GDB_SIGNAL_PWR:
+ return WINDOWS_SIGLOST;
+ case GDB_SIGNAL_USR1:
+ return WINDOWS_SIGUSR1;
+ case GDB_SIGNAL_USR2:
+ return WINDOWS_SIGUSR2;
+#endif /* __CYGWIN__ */
+ }
+ return -1;
+}
+
/* To be called from the various GDB_OSABI_CYGWIN handlers for the
various Windows architectures and machine types. */
@@ -477,6 +605,8 @@ windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
set_gdbarch_iterate_over_objfiles_in_search_order
(gdbarch, windows_iterate_over_objfiles_in_search_order);
+ set_gdbarch_gdb_signal_to_target (gdbarch, windows_gdb_signal_to_target);
+
set_solib_ops (gdbarch, &solib_target_so_ops);
}
base-commit: 44f81a76542dbeada2541a05de191ae0ac0fbc2c
--
2.14.5
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-12-18 18:33 ` Eli Zaretskii
2019-12-25 15:57 ` Eli Zaretskii
@ 2020-01-03 17:04 ` Pedro Alves
1 sibling, 0 replies; 26+ messages in thread
From: Pedro Alves @ 2020-01-03 17:04 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: philippe.waroquiers, gdb-patches
On 12/18/19 6:32 PM, Eli Zaretskii wrote:
>> Cc: philippe.waroquiers@skynet.be, gdb-patches@sourceware.org
>> From: Pedro Alves <palves@redhat.com>
>> Date: Wed, 18 Dec 2019 17:42:28 +0000
>>
>>> A new file for just one function sounds too much to me. Is it OK to
>>> define an inline function in gdb_wait.h, as in the prototype change
>>> below? If this way is accepted, I will post a fully formatted patch.
>>
>> I don't think it's too much. As a static inline function means that
>> you end up with multiple versions of the function, including
>> the mapping array, in the gdb binary. And also make gdb_wait.h
>> expose <windows.h>. You could add a new gdbsupport/gdb_wait.c
>> file, with the function wrapped in #ifdef __MINGW32__ to keep it simple
>> and avoid host/target checks in the configure.ac files.
>
> Sorry, I don't understand what host/target checks might be needed in
> configure.ac, can you explain?
What I meant is that files like mingw-hdep.o are conditionally added
to the set of files to build by configure.ac, depending on the host
triplet. An alternative mechanism would be to merge all of
mingw-hdep.c posix-hdep.c in a single .c file, and then use #ifdef
within. I was suggesting the latter mechanism for this new file.
>
>> We should not rely on signal.h constants for this hook. See gdbarch.sh:
>>
>> # Signal translation: translate the GDB's internal signal number into
>> # the inferior's signal (target's) representation. The implementation
>> # of this method must be host independent. IOW, don't rely on symbols
>> # of the NAT_FILE header (the nm-*.h files), the host <signal.h>
>> # header, or similar headers.
>> # Return the target signal number if found, or -1 if the GDB internal
>> # signal number is invalid.
>> M;int;gdb_signal_to_target;enum gdb_signal signal;signal
>>
>> Say you're debugging against a mingw gdbserver from a Linux host.
>> If you rely on <signal.h> constants here, this function is going to
>> return the Linux (or whatever the host) numbers instead of the
>> Windows/mingw numbers. For Linux, we define the LINUX_SIGxxx numbers
>> in linux-tdep.c, around line 125. The patch should add a similar
>> enum.
>
> So we need to have 2 different sets of explicit signal numbers, one
> for MinGW64, the other for mingw.org's MinGW (no, they are not
> identical)? And perhaps one more for Cygwin? Or should we just
> support the signals common to all 3 environments?
>
> And what do we do when the signal numbers in the system's signal.h
> header change in some future version of MinGW/Cygwin?
I would think signal numbers changing would be unlikely, since it
would be an ABI break.
> This sounds
> like a very fragile arrangement, at least for non-Posix systems where
> signals are emulated and aren't part of the kernel definitions set in
> stone. I'm okay with doing a bunch of defines, but it seems to me a
> maintenance headache in the long run, FWIW.
The alternative is that the cross debugging scenario
doesn't work. It doesn't seem better to me. A potential alternative
would be to offload the mapping/conversions to the remote/server
side somehow, but that can't work for cross-core debugging, so it's
not ideal either.
>
>> With this change, the user no longer has access to the original
>> $_exitcode, for the cases that match one of the known exceptions.
>> I don't know whether anyone is relying on those, though I wouldn't
>> be surprised if so. I assume you've pondered about this and consider
>> that the change is still worth it anyhow. This should at least be
>> documented. I wonder whether we should provide both the exit
>> code in $_exitcode and the translated signal number in $_exitsignal,
>> though that would require more changes.
>
> I think this is a micro-optimization that is way in the area of the
> diminishing returns. I've never seen a program to return an exit
> status with the high 2 bits set. I'd definitely not recommend to
> tweak the current assumption in the GDB code that if a program exited
> due to a signal, its exit code is irrelevant, based on such a
> theoretical possibility. In most cases, the fact that the inferior
> got a fatal exception will be noted before it exits anyway.
We're writing a debugger, and it doesn't seem odd to me that people
would like for the debugger to provide all information available
in order to debug the problem, rather than hide it.
You may be right that nobody actually cares about it, but I thought
I'd point it out so we can make an informed decision.
>
>> Related, when windows_status_to_termsig doesn't recognize the
>> exception number, we end up with GDB_SIGNAL_UNKNOWN, and then
>> $_exitsignal == -1. I.e., we lose information in that case. Again,
>> something to ponder about that information loss is OK, or whether
>> we should do something about it.
>
> I don't think we should do anything about it, it's highly theoretical
> situation I've never seen in real life. And we already lose
> information in windows-nat.c, when we return GDB_SIGNAL_UNKNOWN for
> any exception we don't recognize explicitly.
OK. We do print the raw Win32 exception before converting to
GDB_SIGNAL_UNKNOWN, so the user sees it, but I get your point.
> In any case, the way
> this stuff currently works, I see no simple way of returning an
> arbitrary value of a signal.
Yeah, I think we'd have to change struct target_waitstatus.
>
> Maybe we should abandon the idea of doing this in windows-nat.c and
> win32-low.c, and only translate the exit code in cli-cmds.c for the
> 'pipe' command? It's much more important in that case (since we don't
> intercept the signals as we do from the inferior), and most of those
> complications don't apply there. There's also no backward
> compatibility problem, since 'pipe' is a new feature in GDB 9, with 2
> new convenience variables to hold the exit status and the signal
> value. WDYT?
I don't know, I don't have a strong opinion. As I mentioned, I'm
only pointing out the issues so we hash it all out and make an
informed decision.
I'll take a look at your new patch.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-12-18 18:33 ` Eli Zaretskii
@ 2019-12-25 15:57 ` Eli Zaretskii
2020-01-03 19:59 ` Pedro Alves
2020-01-03 17:04 ` Pedro Alves
1 sibling, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2019-12-25 15:57 UTC (permalink / raw)
To: palves, philippe.waroquiers; +Cc: gdb-patches
No further comments, so I made additional changes to take care of
Pedro's review comments, and the result is below.
OK to commit?
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index acf9106..838eafd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,26 @@
+2019-12-25 Eli Zaretskii <eliz@gnu.org>
+
+ * 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 (get_windows_debug_event): Extract the fatal
+ exception from the exit status and convert to the equivalent Posix
+ signal number.
+
+ * gdbsupport/gdb_wait.c: New file, implements
+ windows_status_to_termsig.
+
+ * gdbsupport/gdb_wait.h (WIFEXITED, WIFSIGNALED, WEXITSTATUS)
+ (WTERMSIG) [__MINGW32__]: Separate definitions for MinGW.
+
+ * cli/cli-cmds.c (exit_status_set_internal_vars): Account for the
+ possibility that WTERMSIG returns GDB_SIGNAL_UNKNOWN.
+
+ * Makefile.in (COMMON_SFILES): Add gdbsupport/gdb_wait.c.
+
2019-12-21 George Barrett <bob@bob131.so>
* solib-svr4.c (svr4_handle_solib_event): Add fallback link
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index fa5c820..34d0acf 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -986,6 +986,7 @@ COMMON_SFILES = \
gdbsupport/gdb-dlfcn.c \
gdbsupport/gdb_tilde_expand.c \
gdbsupport/gdb_vecs.c \
+ gdbsupport/gdb_wait.c \
gdbsupport/netstuff.c \
gdbsupport/new-op.c \
gdbsupport/pathstuff.c \
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 681d53c..0d1584e 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -798,10 +798,16 @@ exit_status_set_internal_vars (int exit_status)
clear_internalvar (var_code);
clear_internalvar (var_signal);
- if (WIFEXITED (exit_status))
- set_internalvar_integer (var_code, WEXITSTATUS (exit_status));
- else if (WIFSIGNALED (exit_status))
+ enum gdb_signal exit_signal
+ = WIFSIGNALED (exit_status) ? WTERMSIG (exit_status) : GDB_SIGNAL_UNKNOWN;
+ /* The GDB_SIGNAL_UNKNOWN condition can happen on MinGW, if we don't
+ recognize the fatal exception code encoded in the exit status;
+ see gdb_wait.c. We don't want to lose information in the exit
+ status in that case. */
+ if (exit_signal != GDB_SIGNAL_UNKNOWN)
set_internalvar_integer (var_signal, WTERMSIG (exit_status));
+ else if (!WIFSIGNALED (exit_status))
+ set_internalvar_integer (var_code, WEXITSTATUS (exit_status));
else
warning (_("unexpected shell command exit status %d"), exit_status);
}
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 10d5c95..12e50b6 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -68,6 +68,7 @@
#include "inf-child.h"
#include "gdbsupport/gdb_tilde_expand.h"
#include "gdbsupport/pathstuff.h"
+#include "gdbsupport/gdb_wait.h"
#define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
#define DebugActiveProcessStop dyn_DebugActiveProcessStop
@@ -1620,8 +1621,22 @@ get_windows_debug_event (struct target_ops *ops,
windows_delete_thread (ptid_t (current_event.dwProcessId, 0,
current_event.dwThreadId),
0, true /* main_thread_p */);
- ourstatus->kind = TARGET_WAITKIND_EXITED;
- ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
+ 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. */
+ enum gdb_signal exit_signal = WIFSIGNALED (exit_status)
+ ? WTERMSIG (exit_status) : GDB_SIGNAL_UNKNOWN;
+ if (exit_signal == GDB_SIGNAL_UNKNOWN)
+ {
+ ourstatus->kind = TARGET_WAITKIND_EXITED;
+ ourstatus->value.integer = exit_status;
+ }
+ else
+ {
+ ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
+ ourstatus->value.sig = exit_signal;
+ }
thread_id = current_event.dwThreadId;
}
break;
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index bb69a79..c2cecce 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -35,6 +35,55 @@
#include "solib-target.h"
#include "gdbcore.h"
+/* Windows signal numbers differ between MinGW flavors and between
+ those and Cygwin. The below enumeration was gleaned from the
+ respective headers; the ones marked with MinGW64/Cygwin are defined
+ only by MinGW64 and Cygwin, not by mingw.org's MinGW. */
+
+enum
+ {
+ WINDOWS_SIGHUP = 1, /* MinGW64/Cygwin */
+ WINDOWS_SIGINT = 2,
+ WINDOWS_SIGQUIT = 3, /* MinGW64/Cygwin */
+ WINDOWS_SIGILL = 4,
+ WINDOWS_SIGTRAP = 5, /* MinGW64/Cygwin */
+#ifdef __CYGWIN__
+ WINDOWS_SGABRT = 6,
+#else
+ WINDOWS_SIGIOT = 6, /* MinGW64 */
+#endif
+ WINDOWS_SIGEMT = 7, /* MinGW64/Cygwin */
+ WINDOWS_SIGFPE = 8,
+ WINDOWS_SIGKILL = 9, /* MinGW64/Cygwin */
+ WINDOWS_SIGBUS = 10, /* MinGW64/Cygwin */
+ WINDOWS_SIGSEGV = 11,
+ WINDOWS_SIGSYS = 12, /* MinGW64/Cygwin */
+ WINDOWS_SIGPIPE = 13,/* MinGW64/Cygwin */
+ WINDOWS_SIGALRM = 14,/* MinGW64/Cygwin */
+ WINDOWS_SIGTERM = 15,
+#ifdef __CYGWIN__
+ WINDOWS_SIGURG = 16,
+ WINDOWS_SIGSTOP = 17,
+ WINDOWS_SIGTSTP = 18,
+ WINDOWS_SIGCONT = 19,
+ WINDOWS_SIGCHLD = 20,
+ WINDOWS_SIGTTIN = 21,
+ WINDOWS_SIGTTOU = 22,
+ WINDOWS_SIGIO = 23,
+ WINDOWS_SIGXCPU = 24,
+ WINDOWS_SIGXFSZ = 25,
+ WINDOWS_SIGVTALRM = 26,
+ WINDOWS_SIGPROF = 27,
+ WINDOWS_SIGWINCH = 28,
+ WINDOWS_SIGLOST = 29,
+ WINDOWS_SIGUSR1 = 30,
+ WINDOWS_SIGUSR2 = 31
+#else
+ WINDOWS_SIGBREAK = 21,
+ WINDOWS_SIGABRT = 22
+#endif
+ };
+
struct cmd_list_element *info_w32_cmdlist;
typedef struct thread_information_block_32
@@ -461,6 +510,81 @@ init_w32_command_list (void)
}
}
+static int
+windows_gdb_signal_to_target (struct gdbarch *gdbarch, enum gdb_signal signal)
+{
+ switch (signal)
+ {
+ case GDB_SIGNAL_0:
+ return 0;
+ case GDB_SIGNAL_HUP:
+ return WINDOWS_SIGHUP;
+ case GDB_SIGNAL_INT:
+ return WINDOWS_SIGINT;
+ case GDB_SIGNAL_QUIT:
+ return WINDOWS_SIGQUIT;
+ case GDB_SIGNAL_ILL:
+ return WINDOWS_SIGILL;
+ case GDB_SIGNAL_TRAP:
+ return WINDOWS_SIGTRAP;
+ case GDB_SIGNAL_ABRT:
+ return WINDOWS_SIGABRT;
+ case GDB_SIGNAL_EMT:
+ return WINDOWS_SIGEMT;
+ case GDB_SIGNAL_FPE:
+ return WINDOWS_SIGFPE;
+ case GDB_SIGNAL_KILL:
+ return WINDOWS_SIGKILL;
+ case GDB_SIGNAL_BUS:
+ return WINDOWS_SIGBUS;
+ case GDB_SIGNAL_SEGV:
+ return WINDOWS_SIGSEGV;
+ case GDB_SIGNAL_SYS:
+ return WINDOWS_SIGSYS;
+ case GDB_SIGNAL_PIPE:
+ return WINDOWS_SIGPIPE;
+ case GDB_SIGNAL_ALRM:
+ return WINDOWS_SIGALRM;
+ case GDB_SIGNAL_TERM:
+ return WINDOWS_SIGTERM;
+#ifdef __CYGWIN__
+ case GDB_SIGNAL_URG:
+ return WINDOWS_SIGURG;
+ case GDB_SIGNAL_STOP:
+ return WINDOWS_SIGSTOP;
+ case GDB_SIGNAL_TSTP:
+ return WINDOWS_SIGTSTP;
+ case GDB_SIGNAL_CONT:
+ return WINDOWS_SIGCONT;
+ case GDB_SIGNAL_CHLD:
+ return WINDOWS_SIGCHLD;
+ case GDB_SIGNAL_TTIN:
+ return WINDOWS_SIGTTIN;
+ case GDB_SIGNAL_TTOU:
+ return WINDOWS_SIGTTOU;
+ case GDB_SIGNAL_IO:
+ return WINDOWS_SIGIO;
+ case GDB_SIGNAL_XCPU:
+ return WINDOWS_SIGXCPU;
+ case GDB_SIGNAL_XFSZ:
+ return WINDOWS_SIGXFSZ;
+ case GDB_SIGNAL_VTALRM:
+ return WINDOWS_SIGVTALRM;
+ case GDB_SIGNAL_PROF:
+ return WINDOWS_SIGPROF;
+ case GDB_SIGNAL_WINCH:
+ return WINDOWS_SIGWINCH;
+ case GDB_SIGNAL_PWR:
+ return WINDOWS_SIGLOST;
+ case GDB_SIGNAL_USR1:
+ return WINDOWS_SIGUSR1;
+ case GDB_SIGNAL_USR2:
+ return WINDOWS_SIGUSR2;
+#endif /* __CYGWIN__ */
+ }
+ return -1;
+}
+
/* To be called from the various GDB_OSABI_CYGWIN handlers for the
various Windows architectures and machine types. */
@@ -477,6 +601,8 @@ windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
set_gdbarch_iterate_over_objfiles_in_search_order
(gdbarch, windows_iterate_over_objfiles_in_search_order);
+ set_gdbarch_gdb_signal_to_target (gdbarch, windows_gdb_signal_to_target);
+
set_solib_ops (gdbarch, &solib_target_so_ops);
}
diff --git a/gdb/gdbsupport/gdb_wait.h b/gdb/gdbsupport/gdb_wait.h
index b3b752c..e8597f9 100644
--- a/gdb/gdbsupport/gdb_wait.h
+++ b/gdb/gdbsupport/gdb_wait.h
@@ -38,20 +38,33 @@
in POSIX.1. We fail to define WNOHANG and WUNTRACED, which POSIX.1
<sys/wait.h> defines, since our code does not use waitpid() (but
NOTE exception for GNU/Linux below). We also fail to declare
- wait() and waitpid(). */
+ wait() and waitpid().
+
+ For MinGW, we use the fact that 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. See also gdb_wait.c. */
#ifndef WIFEXITED
-#define WIFEXITED(w) (((w)&0377) == 0)
+# ifdef __MINGW32__
+# define WIFEXITED(w) (((w) & 0xC0000000) == 0)
+# else
+# define WIFEXITED(w) (((w)&0377) == 0)
+# endif
#endif
#ifndef WIFSIGNALED
-#define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
+# ifdef __MINGW32__
+# define WIFSIGNALED(w) (((w) & 0xC0000000) == 0xC0000000)
+# else
+# define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
+# endif
#endif
#ifndef WIFSTOPPED
#ifdef IBM6000
-/* Unfortunately, the above comment (about being compatible in all Unix
+/* Unfortunately, the above comment (about being compatible in all Unix
systems) is not quite correct for AIX, sigh. And AIX 3.2 can generate
status words like 0x57c (sigtrap received after load), and gdb would
choke on it. */
@@ -64,11 +77,20 @@
#endif
#ifndef WEXITSTATUS
-#define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */
+# ifdef __MINGW32__
+# define WEXITSTATUS(w) ((w) & ~0xC0000000)
+# else
+# define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */
+# endif
#endif
#ifndef WTERMSIG
-#define WTERMSIG(w) ((w) & 0177)
+# ifdef __MINGW32__
+extern enum gdb_signal windows_status_to_termsig (unsigned long);
+# define WTERMSIG(w) windows_status_to_termsig (w)
+# else
+# define WTERMSIG(w) ((w) & 0177)
+# endif
#endif
#ifndef WSTOPSIG
diff --git a/gdb/gdbsupport/gdb_wait.c b/gdb/gdbsupport/gdb_wait.c
new file mode 100644
index 0000000..7096152
--- /dev/null
+++ b/gdb/gdbsupport/gdb_wait.c
@@ -0,0 +1,80 @@
+/* Support code for standard wait macros in gdb_wait.h.
+
+ Copyright (C) 2019 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "common-defs.h"
+
+#ifdef __MINGW32__
+
+/* The underlying idea is that 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. We thus emulate WTERMSIG etc. by translating the fatal
+ exception codes to more-or-less equivalent Posix signals.
+
+ The translation below is not perfect, because a program could
+ legitimately exit normally with a status whose value happens to
+ have the high bits set, but that's extremely rare, to say the
+ least, and it is deemed such a negligibly small probability of
+ false positives is justified by the utility of reporting the
+ terminating signal in the "normal" cases. */
+
+# include "gdb/signals.h" /* for enum gdb_signal */
+
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h> /* for EXCEPTION_* constants */
+
+struct xlate_status
+{
+ DWORD status; /* exit status (actually, fatal exception code) */
+ enum gdb_signal sig; /* corresponding GDB signal value */
+};
+
+enum gdb_signal
+windows_status_to_termsig (unsigned long status)
+{
+ static const xlate_status status_xlate_tbl[] =
+ {
+ {EXCEPTION_ACCESS_VIOLATION, GDB_SIGNAL_SEGV},
+ {EXCEPTION_IN_PAGE_ERROR, GDB_SIGNAL_SEGV},
+ {EXCEPTION_INVALID_HANDLE, GDB_SIGNAL_SEGV},
+ {EXCEPTION_ILLEGAL_INSTRUCTION, GDB_SIGNAL_ILL},
+ {EXCEPTION_NONCONTINUABLE_EXCEPTION, GDB_SIGNAL_ILL},
+ {EXCEPTION_ARRAY_BOUNDS_EXCEEDED, GDB_SIGNAL_SEGV},
+ {EXCEPTION_FLT_DENORMAL_OPERAND, GDB_SIGNAL_FPE},
+ {EXCEPTION_FLT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE},
+ {EXCEPTION_FLT_INEXACT_RESULT, GDB_SIGNAL_FPE},
+ {EXCEPTION_FLT_INVALID_OPERATION, GDB_SIGNAL_FPE},
+ {EXCEPTION_FLT_OVERFLOW, GDB_SIGNAL_FPE},
+ {EXCEPTION_FLT_STACK_CHECK, GDB_SIGNAL_FPE},
+ {EXCEPTION_FLT_UNDERFLOW, GDB_SIGNAL_FPE},
+ {EXCEPTION_INT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE},
+ {EXCEPTION_INT_OVERFLOW, GDB_SIGNAL_FPE},
+ {EXCEPTION_PRIV_INSTRUCTION, GDB_SIGNAL_ILL},
+ {EXCEPTION_STACK_OVERFLOW, GDB_SIGNAL_SEGV},
+ {CONTROL_C_EXIT, GDB_SIGNAL_TERM}
+ };
+
+ for (const xlate_status &x : status_xlate_tbl)
+ if (x.status == status)
+ return x.sig;
+
+ return GDB_SIGNAL_UNKNOWN;
+}
+
+#endif /* __MINGW32__ */
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 028d1e9..41e4ed1 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,12 @@
+2019-12-25 Eli Zaretskii <eliz@gnu.org>
+
+ * 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].
+
2019-12-19 Christian Biesinger <cbiesinger@google.com>
* configure: Regenerate.
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 9e8c213..8022753 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -217,6 +217,7 @@ SFILES = \
$(srcdir)/gdbsupport/gdb-dlfcn.c \
$(srcdir)/gdbsupport/gdb_tilde_expand.c \
$(srcdir)/gdbsupport/gdb_vecs.c \
+ $(srcdir)/gdbsupport/gdb_wait.c \
$(srcdir)/gdbsupport/netstuff.c \
$(srcdir)/gdbsupport/new-op.c \
$(srcdir)/gdbsupport/pathstuff.c \
@@ -264,6 +265,7 @@ OBS = \
gdbsupport/gdb-dlfcn.o \
gdbsupport/gdb_tilde_expand.o \
gdbsupport/gdb_vecs.o \
+ gdbsupport/gdb_wait.o \
gdbsupport/netstuff.o \
gdbsupport/new-op.o \
gdbsupport/pathstuff.o \
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index 449ed5f..d6ff794 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -34,6 +34,7 @@
#include <process.h>
#include "gdbsupport/gdb_tilde_expand.h"
#include "gdbsupport/common-inferior.h"
+#include "gdbsupport/gdb_wait.h"
#ifndef USE_WIN32API
#include <sys/cygwin.h>
@@ -1511,8 +1512,24 @@ get_child_debug_event (struct target_waitstatus *ourstatus)
"for pid=%u tid=%x\n",
(unsigned) current_event.dwProcessId,
(unsigned) current_event.dwThreadId));
- ourstatus->kind = TARGET_WAITKIND_EXITED;
- ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
+ {
+ 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. */
+ enum gdb_signal exit_signal = WIFSIGNALED (exit_status)
+ ? WTERMSIG (exit_status) : GDB_SIGNAL_UNKNOWN;
+ if (exit_signal == GDB_SIGNAL_UNKNOWN)
+ {
+ ourstatus->kind = TARGET_WAITKIND_EXITED;
+ ourstatus->value.integer = exit_status;
+ }
+ else
+ {
+ ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
+ ourstatus->value.sig = exit_signal;
+ }
+ }
child_continue (DBG_CONTINUE, -1);
CloseHandle (current_process_handle);
current_process_handle = NULL;
@@ -1607,6 +1624,7 @@ win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options)
win32_clear_inferiors ();
return ptid_t (current_event.dwProcessId);
case TARGET_WAITKIND_STOPPED:
+ case TARGET_WAITKIND_SIGNALLED:
case TARGET_WAITKIND_LOADED:
OUTMSG2 (("Child Stopped with signal = %d \n",
ourstatus->value.sig));
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-12-18 17:42 ` Pedro Alves
@ 2019-12-18 18:33 ` Eli Zaretskii
2019-12-25 15:57 ` Eli Zaretskii
2020-01-03 17:04 ` Pedro Alves
0 siblings, 2 replies; 26+ messages in thread
From: Eli Zaretskii @ 2019-12-18 18:33 UTC (permalink / raw)
To: Pedro Alves; +Cc: philippe.waroquiers, gdb-patches
> Cc: philippe.waroquiers@skynet.be, gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Wed, 18 Dec 2019 17:42:28 +0000
>
> > A new file for just one function sounds too much to me. Is it OK to
> > define an inline function in gdb_wait.h, as in the prototype change
> > below? If this way is accepted, I will post a fully formatted patch.
>
> I don't think it's too much. As a static inline function means that
> you end up with multiple versions of the function, including
> the mapping array, in the gdb binary. And also make gdb_wait.h
> expose <windows.h>. You could add a new gdbsupport/gdb_wait.c
> file, with the function wrapped in #ifdef __MINGW32__ to keep it simple
> and avoid host/target checks in the configure.ac files.
Sorry, I don't understand what host/target checks might be needed in
configure.ac, can you explain?
> We should not rely on signal.h constants for this hook. See gdbarch.sh:
>
> # Signal translation: translate the GDB's internal signal number into
> # the inferior's signal (target's) representation. The implementation
> # of this method must be host independent. IOW, don't rely on symbols
> # of the NAT_FILE header (the nm-*.h files), the host <signal.h>
> # header, or similar headers.
> # Return the target signal number if found, or -1 if the GDB internal
> # signal number is invalid.
> M;int;gdb_signal_to_target;enum gdb_signal signal;signal
>
> Say you're debugging against a mingw gdbserver from a Linux host.
> If you rely on <signal.h> constants here, this function is going to
> return the Linux (or whatever the host) numbers instead of the
> Windows/mingw numbers. For Linux, we define the LINUX_SIGxxx numbers
> in linux-tdep.c, around line 125. The patch should add a similar
> enum.
So we need to have 2 different sets of explicit signal numbers, one
for MinGW64, the other for mingw.org's MinGW (no, they are not
identical)? And perhaps one more for Cygwin? Or should we just
support the signals common to all 3 environments?
And what do we do when the signal numbers in the system's signal.h
header change in some future version of MinGW/Cygwin? This sounds
like a very fragile arrangement, at least for non-Posix systems where
signals are emulated and aren't part of the kernel definitions set in
stone. I'm okay with doing a bunch of defines, but it seems to me a
maintenance headache in the long run, FWIW.
> With this change, the user no longer has access to the original
> $_exitcode, for the cases that match one of the known exceptions.
> I don't know whether anyone is relying on those, though I wouldn't
> be surprised if so. I assume you've pondered about this and consider
> that the change is still worth it anyhow. This should at least be
> documented. I wonder whether we should provide both the exit
> code in $_exitcode and the translated signal number in $_exitsignal,
> though that would require more changes.
I think this is a micro-optimization that is way in the area of the
diminishing returns. I've never seen a program to return an exit
status with the high 2 bits set. I'd definitely not recommend to
tweak the current assumption in the GDB code that if a program exited
due to a signal, its exit code is irrelevant, based on such a
theoretical possibility. In most cases, the fact that the inferior
got a fatal exception will be noted before it exits anyway.
> Related, when windows_status_to_termsig doesn't recognize the
> exception number, we end up with GDB_SIGNAL_UNKNOWN, and then
> $_exitsignal == -1. I.e., we lose information in that case. Again,
> something to ponder about that information loss is OK, or whether
> we should do something about it.
I don't think we should do anything about it, it's highly theoretical
situation I've never seen in real life. And we already lose
information in windows-nat.c, when we return GDB_SIGNAL_UNKNOWN for
any exception we don't recognize explicitly. In any case, the way
this stuff currently works, I see no simple way of returning an
arbitrary value of a signal.
Maybe we should abandon the idea of doing this in windows-nat.c and
win32-low.c, and only translate the exit code in cli-cmds.c for the
'pipe' command? It's much more important in that case (since we don't
intercept the signals as we do from the inferior), and most of those
complications don't apply there. There's also no backward
compatibility problem, since 'pipe' is a new feature in GDB 9, with 2
new convenience variables to hold the exit status and the signal
value. WDYT?
Thanks.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-12-18 17:08 ` Eli Zaretskii
@ 2019-12-18 17:42 ` Pedro Alves
2019-12-18 18:33 ` Eli Zaretskii
0 siblings, 1 reply; 26+ messages in thread
From: Pedro Alves @ 2019-12-18 17:42 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: philippe.waroquiers, gdb-patches
On 12/18/19 5:07 PM, Eli Zaretskii wrote:
>> Cc: philippe.waroquiers@skynet.be, gdb-patches@sourceware.org
>> From: Pedro Alves <palves@redhat.com>
>> Date: Tue, 17 Dec 2019 17:51:26 +0000
>>
>> The issue pointed out was that by putting the windows_status_to_termsig
>> function in windows-nat.c, and then calling it from gdb's common code
>> (cli/cli-cmds.c, via WTERMSIG) would result in a build/link failure when
>> you try to build a cross debugger hosted on mingw, because such a gdb
>> build does not include the native Windows target support, i.e., does not
>> build/link the windows-nat.o object. Putting said function in mingw-hdep.c
>> instead fixes that issue because that file is included as part of the build
>> in all kinds of mingw-hosted GDBs, either native or cross-debugger.
>>
>>>> I admit to being a bit confused about why we want to do this
>>>> translation for this feature while we don't do it for the exit code
>>>> of inferiors running under gdb, for example. I mean, exit status
>>>> with 0xc0000000 set don't cause $_exitsignal to be set instead of
>>>> $_exitcode.
>>>
>>> Yes, we should do this for exit code of inferiors as well.
>>>
>>> Native MS-Windows debugging produces the TARGET_WAITKIND_* values in
>>> windows-nat.c, so I think the conversion we are talking about will
>>> have to be done there, perhaps _in_addition_to_ other places? IOW,
>>> the function that performs the conversion can be defined in
>>> mingw-hdep.c, but it will have to be called from windows-nat.c at
>>> least, right? And I'm uncertain what other places will have to call
>>> that conversion function for the use case of running a cross-debugger,
>>> can someone please help me understand that?
>>
>> You'll also want to call it in gdbserver's win32-low.c file, so that
>> you get the translation too when debugging against gdbserver.
>> This actually suggests putting the new function in some new
>> shared file in gdb/gdbsupport/, since gdb/mingw-hdep.c is gdb-only.
>
> A new file for just one function sounds too much to me. Is it OK to
> define an inline function in gdb_wait.h, as in the prototype change
> below? If this way is accepted, I will post a fully formatted patch.
I don't think it's too much. As a static inline function means that
you end up with multiple versions of the function, including
the mapping array, in the gdb binary. And also make gdb_wait.h
expose <windows.h>. You could add a new gdbsupport/gdb_wait.c
file, with the function wrapped in #ifdef __MINGW32__ to keep it simple
and avoid host/target checks in the configure.ac files.
>
> Thanks.
>
> --- gdb/gdbsupport/gdb_wait.h~0 2019-09-21 00:58:17.000000000 +0300
> +++ gdb/gdbsupport/gdb_wait.h 2019-12-18 17:59:28.434097000 +0200
> @@ -40,18 +40,84 @@
> NOTE exception for GNU/Linux below). We also fail to declare
> wait() and waitpid(). */
>
> +/* For MINGW, the underlying idea is that 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.
> +
> + The translation below is not perfect, because a program could
> + legitimately exit normally with a status whose value happens to
> + have the high bits set, but that's extremely rare, to say the
> + least, and it is deemed such a negligibly small probability of
> + false positives is justified by the utility of reporting the
> + terminating signal in the "normal" cases. */
> +
> +#ifdef __MINGW32__
> +
> +# define WIN32_LEAN_AND_MEAN
> +# include <windows.h> /* for EXCEPTION_* constants */
> +# include "gdb/signals.h" /* for enum gdb_signal */
> +
> +struct xlate_status
> +{
> + DWORD status; /* exit status (actually, fatal exception code) */
> + enum gdb_signal sig; /* corresponding GDB signal value */
> +};
> +
> +static inline enum gdb_signal
> +windows_status_to_termsig (DWORD status)
> +{
> + static const xlate_status status_xlate_tbl[] =
> + {
> + {EXCEPTION_ACCESS_VIOLATION, GDB_SIGNAL_SEGV},
> + {EXCEPTION_IN_PAGE_ERROR, GDB_SIGNAL_SEGV},
> + {EXCEPTION_INVALID_HANDLE, GDB_SIGNAL_SEGV},
> + {EXCEPTION_ILLEGAL_INSTRUCTION, GDB_SIGNAL_ILL},
> + {EXCEPTION_NONCONTINUABLE_EXCEPTION, GDB_SIGNAL_ILL},
> + {EXCEPTION_ARRAY_BOUNDS_EXCEEDED, GDB_SIGNAL_SEGV},
> + {EXCEPTION_FLT_DENORMAL_OPERAND, GDB_SIGNAL_FPE},
> + {EXCEPTION_FLT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE},
> + {EXCEPTION_FLT_INEXACT_RESULT, GDB_SIGNAL_FPE},
> + {EXCEPTION_FLT_INVALID_OPERATION, GDB_SIGNAL_FPE},
> + {EXCEPTION_FLT_OVERFLOW, GDB_SIGNAL_FPE},
> + {EXCEPTION_FLT_STACK_CHECK, GDB_SIGNAL_FPE},
> + {EXCEPTION_FLT_UNDERFLOW, GDB_SIGNAL_FPE},
> + {EXCEPTION_INT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE},
> + {EXCEPTION_INT_OVERFLOW, GDB_SIGNAL_FPE},
> + {EXCEPTION_PRIV_INSTRUCTION, GDB_SIGNAL_ILL},
> + {EXCEPTION_STACK_OVERFLOW, GDB_SIGNAL_SEGV},
> + {CONTROL_C_EXIT, GDB_SIGNAL_TERM}
> + };
> +
> + for (const xlate_status &x : status_xlate_tbl)
> + if (x.status == status)
> + return x.sig;
> +
> + return GDB_SIGNAL_UNKNOWN;
> +}
> +
> +#endif /* __MINGW32__ */
> +
> #ifndef WIFEXITED
> -#define WIFEXITED(w) (((w)&0377) == 0)
> +# ifdef __MINGW32__
> +# define WIFEXITED(w) (((w) & 0xC0000000) == 0)
> +# else
> +# define WIFEXITED(w) (((w)&0377) == 0)
> +# endif
> #endif
>
> #ifndef WIFSIGNALED
> -#define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
> +# ifdef __MINGW32__
> +# define WIFSIGNALED(w) (((w) & 0xC0000000) == 0xC0000000)
> +# else
> +# define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
> +# endif
> #endif
>
> #ifndef WIFSTOPPED
> #ifdef IBM6000
>
> -/* Unfortunately, the above comment (about being compatible in all Unix
> +/* Unfortunately, the above comment (about being compatible in all Unix
> systems) is not quite correct for AIX, sigh. And AIX 3.2 can generate
> status words like 0x57c (sigtrap received after load), and gdb would
> choke on it. */
> @@ -64,11 +130,19 @@
> #endif
>
> #ifndef WEXITSTATUS
> -#define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */
> +# ifdef __MINGW32__
> +# define WEXITSTATUS(w) ((w) & ~0xC0000000)
> +# else
> +# define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */
> +# endif
> #endif
>
> #ifndef WTERMSIG
> -#define WTERMSIG(w) ((w) & 0177)
> +# ifdef __MINGW32__
> +# define WTERMSIG(w) windows_status_to_termsig (w)
> +# else
> +# define WTERMSIG(w) ((w) & 0177)
> +# endif
> #endif
>
> #ifndef WSTOPSIG
> --- gdb/windows-nat.c~0 2019-12-11 22:24:51.000000000 +0200
> +++ gdb/windows-nat.c 2019-12-18 18:21:00.264558400 +0200
> @@ -68,6 +68,7 @@
> #include "inf-child.h"
> #include "gdbsupport/gdb_tilde_expand.h"
> #include "gdbsupport/pathstuff.h"
> +#include "gdbsupport/gdb_wait.h"
>
> #define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
> #define DebugActiveProcessStop dyn_DebugActiveProcessStop
> @@ -1620,8 +1621,17 @@ get_windows_debug_event (struct target_o
> windows_delete_thread (ptid_t (current_event.dwProcessId, 0,
> current_event.dwThreadId),
> 0, true /* main_thread_p */);
> - ourstatus->kind = TARGET_WAITKIND_EXITED;
> - ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
> + DWORD exit_status = current_event.u.ExitProcess.dwExitCode;
> + if (WIFEXITED (exit_status))
> + {
> + ourstatus->kind = TARGET_WAITKIND_EXITED;
> + ourstatus->value.integer = WEXITSTATUS (exit_status);
> + }
> + else
> + {
> + ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
> + ourstatus->value.sig = WTERMSIG (exit_status);
> + }
> thread_id = current_event.dwThreadId;
> }
> break;
> --- gdb/windows-tdep.c~0 2019-09-21 00:58:17.000000000 +0300
> +++ gdb/windows-tdep.c 2019-12-18 17:49:52.360580700 +0200
> @@ -35,6 +35,8 @@
> #include "solib-target.h"
> #include "gdbcore.h"
>
> +#include <signal.h>
> +
>
> +static int
> +windows_gdb_signal_to_target (struct gdbarch *gdbarch, enum gdb_signal signal)
> +{
We should not rely on signal.h constants for this hook. See gdbarch.sh:
# Signal translation: translate the GDB's internal signal number into
# the inferior's signal (target's) representation. The implementation
# of this method must be host independent. IOW, don't rely on symbols
# of the NAT_FILE header (the nm-*.h files), the host <signal.h>
# header, or similar headers.
# Return the target signal number if found, or -1 if the GDB internal
# signal number is invalid.
M;int;gdb_signal_to_target;enum gdb_signal signal;signal
Say you're debugging against a mingw gdbserver from a Linux host.
If you rely on <signal.h> constants here, this function is going to
return the Linux (or whatever the host) numbers instead of the
Windows/mingw numbers. For Linux, we define the LINUX_SIGxxx numbers
in linux-tdep.c, around line 125. The patch should add a similar
enum.
Some overall comments:
With this change, the user no longer has access to the original
$_exitcode, for the cases that match one of the known exceptions.
I don't know whether anyone is relying on those, though I wouldn't
be surprised if so. I assume you've pondered about this and consider
that the change is still worth it anyhow. This should at least be
documented. I wonder whether we should provide both the exit
code in $_exitcode and the translated signal number in $_exitsignal,
though that would require more changes.
Related, when windows_status_to_termsig doesn't recognize the
exception number, we end up with GDB_SIGNAL_UNKNOWN, and then
$_exitsignal == -1. I.e., we lose information in that case. Again,
something to ponder about that information loss is OK, or whether
we should do something about it.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-12-17 17:51 ` Pedro Alves
@ 2019-12-18 17:08 ` Eli Zaretskii
2019-12-18 17:42 ` Pedro Alves
0 siblings, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2019-12-18 17:08 UTC (permalink / raw)
To: Pedro Alves; +Cc: philippe.waroquiers, gdb-patches
> Cc: philippe.waroquiers@skynet.be, gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Tue, 17 Dec 2019 17:51:26 +0000
>
> The issue pointed out was that by putting the windows_status_to_termsig
> function in windows-nat.c, and then calling it from gdb's common code
> (cli/cli-cmds.c, via WTERMSIG) would result in a build/link failure when
> you try to build a cross debugger hosted on mingw, because such a gdb
> build does not include the native Windows target support, i.e., does not
> build/link the windows-nat.o object. Putting said function in mingw-hdep.c
> instead fixes that issue because that file is included as part of the build
> in all kinds of mingw-hosted GDBs, either native or cross-debugger.
>
> >> I admit to being a bit confused about why we want to do this
> >> translation for this feature while we don't do it for the exit code
> >> of inferiors running under gdb, for example. I mean, exit status
> >> with 0xc0000000 set don't cause $_exitsignal to be set instead of
> >> $_exitcode.
> >
> > Yes, we should do this for exit code of inferiors as well.
> >
> > Native MS-Windows debugging produces the TARGET_WAITKIND_* values in
> > windows-nat.c, so I think the conversion we are talking about will
> > have to be done there, perhaps _in_addition_to_ other places? IOW,
> > the function that performs the conversion can be defined in
> > mingw-hdep.c, but it will have to be called from windows-nat.c at
> > least, right? And I'm uncertain what other places will have to call
> > that conversion function for the use case of running a cross-debugger,
> > can someone please help me understand that?
>
> You'll also want to call it in gdbserver's win32-low.c file, so that
> you get the translation too when debugging against gdbserver.
> This actually suggests putting the new function in some new
> shared file in gdb/gdbsupport/, since gdb/mingw-hdep.c is gdb-only.
A new file for just one function sounds too much to me. Is it OK to
define an inline function in gdb_wait.h, as in the prototype change
below? If this way is accepted, I will post a fully formatted patch.
Thanks.
--- gdb/gdbsupport/gdb_wait.h~0 2019-09-21 00:58:17.000000000 +0300
+++ gdb/gdbsupport/gdb_wait.h 2019-12-18 17:59:28.434097000 +0200
@@ -40,18 +40,84 @@
NOTE exception for GNU/Linux below). We also fail to declare
wait() and waitpid(). */
+/* For MINGW, the underlying idea is that 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.
+
+ The translation below is not perfect, because a program could
+ legitimately exit normally with a status whose value happens to
+ have the high bits set, but that's extremely rare, to say the
+ least, and it is deemed such a negligibly small probability of
+ false positives is justified by the utility of reporting the
+ terminating signal in the "normal" cases. */
+
+#ifdef __MINGW32__
+
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h> /* for EXCEPTION_* constants */
+# include "gdb/signals.h" /* for enum gdb_signal */
+
+struct xlate_status
+{
+ DWORD status; /* exit status (actually, fatal exception code) */
+ enum gdb_signal sig; /* corresponding GDB signal value */
+};
+
+static inline enum gdb_signal
+windows_status_to_termsig (DWORD status)
+{
+ static const xlate_status status_xlate_tbl[] =
+ {
+ {EXCEPTION_ACCESS_VIOLATION, GDB_SIGNAL_SEGV},
+ {EXCEPTION_IN_PAGE_ERROR, GDB_SIGNAL_SEGV},
+ {EXCEPTION_INVALID_HANDLE, GDB_SIGNAL_SEGV},
+ {EXCEPTION_ILLEGAL_INSTRUCTION, GDB_SIGNAL_ILL},
+ {EXCEPTION_NONCONTINUABLE_EXCEPTION, GDB_SIGNAL_ILL},
+ {EXCEPTION_ARRAY_BOUNDS_EXCEEDED, GDB_SIGNAL_SEGV},
+ {EXCEPTION_FLT_DENORMAL_OPERAND, GDB_SIGNAL_FPE},
+ {EXCEPTION_FLT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE},
+ {EXCEPTION_FLT_INEXACT_RESULT, GDB_SIGNAL_FPE},
+ {EXCEPTION_FLT_INVALID_OPERATION, GDB_SIGNAL_FPE},
+ {EXCEPTION_FLT_OVERFLOW, GDB_SIGNAL_FPE},
+ {EXCEPTION_FLT_STACK_CHECK, GDB_SIGNAL_FPE},
+ {EXCEPTION_FLT_UNDERFLOW, GDB_SIGNAL_FPE},
+ {EXCEPTION_INT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE},
+ {EXCEPTION_INT_OVERFLOW, GDB_SIGNAL_FPE},
+ {EXCEPTION_PRIV_INSTRUCTION, GDB_SIGNAL_ILL},
+ {EXCEPTION_STACK_OVERFLOW, GDB_SIGNAL_SEGV},
+ {CONTROL_C_EXIT, GDB_SIGNAL_TERM}
+ };
+
+ for (const xlate_status &x : status_xlate_tbl)
+ if (x.status == status)
+ return x.sig;
+
+ return GDB_SIGNAL_UNKNOWN;
+}
+
+#endif /* __MINGW32__ */
+
#ifndef WIFEXITED
-#define WIFEXITED(w) (((w)&0377) == 0)
+# ifdef __MINGW32__
+# define WIFEXITED(w) (((w) & 0xC0000000) == 0)
+# else
+# define WIFEXITED(w) (((w)&0377) == 0)
+# endif
#endif
#ifndef WIFSIGNALED
-#define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
+# ifdef __MINGW32__
+# define WIFSIGNALED(w) (((w) & 0xC0000000) == 0xC0000000)
+# else
+# define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
+# endif
#endif
#ifndef WIFSTOPPED
#ifdef IBM6000
-/* Unfortunately, the above comment (about being compatible in all Unix
+/* Unfortunately, the above comment (about being compatible in all Unix
systems) is not quite correct for AIX, sigh. And AIX 3.2 can generate
status words like 0x57c (sigtrap received after load), and gdb would
choke on it. */
@@ -64,11 +130,19 @@
#endif
#ifndef WEXITSTATUS
-#define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */
+# ifdef __MINGW32__
+# define WEXITSTATUS(w) ((w) & ~0xC0000000)
+# else
+# define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */
+# endif
#endif
#ifndef WTERMSIG
-#define WTERMSIG(w) ((w) & 0177)
+# ifdef __MINGW32__
+# define WTERMSIG(w) windows_status_to_termsig (w)
+# else
+# define WTERMSIG(w) ((w) & 0177)
+# endif
#endif
#ifndef WSTOPSIG
--- gdb/windows-nat.c~0 2019-12-11 22:24:51.000000000 +0200
+++ gdb/windows-nat.c 2019-12-18 18:21:00.264558400 +0200
@@ -68,6 +68,7 @@
#include "inf-child.h"
#include "gdbsupport/gdb_tilde_expand.h"
#include "gdbsupport/pathstuff.h"
+#include "gdbsupport/gdb_wait.h"
#define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
#define DebugActiveProcessStop dyn_DebugActiveProcessStop
@@ -1620,8 +1621,17 @@ get_windows_debug_event (struct target_o
windows_delete_thread (ptid_t (current_event.dwProcessId, 0,
current_event.dwThreadId),
0, true /* main_thread_p */);
- ourstatus->kind = TARGET_WAITKIND_EXITED;
- ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
+ DWORD exit_status = current_event.u.ExitProcess.dwExitCode;
+ if (WIFEXITED (exit_status))
+ {
+ ourstatus->kind = TARGET_WAITKIND_EXITED;
+ ourstatus->value.integer = WEXITSTATUS (exit_status);
+ }
+ else
+ {
+ ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
+ ourstatus->value.sig = WTERMSIG (exit_status);
+ }
thread_id = current_event.dwThreadId;
}
break;
--- gdb/windows-tdep.c~0 2019-09-21 00:58:17.000000000 +0300
+++ gdb/windows-tdep.c 2019-12-18 17:49:52.360580700 +0200
@@ -35,6 +35,8 @@
#include "solib-target.h"
#include "gdbcore.h"
+#include <signal.h>
+
struct cmd_list_element *info_w32_cmdlist;
typedef struct thread_information_block_32
@@ -461,6 +463,29 @@ init_w32_command_list (void)
}
}
+static int
+windows_gdb_signal_to_target (struct gdbarch *gdbarch, enum gdb_signal signal)
+{
+ switch (signal)
+ {
+ case GDB_SIGNAL_0:
+ return 0;
+ case GDB_SIGNAL_INT:
+ return SIGINT;
+ case GDB_SIGNAL_ILL:
+ return SIGILL;
+ case GDB_SIGNAL_ABRT:
+ return SIGABRT;
+ case GDB_SIGNAL_FPE:
+ return SIGFPE;
+ case GDB_SIGNAL_SEGV:
+ return SIGSEGV;
+ case GDB_SIGNAL_TERM:
+ return SIGTERM;
+ }
+ return -1;
+}
+
/* To be called from the various GDB_OSABI_CYGWIN handlers for the
various Windows architectures and machine types. */
@@ -477,6 +502,8 @@ windows_init_abi (struct gdbarch_info in
set_gdbarch_iterate_over_objfiles_in_search_order
(gdbarch, windows_iterate_over_objfiles_in_search_order);
+ set_gdbarch_gdb_signal_to_target (gdbarch, windows_gdb_signal_to_target);
+
set_solib_ops (gdbarch, &solib_target_so_ops);
}
--- gdb/gdbserver/win32-low.c~0 2019-11-19 03:10:41.000000000 +0200
+++ gdb/gdbserver/win32-low.c 2019-12-18 17:51:32.098324200 +0200
@@ -34,6 +34,7 @@
#include <process.h>
#include "gdbsupport/gdb_tilde_expand.h"
#include "gdbsupport/common-inferior.h"
+#include "gdbsupport/gdb_wait.h"
#ifndef USE_WIN32API
#include <sys/cygwin.h>
@@ -1511,8 +1512,19 @@ get_child_debug_event (struct target_wai
"for pid=%u tid=%x\n",
(unsigned) current_event.dwProcessId,
(unsigned) current_event.dwThreadId));
- ourstatus->kind = TARGET_WAITKIND_EXITED;
- ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
+ {
+ DWORD exit_status = current_event.u.ExitProcess.dwExitCode;
+ if (WIFEXITED (exit_status))
+ {
+ ourstatus->kind = TARGET_WAITKIND_EXITED;
+ ourstatus->value.integer = WEXITSTATUS (exit_status);
+ }
+ else
+ {
+ ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
+ ourstatus->value.sig = WTERMSIG (exit_status);
+ }
+ }
child_continue (DBG_CONTINUE, -1);
CloseHandle (current_process_handle);
current_process_handle = NULL;
@@ -1607,6 +1619,7 @@ win32_wait (ptid_t ptid, struct target_w
win32_clear_inferiors ();
return ptid_t (current_event.dwProcessId);
case TARGET_WAITKIND_STOPPED:
+ case TARGET_WAITKIND_SIGNALLED:
case TARGET_WAITKIND_LOADED:
OUTMSG2 (("Child Stopped with signal = %d \n",
ourstatus->value.sig));
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-12-17 17:00 ` Eli Zaretskii
@ 2019-12-17 17:51 ` Pedro Alves
2019-12-18 17:08 ` Eli Zaretskii
0 siblings, 1 reply; 26+ messages in thread
From: Pedro Alves @ 2019-12-17 17:51 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: philippe.waroquiers, gdb-patches
On 12/17/19 4:59 PM, Eli Zaretskii wrote:
>> From: Pedro Alves <palves@redhat.com>
>> Date: Mon, 27 May 2019 18:33:11 +0100
>
> To recap, back in May Philippe added the 'pipe' command, and we had a
> brief discussion regarding the use of WIFEXITED, WIFSIGNALED, and
> other related macros from <sys/wait.h>, on MS-Windows. It was decided
> back then to leave for later the translation of exit codes returned by
> 'pipe' in MS-Windows build of GDB.
>
> I've now started to look at this issue, with the intent to provide ext
> status to signal conversion for the MS-Windows ports of GDB, and I
> have a few questions regarding the details.
>
> In that discussion, Pedro commented on Philippe's proposed patch
> (https://sourceware.org/ml/gdb-patches/2019-05/msg00131.html) which
> added the definitions for WIF* and WEXIT* macros to gdb_wait.h and
> their use in widnows-nat.c. The comments are in
> https://sourceware.org/ml/gdb-patches/2019-05/msg00590.html, and go
> like this:
>
>>> * common/gdb_wait.h (WIFEXITED, WIFSIGNALED, WEXITSTATUS,
>>> WTERMSIG): Define better versions for MinGW.
>>> * windows-nat.c (xlate): Uncomment the definition.
>>> (windows_status_to_termsig): New function.
>>
>> windows-nat.c looks like the wrong place to put this.
>>
>> windows-nat.c is only included in the build if building a native
>> debugger. But, you need this functionality on every Windows-hosted build
>> of GDB, even cross debuggers. So I think you're breaking the build on
>> the Windows-hosted, non-native-debugger case.
>>
>> E.g., --host=mingw --target=arm-none-eabi.
>>
>> The right place would be mingw-hdep.c.
>
> I'm okay with doing this in mingw-hdep.c, but I'm a bit confused by
> this comment. The encoding of the fatal exception in the exit status
> of a program is a feature of the native MS-Windows processes. Does
> "running cross-debugger" mentioned above allude to running an
> MS-Windows program?
The issue pointed out was that by putting the windows_status_to_termsig
function in windows-nat.c, and then calling it from gdb's common code
(cli/cli-cmds.c, via WTERMSIG) would result in a build/link failure when
you try to build a cross debugger hosted on mingw, because such a gdb
build does not include the native Windows target support, i.e., does not
build/link the windows-nat.o object. Putting said function in mingw-hdep.c
instead fixes that issue because that file is included as part of the build
in all kinds of mingw-hosted GDBs, either native or cross-debugger.
>> I admit to being a bit confused about why we want to do this
>> translation for this feature while we don't do it for the exit code
>> of inferiors running under gdb, for example. I mean, exit status
>> with 0xc0000000 set don't cause $_exitsignal to be set instead of
>> $_exitcode.
>
> Yes, we should do this for exit code of inferiors as well.
>
> Native MS-Windows debugging produces the TARGET_WAITKIND_* values in
> windows-nat.c, so I think the conversion we are talking about will
> have to be done there, perhaps _in_addition_to_ other places? IOW,
> the function that performs the conversion can be defined in
> mingw-hdep.c, but it will have to be called from windows-nat.c at
> least, right? And I'm uncertain what other places will have to call
> that conversion function for the use case of running a cross-debugger,
> can someone please help me understand that?
You'll also want to call it in gdbserver's win32-low.c file, so that
you get the translation too when debugging against gdbserver.
This actually suggests putting the new function in some new
shared file in gdb/gdbsupport/, since gdb/mingw-hdep.c is gdb-only.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-05-27 17:33 ` Pedro Alves
2019-05-27 18:38 ` Eli Zaretskii
@ 2019-12-17 17:00 ` Eli Zaretskii
2019-12-17 17:51 ` Pedro Alves
1 sibling, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2019-12-17 17:00 UTC (permalink / raw)
To: Pedro Alves; +Cc: philippe.waroquiers, gdb-patches
> From: Pedro Alves <palves@redhat.com>
> Date: Mon, 27 May 2019 18:33:11 +0100
To recap, back in May Philippe added the 'pipe' command, and we had a
brief discussion regarding the use of WIFEXITED, WIFSIGNALED, and
other related macros from <sys/wait.h>, on MS-Windows. It was decided
back then to leave for later the translation of exit codes returned by
'pipe' in MS-Windows build of GDB.
I've now started to look at this issue, with the intent to provide ext
status to signal conversion for the MS-Windows ports of GDB, and I
have a few questions regarding the details.
In that discussion, Pedro commented on Philippe's proposed patch
(https://sourceware.org/ml/gdb-patches/2019-05/msg00131.html) which
added the definitions for WIF* and WEXIT* macros to gdb_wait.h and
their use in widnows-nat.c. The comments are in
https://sourceware.org/ml/gdb-patches/2019-05/msg00590.html, and go
like this:
> > * common/gdb_wait.h (WIFEXITED, WIFSIGNALED, WEXITSTATUS,
> > WTERMSIG): Define better versions for MinGW.
> > * windows-nat.c (xlate): Uncomment the definition.
> > (windows_status_to_termsig): New function.
>
> windows-nat.c looks like the wrong place to put this.
>
> windows-nat.c is only included in the build if building a native
> debugger. But, you need this functionality on every Windows-hosted build
> of GDB, even cross debuggers. So I think you're breaking the build on
> the Windows-hosted, non-native-debugger case.
>
> E.g., --host=mingw --target=arm-none-eabi.
>
> The right place would be mingw-hdep.c.
I'm okay with doing this in mingw-hdep.c, but I'm a bit confused by
this comment. The encoding of the fatal exception in the exit status
of a program is a feature of the native MS-Windows processes. Does
"running cross-debugger" mentioned above allude to running an
MS-Windows program? If so, which GDB component (that is presumably
not windows-nat.c) is involved in running such cross-debugged programs
and for translating the debug status to the likes of
TARGET_WAITKIND_EXITED? And how does the 'pipe' command support these
cross-debugging use cases (as it uses the 'popen' C library function,
which AFAIU runs natively)?
> I admit to being a bit confused about why we want to do this
> translation for this feature while we don't do it for the exit code
> of inferiors running under gdb, for example. I mean, exit status
> with 0xc0000000 set don't cause $_exitsignal to be set instead of
> $_exitcode.
Yes, we should do this for exit code of inferiors as well.
Native MS-Windows debugging produces the TARGET_WAITKIND_* values in
windows-nat.c, so I think the conversion we are talking about will
have to be done there, perhaps _in_addition_to_ other places? IOW,
the function that performs the conversion can be defined in
mingw-hdep.c, but it will have to be called from windows-nat.c at
least, right? And I'm uncertain what other places will have to call
that conversion function for the use case of running a cross-debugger,
can someone please help me understand that?
TIA
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-05-29 12:38 ` Pedro Alves
2019-05-29 15:03 ` Eli Zaretskii
@ 2019-05-30 10:26 ` Philippe Waroquiers
1 sibling, 0 replies; 26+ messages in thread
From: Philippe Waroquiers @ 2019-05-30 10:26 UTC (permalink / raw)
To: Pedro Alves, Eli Zaretskii; +Cc: gdb-patches
On Wed, 2019-05-29 at 13:37 +0100, Pedro Alves wrote:
> On 5/27/19 7:37 PM, Eli Zaretskii wrote:
> > > From: Pedro Alves <palves@redhat.com>
> > > Date: Mon, 27 May 2019 18:33:11 +0100
> > >
> > > I admit to being a bit confused about why we want to do this
> > > translation for this feature while we don't do it for the exit code
> > > of inferiors running under gdb, for example. I mean, exit status
> > > with 0xc0000000 set don't cause $_exitsignal to be set instead of
> > > $_exitcode.
> >
> > We should probably do this everywhere where it matters whether the
> > inferior exited due to a fatal signal.
>
> Wouldn't it better to leave that translation out of this patch series,
> and do it everywhere it matters as a separate change, to avoid
> creating inconsistencies? Might be simpler for Philippe too, since
> the current patch isn't OK as is.
Yes, that looks a better approach, in particular because I do not have
a platform where I can compile such builds ...
Philippe
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-05-29 12:38 ` Pedro Alves
@ 2019-05-29 15:03 ` Eli Zaretskii
2019-05-30 10:26 ` Philippe Waroquiers
1 sibling, 0 replies; 26+ messages in thread
From: Eli Zaretskii @ 2019-05-29 15:03 UTC (permalink / raw)
To: Pedro Alves; +Cc: philippe.waroquiers, gdb-patches
> Cc: philippe.waroquiers@skynet.be, gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Wed, 29 May 2019 13:37:56 +0100
>
> > We should probably do this everywhere where it matters whether the
> > inferior exited due to a fatal signal.
>
> Wouldn't it better to leave that translation out of this patch series,
> and do it everywhere it matters as a separate change, to avoid
> creating inconsistencies? Might be simpler for Philippe too, since
> the current patch isn't OK as is.
It's up to you guys, I don't have a strong opinion about that.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-05-27 18:38 ` Eli Zaretskii
@ 2019-05-29 12:38 ` Pedro Alves
2019-05-29 15:03 ` Eli Zaretskii
2019-05-30 10:26 ` Philippe Waroquiers
0 siblings, 2 replies; 26+ messages in thread
From: Pedro Alves @ 2019-05-29 12:38 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: philippe.waroquiers, gdb-patches
On 5/27/19 7:37 PM, Eli Zaretskii wrote:
>> From: Pedro Alves <palves@redhat.com>
>> Date: Mon, 27 May 2019 18:33:11 +0100
>>
>> I admit to being a bit confused about why we want to do this
>> translation for this feature while we don't do it for the exit code
>> of inferiors running under gdb, for example. I mean, exit status
>> with 0xc0000000 set don't cause $_exitsignal to be set instead of
>> $_exitcode.
>
> We should probably do this everywhere where it matters whether the
> inferior exited due to a fatal signal.
Wouldn't it better to leave that translation out of this patch series,
and do it everywhere it matters as a separate change, to avoid
creating inconsistencies? Might be simpler for Philippe too, since
the current patch isn't OK as is.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-05-27 17:33 ` Pedro Alves
@ 2019-05-27 18:38 ` Eli Zaretskii
2019-05-29 12:38 ` Pedro Alves
2019-12-17 17:00 ` Eli Zaretskii
1 sibling, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2019-05-27 18:38 UTC (permalink / raw)
To: Pedro Alves; +Cc: philippe.waroquiers, gdb-patches
> From: Pedro Alves <palves@redhat.com>
> Date: Mon, 27 May 2019 18:33:11 +0100
>
> I admit to being a bit confused about why we want to do this
> translation for this feature while we don't do it for the exit code
> of inferiors running under gdb, for example. I mean, exit status
> with 0xc0000000 set don't cause $_exitsignal to be set instead of
> $_exitcode.
We should probably do this everywhere where it matters whether the
inferior exited due to a fatal signal.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [RFAv3 2/6] Improve process exit status macros on MinGW
2019-05-04 16:18 ` [RFAv3 2/6] Improve process exit status macros on MinGW Philippe Waroquiers
@ 2019-05-27 17:33 ` Pedro Alves
2019-05-27 18:38 ` Eli Zaretskii
2019-12-17 17:00 ` Eli Zaretskii
0 siblings, 2 replies; 26+ messages in thread
From: Pedro Alves @ 2019-05-27 17:33 UTC (permalink / raw)
To: Philippe Waroquiers, gdb-patches
On 5/4/19 5:17 PM, Philippe Waroquiers wrote:
> gdb/ChangeLog
> 2019-05-04 Eli Zaretskii <eliz@gnu.org>
> Philippe Waroquiers <philippe.waroquiers@skynet.be>
>
> * common/gdb_wait.h (WIFEXITED, WIFSIGNALED, WEXITSTATUS,
> WTERMSIG): Define better versions for MinGW.
> * windows-nat.c (xlate): Uncomment the definition.
> (windows_status_to_termsig): New function.
windows-nat.c looks like the wrong place to put this.
windows-nat.c is only included in the build if building a native
debugger. But, you need this functionality on every Windows-hosted build
of GDB, even cross debuggers. So I think you're breaking the build on
the Windows-hosted, non-native-debugger case.
E.g., --host=mingw --target=arm-none-eabi.
The right place would be mingw-hdep.c.
I admit to being a bit confused about why we want to do this
translation for this feature while we don't do it for the exit code
of inferiors running under gdb, for example. I mean, exit status
with 0xc0000000 set don't cause $_exitsignal to be set instead of
$_exitcode.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 26+ messages in thread
* [RFAv3 2/6] Improve process exit status macros on MinGW
2019-05-04 16:18 [RFAv3 0/6] Implement | (pipe) command Philippe Waroquiers
@ 2019-05-04 16:18 ` Philippe Waroquiers
2019-05-27 17:33 ` Pedro Alves
0 siblings, 1 reply; 26+ messages in thread
From: Philippe Waroquiers @ 2019-05-04 16:18 UTC (permalink / raw)
To: gdb-patches; +Cc: Philippe Waroquiers
gdb/ChangeLog
2019-05-04 Eli Zaretskii <eliz@gnu.org>
Philippe Waroquiers <philippe.waroquiers@skynet.be>
* common/gdb_wait.h (WIFEXITED, WIFSIGNALED, WEXITSTATUS,
WTERMSIG): Define better versions for MinGW.
* windows-nat.c (xlate): Uncomment the definition.
(windows_status_to_termsig): New function.
---
gdb/common/gdb_wait.h | 27 +++++++++++++++++++++++++++
gdb/windows-nat.c | 18 ++++++++++++++----
2 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/gdb/common/gdb_wait.h b/gdb/common/gdb_wait.h
index b3b752cf3a..ca95240009 100644
--- a/gdb/common/gdb_wait.h
+++ b/gdb/common/gdb_wait.h
@@ -40,13 +40,31 @@
NOTE exception for GNU/Linux below). We also fail to declare
wait() and waitpid(). */
+/* For MINGW, the underlying idea is that when a Windows program is terminated
+ by a fatal exception, its exit code is the value of that exception, as
+ defined by the various STATUS_* symbols in the Windows API headers.
+
+ The below is not perfect, because a program could legitimately exit normally
+ with a status whose value happens to have the high bits set, but that's
+ extremely rare, to say the least, and it is deemed such a negligibly small
+ probability of false positives is justified by the utility of reporting the
+ terminating signal in the "normal" cases. */
+
#ifndef WIFEXITED
+#if defined (__MINGW32__)
+#define WIFEXITED(stat_val) (((stat_val) & 0xC0000000) == 0)
+#else
#define WIFEXITED(w) (((w)&0377) == 0)
#endif
+#endif
#ifndef WIFSIGNALED
+#if defined (__MINGW32__)
+#define WIFSIGNALED(stat_val) (((stat_val) & 0xC0000000) == 0xC0000000)
+#else
#define WIFSIGNALED(w) (((w)&0377) != 0177 && ((w)&~0377) == 0)
#endif
+#endif
#ifndef WIFSTOPPED
#ifdef IBM6000
@@ -64,12 +82,21 @@
#endif
#ifndef WEXITSTATUS
+#if defined (__MINGW32__)
+#define WEXITSTATUS(stat_val) ((stat_val) & 255)
+#else
#define WEXITSTATUS(w) (((w) >> 8) & 0377) /* same as WRETCODE */
#endif
+#endif
#ifndef WTERMSIG
+#if defined (__MINGW32__)
+extern enum gdb_signal windows_status_to_termsig (int stat_val);
+#define WTERMSIG(stat_val) windows_status_to_termsig (stat_val)
+#else
#define WTERMSIG(w) ((w) & 0177)
#endif
+#endif
#ifndef WSTOPSIG
#define WSTOPSIG WEXITSTATUS
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index ae4e3d55b3..c90caeda6a 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -280,9 +280,9 @@ static const int *mappings;
a segment register or not. */
static segment_register_p_ftype *segment_register_p;
-/* See windows_nat_target::resume to understand why this is commented
- out. */
-#if 0
+/* See windows_nat_target::resume to understand why xlate is not used
+ to translate a signal into an exception. */
+
/* This vector maps the target's idea of an exception (extracted
from the DEBUG_EVENT structure) to GDB's idea. */
@@ -302,7 +302,17 @@ static const struct xlate_exception xlate[] =
{STATUS_FLOAT_DIVIDE_BY_ZERO, GDB_SIGNAL_FPE}
};
-#endif /* 0 */
+/* Translate a windows exception inside STAT_VAL into a gdb_signal.
+ This should only be called if WIFSIGNALED (stat_val). */
+
+enum gdb_signal
+windows_status_to_termsig (int stat_val)
+{
+ for (const xlate_exception &x : xlate)
+ if (x.them == (stat_val & ~0xC0000000))
+ return x.us;
+ return GDB_SIGNAL_UNKNOWN;
+}
struct windows_nat_target final : public x86_nat_target<inf_child_target>
{
--
2.20.1
^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2020-01-06 19:55 UTC | newest]
Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <271718487.11947642.1578332826544.ref@mail.yahoo.com>
2020-01-06 17:47 ` [RFAv3 2/6] Improve process exit status macros on MinGW Hannes Domani via gdb-patches
2020-01-06 18:23 ` Eli Zaretskii
2019-05-04 16:18 [RFAv3 0/6] Implement | (pipe) command Philippe Waroquiers
2019-05-04 16:18 ` [RFAv3 2/6] Improve process exit status macros on MinGW Philippe Waroquiers
2019-05-27 17:33 ` Pedro Alves
2019-05-27 18:38 ` Eli Zaretskii
2019-05-29 12:38 ` Pedro Alves
2019-05-29 15:03 ` Eli Zaretskii
2019-05-30 10:26 ` Philippe Waroquiers
2019-12-17 17:00 ` Eli Zaretskii
2019-12-17 17:51 ` Pedro Alves
2019-12-18 17:08 ` Eli Zaretskii
2019-12-18 17:42 ` Pedro Alves
2019-12-18 18:33 ` Eli Zaretskii
2019-12-25 15:57 ` Eli Zaretskii
2020-01-03 19:59 ` Pedro Alves
2020-01-03 20:08 ` Pedro Alves
2020-01-03 20:34 ` Eli Zaretskii
2020-01-06 11:57 ` Pedro Alves
2020-01-06 16:17 ` Eli Zaretskii
2020-01-06 18:51 ` Pedro Alves
2020-01-06 19:26 ` Eli Zaretskii
2020-01-06 18:59 ` Hannes Domani via gdb-patches
2020-01-06 19:34 ` Eli Zaretskii
2020-01-06 19:38 ` Hannes Domani via gdb-patches
2020-01-06 19:55 ` Eli Zaretskii
2020-01-03 17:04 ` Pedro Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox