1 # Copyright
2012-2024 Free Software Foundation
, Inc.
3 # This
program is free software
; you can redistribute it and
/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation
; either version
3 of the License
, or
6 #
(at your option
) any later version.
8 # This
program is distributed in the hope that it will be useful
,
9 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License
for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this
program.
If not
, see
<http
://www.gnu.org
/licenses
/>.
16 require
{!target_info
exists gdb
,nosignals
}
20 if {[prepare_for_testing
"failed to prepare" $testfile $srcfile debug]} {
24 proc test_catch_signal
{signame
} {
27 with_test_prefix $signame
{
32 # Test
"catch signal" without arguments.
33 # Don
't let the signal be handled otherwise.
34 gdb_breakpoint ${srcfile}:[gdb_get_line_number "first HUP"]
35 gdb_continue_to_breakpoint "first HUP"
36 gdb_test "handle SIGHUP nostop noprint pass" \
37 "SIGHUP.*No.*No.*Yes.*"
38 gdb_test "catch signal" "Catchpoint .*"
39 gdb_test "continue" "Catchpoint .*" "continue to first HUP"
41 # Now ensure that the "pass" setting worked, and also that we did not
43 gdb_breakpoint $
{srcfile
}:[gdb_get_line_number
"handle marker"]
44 gdb_continue_to_breakpoint
"handle marker"
48 # Catch just $SIGNAME.
49 gdb_breakpoint $
{srcfile
}:[gdb_get_line_number
"second HUP"]
50 gdb_continue_to_breakpoint
"second HUP"
51 gdb_test
"catch signal $signame" "Catchpoint .*"
52 gdb_test
"continue" "Catchpoint .*" "continue to catch signal $signame"
55 # Catch just SIGUSR1
-- but it isn
't sent.
56 gdb_breakpoint ${srcfile}:[gdb_get_line_number "third HUP"]
57 gdb_continue_to_breakpoint "third HUP"
58 gdb_test "handle SIGUSR1 nostop noprint pass" \
59 "SIGUSR1.*No.*No.*Yes.*"
60 gdb_test "catch signal SIGUSR1" "Catchpoint .*"
62 # Also verify that if we set SIGHUP to "nopass", then it is
63 # still not delivered.
64 gdb_breakpoint ${srcfile}:[gdb_get_line_number "handle marker"]
65 gdb_test "handle SIGHUP nostop noprint nopass" \
66 "SIGHUP.*No.*No.*No.*"
68 gdb_breakpoint ${srcfile}:[gdb_get_line_number "fourth HUP"]
69 gdb_continue_to_breakpoint "fourth HUP"
72 # Verify an internal signal used by gdb is properly caught.
73 gdb_breakpoint ${srcfile}:[gdb_get_line_number "first INT"]
74 gdb_continue_to_breakpoint "first INT"
75 set test "override SIGINT to catch"
76 gdb_test "handle SIGINT nostop print nopass" \
77 "SIGINT.*No.*Yes.*No.*" \
79 "SIGINT is used by the debugger.*Are you sure you want to change it.*y or n.*" \
81 gdb_test "catch signal SIGINT" "Catchpoint .*"
82 gdb_test "continue" "Catchpoint .* SIGINT.*"
86 # Test with symbolic signal.
87 test_catch_signal SIGHUP
89 # Test with numeric signal.
90 clean_restart $testfile
93 # Test with two signals in catchpoint.
94 clean_restart $testfile
95 test_catch_signal "SIGHUP SIGUSR2"
101 gdb_test "catch signal SIGZARDOZ" "Unknown signal name 'SIGZARDOZ
'."
102 gdb_test "catch signal all" "Catchpoint .*"
103 gdb_test "catch signal all SIGHUP" "'all
' cannot be caught with other signals"
104 gdb_test "catch signal SIGHUP all" "'all
' cannot be caught with other signals"
107 foreach {arg desc} {"" "standard signals" \
109 "SIGHUP SIGUSR2" "SIGHUP SIGUSR2" \
112 gdb_test "catch signal $arg" "Catchpoint .*" \
113 "set catchpoint '$
arg' for printing"
114 gdb_test "info break" "$decimal.*catchpoint.*signal.*$desc.*" \
115 "info break for '$
arg'"
116 gdb_breakpoint "main"
117 gdb_test "save breakpoints [standard_output_file bps.$i]" \
118 "Saved to file .*bps.$i.*" \
119 "save breakpoints for '$
arg'"
121 set filename [remote_upload host [standard_output_file bps.$i] \
122 [standard_output_file bps-local.$i]]
123 set fd [open $filename]
124 set file_data [read $fd]
125 set data [split $file_data "\n"]
129 set pattern "catch signal"
131 set pattern "catch signal $arg"
133 gdb_assert {[expr [llength $data] == 3]} \
134 "Number of lines of save breakpoints for '$
arg'"
135 # Check the first line.
136 gdb_assert {[string match $pattern [lindex $data 0]]} \
137 "1st line of save breakpoints for '$
arg'"
138 # Check the second line.
139 gdb_assert {[string match "break main" [lindex $data 1]]} \
140 "2nd line of save breakpoints for '$
arg'"
141 # Check the trailing newline.
142 gdb_assert {[string match "" [lindex $data 2]]} \
143 "Trailing newline of save breakpoints for '$
arg'"