From: Sergio Durigan Junior <sergiodj@redhat.com>
To: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
Cc: "'GDB Patches'" <gdb-patches@sourceware.org>
Subject: Re: [RFC/PATCH] New convenience variable $_exitsignal
Date: Mon, 17 Jun 2013 17:55:00 -0000 [thread overview]
Message-ID: <m3zjuotykn.fsf@redhat.com> (raw)
In-Reply-To: <00db01ce6b24$0b716aa0$22543fe0$@muller@ics-cnrs.unistra.fr> (Pierre Muller's message of "Mon, 17 Jun 2013 08:29:37 +0200")
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
next prev parent reply other threads:[~2013-06-17 17:52 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-16 6:30 Sergio Durigan Junior
2013-06-16 16:22 ` Doug Evans
2013-06-17 3:33 ` Eli Zaretskii
2013-06-17 7:32 ` Pierre Muller
2013-06-17 17:55 ` Sergio Durigan Junior [this message]
2013-06-19 5:26 ` Sergio Durigan Junior
2013-09-16 18:04 ` Pedro Alves
2013-09-17 0:11 ` Sergio Durigan Junior
2013-09-17 16:19 ` Pedro Alves
2013-09-17 18:39 ` Tom Tromey
2013-09-17 18:53 ` Philippe Waroquiers
2013-09-17 18:59 ` Sergio Durigan Junior
2013-09-17 18:59 ` Tom Tromey
2013-09-17 19:08 ` Pedro Alves
2013-09-17 19:02 ` Pedro Alves
2013-09-17 19:09 ` Tom Tromey
2013-07-18 16:48 ` Tom Tromey
2013-06-17 17:28 ` Pedro Alves
2013-06-17 17:31 ` Pedro Alves
2013-06-17 17:41 ` Sergio Durigan Junior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3zjuotykn.fsf@redhat.com \
--to=sergiodj@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=pierre.muller@ics-cnrs.unistra.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox