Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
To: "'Sergio Durigan Junior'" <sergiodj@redhat.com>
Cc: "'GDB Patches'" <gdb-patches@sourceware.org>
Subject: RE: [RFC/PATCH] New convenience variable $_exitsignal
Date: Mon, 17 Jun 2013 07:32:00 -0000	[thread overview]
Message-ID: <00db01ce6b24$0b716aa0$22543fe0$@muller@ics-cnrs.unistra.fr> (raw)
In-Reply-To: <m3mwqqvagk.fsf@redhat.com>

  Hi Sergio,

  Is there a reason why you don't handle
corelow.c anymore in your new patch?

  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.

  Sorry to bother you again...

Pierre Muller
 

> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Sergio Durigan Junior
> Envoyé : dimanche 16 juin 2013 08:25
> À : GDB Patches
> Cc : Pedro Alves
> Objet : [RFC/PATCH] New convenience variable $_exitsignal
> 
> This patch was proposed by Pedro at:
> 
> <http://sourceware.org/ml/gdb-patches/2013-06/msg00337.html>
> 
> It adds a new convenience variable called "$_exitsignal", which will
> hold the signal number when the inferior terminates due to the uncaught
> signal.
> 
> I've made modifications on infrun.c:handle_inferior_event such that
> $_exitcode gets cleared when the inferior signalled, and vice-versa.
> This assumption was made because IMO the variables are mutually
> exclusive, i.e., when the inferior terminates because of an uncaught
> signal it is not possible for it to return.  Anyway, Pedro's explanation
> seems to follow the same logic.
> 
> The patch also adds a NEWS entry, documentation bits, and a testcase.
> 
> OK to apply?
> 
> --
> Sergio
> 
> gdb/ChangeLog:
> 2013-06-16  Sergio Durigan Junior  <sergiodj@redhat.com>
> 
> 	* NEWS: Mention new convenience variable "$_exitsignal".
> 	* infrun.c (handle_inferior_event): Set internal variable
> 	"$_exitsignal" for TARGET_WAITKIND_SIGNALLED and clear
> 	"$_exitcode", vice-versa for TARGET_WAITKIND_STOPPED.
> 
> gdb/testsuite/ChangeLog:
> 2013-06-16  Sergio Durigan Junior  <sergiodj@redhat.com>
> 
> 	* gdb.base/exitsignal.exp: New file.
> 	* gdb.base/segv.c: Likewise.
> 
> gdb/doc/ChangeLog:
> 2013-06-16  Sergio Durigan Junior  <sergiodj@redhat.com>
> 
> 	* gdb.texinfo (Convenience Variables): Document "$_exitsignal".
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index eea9917..e9e81b3 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -69,6 +69,10 @@ show range-stepping
>  * The exception-related catchpoints, like "catch throw", now accept a
>    regular expression which can be used to filter exceptions by type.
> 
> +* The new convenience variable $_exitsignal is automatically set to
> +  the signal number when the program being debugged dies due to an
> +  uncaught signal.
> +
>  * MI changes
> 
>    ** The -trace-save MI command can optionally save trace buffer in
Common
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index e6ec4ff..2025f15 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -9735,7 +9735,12 @@ to match the format in which the data was printed.
>  @item $_exitcode
>  @vindex $_exitcode@r{, convenience variable}
>  The variable @code{$_exitcode} is automatically set to the exit code when
> -the program being debugged terminates.
> +the program being debugged terminates normally.
> +
> +@item $_exitsignal
> +@vindex $_exitsignal@r{, convenience variable}
> +The variable @code{$_exitsignal} is automatically set to the signal
> +number when the program being debugged dies due to an uncaught signal.
> 
>  @item $_exception
>  The variable @code{$_exception} is set to the exception object being
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index 51a032b..f4ed1ac 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -3455,6 +3455,12 @@ handle_inferior_event (struct
execution_control_state
> *ecs)
>  	  set_internalvar_integer (lookup_internalvar ("_exitcode"),
>  				   (LONGEST) ecs->ws.value.integer);
> 
> +	  /* Clear the internal variable, since if we are here chances
> +	     are the inferior has not been terminated by a signal.
> +	     And even if it has, then GDB will get to
> +	     TARGET_WAITKIND_SIGNALLED in time...  */
> +	  clear_internalvar (lookup_internalvar ("_exitsignal"));
> +
>  	  /* Also record this in the inferior itself.  */
>  	  current_inferior ()->has_exit_code = 1;
>  	  current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer;
> @@ -3462,7 +3468,17 @@ handle_inferior_event (struct
execution_control_state
> *ecs)
>  	  print_exited_reason (ecs->ws.value.integer);
>  	}
>        else
> -	print_signal_exited_reason (ecs->ws.value.sig);
> +	{
> +	  print_signal_exited_reason (ecs->ws.value.sig);
> +	  /* Set the value of the internal variable $_exitsignal,
> +	     which holds the signal uncaught by the inferior.  */
> +	  set_internalvar_integer (lookup_internalvar ("_exitsignal"),
> +				   (LONGEST) ecs->ws.value.sig);
> +
> +	  /* Clear the $_exitcode internal variable, because if the
> +	     inferior signalled then its return code does not exist.  */
> +	  clear_internalvar (lookup_internalvar ("_exitcode"));
> +	}
> 
>        gdb_flush (gdb_stdout);
>        target_mourn_inferior ();
> diff --git a/gdb/testsuite/gdb.base/exitsignal.exp
> b/gdb/testsuite/gdb.base/exitsignal.exp
> new file mode 100644
> index 0000000..aa041d5
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/exitsignal.exp
> @@ -0,0 +1,49 @@
> +# Copyright 2013 Free Software Foundation, Inc.
> +
> +# 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/>.
> +
> +standard_testfile segv.c
> +
> +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
> +    return -1
> +}
> +
> +# Run to main
> +if { ![runto_main] } {
> +    return -1
> +}
> +
> +# Print $_exitsignal.  It should be void now, because nothing
> +# happened.
> +gdb_test "print \$_exitsignal" " = void" \
> +    "\$_exitsignal is void before running"
> +
> +# Trigger SIGSEGV.
> +gdb_test "continue" "Program received signal SIGSEGV.*" "trigger SIGSEGV"
> +
> +# Continue until the end.
> +gdb_test "continue" "Program terminated with signal SIGSEGV.*" \
> +    "program terminated with SIGSEGV"
> +
> +# Now, print $_exitsignal again.  It should be 11 (SIGSEGV).
> +gdb_test "print \$_exitsignal" " = 11"
> +
> +# Re-run to main, i.e., restart the executable.
> +if { ![rerun_to_main] } {
> +    return -1
> +}
> +
> +# Print the $_exitsignal again.  Even in this normal scenario, it
> +# should still contain the signal triggered in the other run.
> +gdb_test "print \$_exitsignal" " = 11"
> diff --git a/gdb/testsuite/gdb.base/segv.c b/gdb/testsuite/gdb.base/segv.c
> new file mode 100644
> index 0000000..dddbd4c
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/segv.c
> @@ -0,0 +1,31 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2013 Free Software Foundation, Inc.
> +
> +   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/>.
> +
> +*/
> +
> +/* This test can be used just to generate a SIGSEGV.  */
> +
> +#include <stdio.h>
> +
> +int
> +main (int argc, char *argv[])
> +{
> +  char *p = NULL;
> +
> +  /* Generating a SIGSEGV.  */
> +  *p = 1;
> +}


  parent reply	other threads:[~2013-06-17  6:29 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 [this message]
2013-06-17 17:55   ` Sergio Durigan Junior
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             ` Tom Tromey
2013-09-17 18:59             ` Sergio Durigan Junior
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='00db01ce6b24$0b716aa0$22543fe0$@muller@ics-cnrs.unistra.fr' \
    --to=pierre.muller@ics-cnrs.unistra.fr \
    --cc=gdb-patches@sourceware.org \
    --cc=sergiodj@redhat.com \
    /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