This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC/PATCH] New convenience variable $_exitsignal
- From: Sergio Durigan Junior <sergiodj at redhat dot com>
- To: "Pierre Muller" <pierre dot muller at ics-cnrs dot unistra dot fr>
- Cc: "'GDB Patches'" <gdb-patches at sourceware dot org>
- Date: Mon, 17 Jun 2013 14:51:52 -0300
- Subject: Re: [RFC/PATCH] New convenience variable $_exitsignal
- References: <m3mwqqvagk dot fsf at redhat dot com> <00db01ce6b24$0b716aa0$22543fe0$ at muller@ics-cnrs.unistra.fr>
On Monday, June 17 2013, Pierre Muller wrote:
> Hi Sergio,
>
> Is there a reason why you don't handle
> corelow.c anymore in your new patch?
Hi Pierre,
Yes, corelow.c is not important to this patch because (as Pedro
explained on
<http://sourceware.org/ml/gdb-patches/2013-06/msg00337.html>)
$_exitsignal should not be set for corefiles, because the inferior has
not exited.
corelow.c will be touched in my next patch, which will add $_signo (but
with the modifications proposed by Pedro).
> Also, I seem to vaguely remember that on
> linux, the signal that generated the program exit is
> finally embedded in the status...
> See WIFEXITED and WIFSIGNALED macros in linux-nat.c
>
> For instance if I interrupt as (launched without argumrents)
> with Ctrl-C,
> The exit code (at least in bash shell) is 130.
>
> Is this a shell feature? If not, I am not sure setting $_exitcode
> variable to zero is the right thing to do.
To the extent of my knowledge, this is a shell feature. It sets $? (the
variable which contains the exit code of the program) to 128 + signal
number. However, if you use this simple C program (borrowed from
waitpid's manpage, and modified to print the exit code when the child is
killed by a signal):
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
pid_t cpid, w;
int status;
cpid = fork();
if (cpid == -1) {
perror("fork");
exit(EXIT_FAILURE);
}
if (cpid == 0) { /* Code executed by child */
printf("Child PID is %ld\n", (long) getpid());
if (argc == 1)
pause(); /* Wait for signals */
_exit(atoi(argv[1]));
} else { /* Code executed by parent */
do {
w = waitpid(cpid, &status, WUNTRACED | WCONTINUED);
if (w == -1) {
perror("waitpid");
exit(EXIT_FAILURE);
}
if (WIFEXITED(status)) {
printf("exited, status=%d\n", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("killed by signal %d, exit=%d\n", WTERMSIG(status),
WEXITSTATUS(status));
} else if (WIFSTOPPED(status)) {
printf("stopped by signal %d\n", WSTOPSIG(status));
} else if (WIFCONTINUED(status)) {
printf("continued\n");
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
exit(EXIT_SUCCESS);
}
}
And run it:
$ ./a.out
Child PID is 2448
Then, on another terminal:
$ kill -USR1 2448
You'll see:
killed by signal 10, exit=0
Thus, it makes sense to unset $_exitcode (note that I am not setting it
to zero, as you said).
> Sorry to bother you again...
Hey, no problem, your question was actually very pertinent.
Thanks,
--
Sergio