aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2013-01-16 17:31:40 +0000
committerTom Tromey <tromey@redhat.com>2013-01-16 17:31:40 +0000
commitab04a2af2bacfc1062c907630bee6e345dbd2ea9 (patch)
tree12d3019d08999c1decb65cab0a6f1496f8daaf94 /gdb/testsuite
parent8ac3646fbbb5f1e0442caa55559513d593136f8c (diff)
downloadgdb-ab04a2af2bacfc1062c907630bee6e345dbd2ea9.zip
gdb-ab04a2af2bacfc1062c907630bee6e345dbd2ea9.tar.gz
gdb-ab04a2af2bacfc1062c907630bee6e345dbd2ea9.tar.bz2
2013-01-03 Pedro Alves <palves@redhat.com>
Tom Tromey <tromey@redhat.com> PR cli/7221: * NEWS: Add "catch signal". * breakpoint.c (base_breakpoint_ops): No longer static. (bpstat_explains_signal): New function. (init_catchpoint): No longer static. (base_breakpoint_explains_signal): New function. (base_breakpoint_ops): Initialize new field. * breakpoint.h (enum bpstat_signal_value): New. (struct breakpoint_ops) <explains_signal>: New field. (bpstat_explains_signal): Remove macro, declare as function. (base_breakpoint_ops, init_catchpoint): Declare. * break-catch-sig.c: New file. * inferior.h (signal_catch_update): Declare. * infrun.c (signal_catch): New global. (handle_syscall_event): Update for change to bpstat_explains_signal. (handle_inferior_event): Likewise. Always handle random signals via bpstats. (signal_cache_update): Check signal_catch. (signal_catch_update): New function. (_initialize_infrun): Initialize signal_catch. * Makefile.in (SFILES): Add break-catch-sig.c. (COMMON_OBS): Add break-catch-sig.o. gdb/doc * gdb.texinfo (Set Catchpoints): Document "catch signal". (Signals): Likewise. gdb/testsuite * gdb.base/catch-signal.c: New file. * gdb.base/catch-signal.exp: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.base/catch-signal.c46
-rw-r--r--gdb/testsuite/gdb.base/catch-signal.exp129
3 files changed, 180 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 21d01cc..b883eac 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2013-01-16 Tom Tromey <tromey@redhat.com>
+ * gdb.base/catch-signal.c: New file.
+ * gdb.base/catch-signal.exp: New file.
+
+2013-01-16 Tom Tromey <tromey@redhat.com>
+
* gdb.mi/mi-catch-load.exp: Look for "catch-type".
2013-01-15 Jan Kratochvil <jan.kratochvil@redhat.com>
diff --git a/gdb/testsuite/gdb.base/catch-signal.c b/gdb/testsuite/gdb.base/catch-signal.c
new file mode 100644
index 0000000..9c68185
--- /dev/null
+++ b/gdb/testsuite/gdb.base/catch-signal.c
@@ -0,0 +1,46 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2012 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/>. */
+
+#include <signal.h>
+#include <unistd.h>
+
+void
+do_nothing (void)
+{
+}
+
+void
+handle (int sig)
+{
+ do_nothing (); /* handle marker */
+}
+
+int
+main ()
+{
+ signal (SIGHUP, handle);
+ signal (SIGUSR1, SIG_IGN);
+
+ raise (SIGHUP); /* first HUP */
+
+ raise (SIGHUP); /* second HUP */
+
+ raise (SIGHUP); /* third HUP */
+
+ raise (SIGHUP); /* fourth HUP */
+}
+
diff --git a/gdb/testsuite/gdb.base/catch-signal.exp b/gdb/testsuite/gdb.base/catch-signal.exp
new file mode 100644
index 0000000..6c103af
--- /dev/null
+++ b/gdb/testsuite/gdb.base/catch-signal.exp
@@ -0,0 +1,129 @@
+# Copyright 2012 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/>.
+
+if [target_info exists gdb,nosignals] {
+ verbose "Skipping sigall.exp because of nosignals."
+ continue
+}
+
+standard_testfile
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
+ return -1
+}
+
+proc test_catch_signal {signame} {
+ global srcfile
+
+ with_test_prefix $signame {
+ if {![runto_main]} {
+ return -1
+ }
+
+ # Test "catch signal" without arguments.
+ # Don't let the signal be handled otherwise.
+ gdb_breakpoint ${srcfile}:[gdb_get_line_number "first HUP"]
+ gdb_continue_to_breakpoint "first HUP"
+ gdb_test "handle SIGHUP nostop noprint pass" \
+ "SIGHUP.*No.*No.*Yes.*"
+ gdb_test "catch signal" "Catchpoint .*"
+ gdb_test "continue" "Catchpoint .*"
+
+ # Now ensure that the "pass" setting worked, and also that we did not
+ # see gdb's SIGTRAP.
+ gdb_breakpoint ${srcfile}:[gdb_get_line_number "handle marker"]
+ gdb_continue_to_breakpoint "handle marker"
+
+ delete_breakpoints
+
+ # Catch just $SIGNAME.
+ gdb_breakpoint ${srcfile}:[gdb_get_line_number "second HUP"]
+ gdb_continue_to_breakpoint "second HUP"
+ gdb_test "catch signal $signame" "Catchpoint .*"
+ gdb_test "continue" "Catchpoint .*"
+ delete_breakpoints
+
+ # Catch just SIGUSR1 -- but it isn't sent.
+ gdb_breakpoint ${srcfile}:[gdb_get_line_number "third HUP"]
+ gdb_continue_to_breakpoint "third HUP"
+ gdb_test "handle SIGUSR1 nostop noprint pass" \
+ "SIGUSR1.*No.*No.*Yes.*"
+ gdb_test "catch signal SIGUSR1" "Catchpoint .*"
+
+ # Also verify that if we set SIGHUP to "nopass", then it is
+ # still not delivered.
+ gdb_breakpoint ${srcfile}:[gdb_get_line_number "handle marker"]
+ gdb_test "handle SIGHUP nostop noprint nopass" \
+ "SIGHUP.*No.*No.*No.*"
+
+ gdb_breakpoint ${srcfile}:[gdb_get_line_number "fourth HUP"]
+ gdb_continue_to_breakpoint "fourth HUP"
+ delete_breakpoints
+ }
+}
+
+# Test with symbolic signal.
+test_catch_signal SIGHUP
+
+# Test with numeric signal.
+clean_restart $testfile
+test_catch_signal 1
+
+# Test with two signals in catchpoint.
+clean_restart $testfile
+test_catch_signal "SIGHUP SIGUSR2"
+
+#
+# Coverage tests.
+#
+
+gdb_test "catch signal SIGZARDOZ" "Unknown signal name 'SIGZARDOZ'."
+gdb_test "catch signal all" "Catchpoint .*"
+gdb_test "catch signal all SIGHUP" "'all' cannot be caught with other signals"
+gdb_test "catch signal SIGHUP all" "'all' cannot be caught with other signals"
+
+set i 0
+foreach {arg desc} {"" "standard signals" \
+ SIGHUP SIGHUP \
+ "SIGHUP SIGUSR2" "SIGHUP SIGUSR2" \
+ all "any signal"} {
+ delete_breakpoints
+ gdb_test "catch signal $arg" "Catchpoint .*" \
+ "set catchpoint '$arg' for printing"
+ gdb_test "info break" "$decimal.*catchpoint.*signal.*$desc.*" \
+ "info break for '$arg'"
+ gdb_test "save breakpoints [standard_output_file bps.$i]" \
+ "Saved to file .*bps.$i.*" \
+ "save breakpoints for '$arg'"
+
+ set filename [remote_upload host [standard_output_file bps.$i] \
+ [standard_output_file bps-local.$i]]
+ set fd [open $filename]
+ set contents [read -nonewline $fd]
+ close $fd
+
+ if {$arg == ""} {
+ set pattern "catch signal"
+ } else {
+ set pattern "catch signal $arg"
+ }
+ if {[string match $pattern $contents]} {
+ pass "results of save breakpoints for '$arg'"
+ } else {
+ fail "results of save breakpoints for '$arg'"
+ }
+
+ incr i
+}