aboutsummaryrefslogtreecommitdiff
path: root/gdb/doc
diff options
context:
space:
mode:
authorSergio Durigan Junior <sergiodj@redhat.com>2013-10-07 05:34:11 +0000
committerSergio Durigan Junior <sergiodj@redhat.com>2013-10-07 05:34:11 +0000
commit0c5571793a8e3dbd0f99b8e4759bd201f5fe75b7 (patch)
tree38bb49888fe6cc02df72c1486b872b397d4ff21e /gdb/doc
parentf872dc3d6e46cf29f9e89392f3c059ce0f6a58b3 (diff)
downloadgdb-0c5571793a8e3dbd0f99b8e4759bd201f5fe75b7.zip
gdb-0c5571793a8e3dbd0f99b8e4759bd201f5fe75b7.tar.gz
gdb-0c5571793a8e3dbd0f99b8e4759bd201f5fe75b7.tar.bz2
This patch 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 the variables are mutually exclusive, i.e., when the inferior terminates because of an uncaught signal it is not possible for it to return. I have also made modifications such that when a corefile is loaded, $_exitsignal gets set to the uncaught signal that "killed" the inferior, and $_exitcode is cleared. The patch also adds a NEWS entry, documentation bits, and a testcase. The documentation entry explains how to use $_exitsignal and $_exitcode in a GDB script, by making use of the new $_isvoid convenience function. gdb/ 2013-10-06 Sergio Durigan Junior <sergiodj@redhat.com> * NEWS: Mention new convenience variable $_exitsignal. * corelow.c (core_open): Reset exit convenience variables. Set $_exitsignal to the uncaught signal which generated the corefile. * infrun.c (handle_inferior_event): Reset exit convenience variables. Set $_exitsignal for TARGET_WAITKIND_SIGNALLED. (clear_exit_convenience_vars): New function. * inferior.h (clear_exit_convenience_vars): New prototype. gdb/testsuite/ 2013-10-06 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.base/corefile.exp: Test whether $_exitsignal is set and $_exitcode is void when opening a corefile. * gdb.base/exitsignal.exp: New file. * gdb.base/segv.c: Likewise. * gdb.base/normal.c: Likewise. gdb/doc/ 2013-10-06 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.texinfo (Convenience Variables): Document $_exitsignal. Update entry for $_exitcode.
Diffstat (limited to 'gdb/doc')
-rw-r--r--gdb/doc/ChangeLog5
-rw-r--r--gdb/doc/gdb.texinfo60
2 files changed, 63 insertions, 2 deletions
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 04e291b..89254a9 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2013-10-06 Sergio Durigan Junior <sergiodj@redhat.com>
+
+ * gdb.texinfo (Convenience Variables): Document $_exitsignal.
+ Update entry for $_exitcode.
+
2013-10-04 Joel Brobecker <brobecker@adacore.com>
* gdb.texinfo (GDB/MI Program Execution): Document "-exec-run"'s
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index a68556b..7ec91d8 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -9751,8 +9751,64 @@ 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.
+When the program being debugged terminates normally, @value{GDBN}
+automatically sets this variable to the exit code of the program, and
+resets @code{$_exitsignal} to @code{void}.
+
+@item $_exitsignal
+@vindex $_exitsignal@r{, convenience variable}
+When the program being debugged dies due to an uncaught signal,
+@value{GDBN} automatically sets this variable to that signal's number,
+and resets @code{$_exitcode} to @code{void}.
+
+To distinguish between whether the program being debugged has exited
+(i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
+@code{$_exitsignal} is not @code{void}), the convenience function
+@code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
+Functions}). For example, considering the following source code:
+
+@smallexample
+#include <signal.h>
+
+int
+main (int argc, char *argv[])
+@{
+ raise (SIGALRM);
+ return 0;
+@}
+@end smallexample
+
+A valid way of telling whether the program being debugged has exited
+or signalled would be:
+
+@smallexample
+(@value{GDBP}) define has_exited_or_signalled
+Type commands for definition of ``has_exited_or_signalled''.
+End with a line saying just ``end''.
+>if $_isvoid ($_exitsignal)
+ >echo The program has exited\n
+ >else
+ >echo The program has signalled\n
+ >end
+>end
+(@value{GDBP}) run
+Starting program:
+
+Program terminated with signal SIGALRM, Alarm clock.
+The program no longer exists.
+(@value{GDBP}) has_exited_or_signalled
+The program has signalled
+@end smallexample
+
+As can be seen, @value{GDBN} correctly informs that the program being
+debugged has signalled, since it calls @code{raise} and raises a
+@code{SIGALRM} signal. If the program being debugged had not called
+@code{raise}, then @value{GDBN} would report a normal exit:
+
+@smallexample
+(@value{GDBP}) has_exited_or_signalled
+The program has exited
+@end smallexample
@item $_exception
The variable @code{$_exception} is set to the exception object being