From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23307 invoked by alias); 17 Jun 2013 06:29:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 23298 invoked by uid 89); 17 Jun 2013 06:29:47 -0000 X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,MSGID_MULTIPLE_AT autolearn=no version=3.3.1 Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.201.42) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 17 Jun 2013 06:29:46 +0000 Received: from md13.u-strasbg.fr (md13.u-strasbg.fr [130.79.200.248]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id r5H6TdP1001395 ; Mon, 17 Jun 2013 08:29:39 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from ms17.u-strasbg.fr (ms17.u-strasbg.fr [130.79.204.117]) by md13.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id r5H6TdK4029001 ; Mon, 17 Jun 2013 08:29:39 +0200 (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from E6510Muller (lec67-4-82-230-53-140.fbx.proxad.net [82.230.53.140]) (Authenticated sender: mullerp) by ms17.u-strasbg.fr (Postfix) with ESMTPSA id A38A71FD9A; Mon, 17 Jun 2013 08:29:37 +0200 (CEST) From: "Pierre Muller" To: "'Sergio Durigan Junior'" Cc: "'GDB Patches'" References: In-Reply-To: Subject: RE: [RFC/PATCH] New convenience variable $_exitsignal Date: Mon, 17 Jun 2013 07:32:00 -0000 Message-ID: <00db01ce6b24$0b716aa0$22543fe0$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-SW-Source: 2013-06/txt/msg00366.txt.bz2 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=20 variable to zero is the right thing to do. Sorry to bother you again... Pierre Muller =20 > -----Message d'origine----- > De=A0: gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Sergio Durigan Junior > Envoy=E9=A0: dimanche 16 juin 2013 08:25 > =C0=A0: GDB Patches > Cc=A0: Pedro Alves > Objet=A0: [RFC/PATCH] New convenience variable $_exitsignal >=20 > This patch was proposed by Pedro at: >=20 > >=20 > It adds a new convenience variable called "$_exitsignal", which will > hold the signal number when the inferior terminates due to the uncaught > signal. >=20 > 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. >=20 > The patch also adds a NEWS entry, documentation bits, and a testcase. >=20 > OK to apply? >=20 > -- > Sergio >=20 > gdb/ChangeLog: > 2013-06-16 Sergio Durigan Junior >=20 > * 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. >=20 > gdb/testsuite/ChangeLog: > 2013-06-16 Sergio Durigan Junior >=20 > * gdb.base/exitsignal.exp: New file. > * gdb.base/segv.c: Likewise. >=20 > gdb/doc/ChangeLog: > 2013-06-16 Sergio Durigan Junior >=20 > * gdb.texinfo (Convenience Variables): Document "$_exitsignal". >=20 > 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. >=20 > +* 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 >=20 > ** 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. >=20 > @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); >=20 > + /* 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 =3D 1; > current_inferior ()->exit_code =3D (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")); > + } >=20 > 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 . > + > +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" " =3D 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" " =3D 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" " =3D 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 . > + > +*/ > + > +/* This test can be used just to generate a SIGSEGV. */ > + > +#include > + > +int > +main (int argc, char *argv[]) > +{ > + char *p =3D NULL; > + > + /* Generating a SIGSEGV. */ > + *p =3D 1; > +}