aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
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/testsuite
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/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog8
-rw-r--r--gdb/testsuite/gdb.base/corefile.exp10
-rw-r--r--gdb/testsuite/gdb.base/exitsignal.exp106
-rw-r--r--gdb/testsuite/gdb.base/normal.c24
-rw-r--r--gdb/testsuite/gdb.base/segv.c29
5 files changed, 177 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 4f07777..3a5a4e0 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+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.
+
2013-10-04 Joel Brobecker <brobecker@adacore.com>
* gdb.mi/mi-start.c, gdb.mi/mi-start.exp: New files.
diff --git a/gdb/testsuite/gdb.base/corefile.exp b/gdb/testsuite/gdb.base/corefile.exp
index 04ae969..72c7a4a 100644
--- a/gdb/testsuite/gdb.base/corefile.exp
+++ b/gdb/testsuite/gdb.base/corefile.exp
@@ -142,6 +142,16 @@ gdb_test "print coremaker_ro" "\\\$$decimal = 201"
gdb_test "print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}"
+# Test the presence and the correct values of $_exitsignal and
+# $_exitcode variables. The corefile is generated with a SIGABRT,
+# which is "6" in the Linux kernel.
+
+gdb_test "print \$_exitsignal" " = 6" \
+ "\$_exitsignal prints SIGABRT (6)"
+
+gdb_test "print \$_exitcode" " = void" \
+ "\$_exitcode is void"
+
# Somehow we better test the ability to read the registers out of the core
# file correctly. I don't think the other tests do this.
diff --git a/gdb/testsuite/gdb.base/exitsignal.exp b/gdb/testsuite/gdb.base/exitsignal.exp
new file mode 100644
index 0000000..8687812
--- /dev/null
+++ b/gdb/testsuite/gdb.base/exitsignal.exp
@@ -0,0 +1,106 @@
+# 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 checks both $_exitcode and $_exitsignal variables. The
+# purpose of this checking is to ensure that the variables are
+# mutually exclusive, i.e., that when $_exitsignal is set, $_exitcode
+# is not, and vice-versa. This mutual exclusion happens because if an
+# inferior exited (either successfuly or not), it certainly was not
+# killed by a signal. However, if it was killed by an uncaught
+# signal, then there is no way for it to have exited.
+
+if { [target_info exists gdb,nosignals] } {
+ verbose "Skipping exitsignal.exp because of nosignals."
+ continue
+}
+
+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"
+
+# Just to guarantee, making sure that $_exitcode is also void.
+gdb_test "print \$_exitcode" " = void" \
+ "\$_exitcode 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" \
+ "\$_exitsignal is 11 (SIGSEGV) after SIGSEGV."
+
+# And $_exitcode should still be void, since the inferior died because
+# of a signal, and did not return.
+gdb_test "print \$_exitcode" " = void" \
+ "\$_exitcode is still void after SIGSEGV"
+
+# Re-run to main, i.e., restart the executable.
+rerun_to_main
+
+# 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" \
+ "\$_exitsignal is 11 (SIGSEGV) after restarting the inferior"
+
+# And, again, print $_exitcode.
+gdb_test "print \$_exitcode" " = void" \
+ "\$_exitcode is still void after restarting the inferior"
+
+# Now we test the behaviour of $_exit{code,signal} during a normal
+# inferior execution.
+standard_testfile normal.c
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
+ return -1
+}
+
+# Checking $_exitsignal and $_exitcode, both should be void before the
+# inferior is executed.
+gdb_test "print \$_exitsignal" " = void" \
+ "\$_exitsignal is void before normal inferior is executed"
+gdb_test "print \$_exitcode" " = void" \
+ "\$_exitcode is void before normal inferior is executed"
+
+# Run the inferior until the end.
+if { ![runto_main] } {
+ return -1
+}
+
+gdb_continue_to_end
+
+# Checking $_exitcode. It should be 0.
+gdb_test "print \$_exitcode" " = 0" \
+ "\$_exitcode is zero after normal inferior is executed"
+
+# Checking $_exitsignal. It should still be void, since the inferior
+# has not received any signal.
+gdb_test "print \$_exitsignal" " = void" \
+ "\$_exitsignal is still void after normal inferior is executed"
diff --git a/gdb/testsuite/gdb.base/normal.c b/gdb/testsuite/gdb.base/normal.c
new file mode 100644
index 0000000..4aa7c45
--- /dev/null
+++ b/gdb/testsuite/gdb.base/normal.c
@@ -0,0 +1,24 @@
+/* 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 is just a normal return 0. */
+
+int
+main (int argc, char *argv[])
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/segv.c b/gdb/testsuite/gdb.base/segv.c
new file mode 100644
index 0000000..8991f4d
--- /dev/null
+++ b/gdb/testsuite/gdb.base/segv.c
@@ -0,0 +1,29 @@
+/* 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 <signal.h>
+
+int
+main (int argc, char *argv[])
+{
+ /* Generating a SIGSEGV. */
+ raise (SIGSEGV);
+
+ return 0;
+}