This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA 2/4] Implement | (pipe) command.
> From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
> Cc: gdb-patches@sourceware.org
> Date: Sun, 21 Apr 2019 11:40:22 +0200
>
> > > + if (shell_command_status > 0)
> > > + {
> > > + if (WIFEXITED (shell_command_status))
> > > + warning (_("shell command \"%s\" exit status %d"), shell_command,
> > > + WEXITSTATUS (shell_command_status));
> > > + else if (WIFSIGNALED (shell_command_status))
> > > + warning (_("shell command \"%s\" exit with signal %d"), shell_command,
> > > + WTERMSIG (shell_command_status));
> >
> > These macros will need to be ported to MinGW, since the current
> > definitions in gdb_wait.h are for Posix systems (and never used on
> > anything other than that). Gnulib has replacements, but they are less
> > functional on Windows than I'd like them to be, in particular when the
> > shell program exited due to a signal. I can provide better
> > replacements if you want.
> It would be nice to have better replacement for Windows,
> as I do not have the knowledge and needed setup to test
> for this platform.
Here's my proposal:
#define WIFEXITED(stat_val) (((stat_val) & 0xC0000000) == 0)
#define WIFSIGNALED(stat_val) (((stat_val) & 0xC0000000) == 0xC0000000)
#define WEXITSTATUS(stat_val) ((stat_val) & 255)
#define WTERMSIG(stat_val) windows_status_to_termsig (stat_val)
where windows_status_to_termsig should use the xlate[] array defined
in windows-nat.c, like the (ifdef'ed away) code in
windows_nat_target::resume does.
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 above 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 I think such a
negligibly small probability of false positives is justified by the
utility of reporting the terminating signal in the "normal" cases.