GDB: trad-frame: Store length of value_bytes in trad_frame_saved_reg
[binutils-gdb.git] / gdb / testsuite / gdb.base / catch-signal.exp
blob6e15da011ac1347ee9bcc417e1d8c2944384cb9c
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}
18 standard_testfile
20 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
21 return -1
24 proc test_catch_signal {signame} {
25 global srcfile
27 with_test_prefix $signame {
28 if {![runto_main]} {
29 return -1
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
42 # see gdb's SIGTRAP.
43 gdb_breakpoint ${srcfile}:[gdb_get_line_number "handle marker"]
44 gdb_continue_to_breakpoint "handle marker"
46 delete_breakpoints
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"
53 delete_breakpoints
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"
70 delete_breakpoints
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.*" \
78 "$test" \
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
91 test_catch_signal 1
93 # Test with two signals in catchpoint.
94 clean_restart $testfile
95 test_catch_signal "SIGHUP SIGUSR2"
98 # Coverage tests.
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"
106 set i 0
107 foreach {arg desc} {"" "standard signals" \
108 SIGHUP SIGHUP \
109 "SIGHUP SIGUSR2" "SIGHUP SIGUSR2" \
110 all "any signal"} {
111 delete_breakpoints
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"]
126 close $fd
128 if {$arg == ""} {
129 set pattern "catch signal"
130 } else {
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'"
145 incr i