ab04a2af2b
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.
129 lines
3.8 KiB
Text
129 lines
3.8 KiB
Text
# 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
|
|
}
|