]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/signals.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / signals.exp
1 # Copyright 1997-2024 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 require {!target_info exists gdb,nosignals}
17
18
19 standard_testfile .c
20
21 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
22 untested "failed to compile"
23 return -1
24 }
25
26 gdb_exit
27 gdb_start
28
29 # This will need to be updated as the exact list of signals changes,
30 # but I want to test that GDB_SIGNAL_0, GDB_SIGNAL_DEFAULT, and
31 # GDB_SIGNAL_UNKNOWN are skipped.
32
33 proc test_handle_all_print {} {
34 global timeout
35 # Increase timeout and expect input buffer for large output from gdb.
36 # Allow blank or TAB as whitespace characters.
37 set oldtimeout $timeout
38 set timeout [expr "$timeout + 60"]
39 verbose "Timeout is now $timeout seconds" 2
40 if { ![istarget "*-*-linux*"]
41 && ( [istarget "*-*-gnu*"]
42 || [istarget "*-*-mach*"] ) } {
43 gdb_test_sequence "handle all print" "" \
44 {
45 "Signal\[ \]+Stop\[ \]+Print\[ \]+Pass to program\[ \]+Description\r\nSIGHUP\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Hangup"
46 "SIG63\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Real-time event 63"
47 "EXC_BREAKPOINT\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Breakpoint"
48 }
49 } else {
50 gdb_test_sequence "handle all print" "" \
51 {
52 "Signal\[ \]+Stop\[ \]+Print\[ \]+Pass to program\[ \]+Description\r\nSIGHUP\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Hangup"
53 "SIG63\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Real-time event 63"
54 }
55 }
56 set timeout $oldtimeout
57 verbose "Timeout restored to $timeout seconds" 2
58 }
59 test_handle_all_print
60
61 clean_restart $binfile
62
63 if {[runto_main]} {
64
65 # Since count is a static variable outside main, runto_main is no
66 # guarantee that count will be 0 at this point.
67
68 gdb_test_no_output "set variable count = 0"
69
70 # Test an inferior function call that takes a signal that hits a
71 # breakpoint (with a false condition). When GDB tries to run the
72 # stack dummy, it will hit the breakpoint at handler. Provided it
73 # doesn't lose its cool, this is not a problem, it just has to
74 # note that the breakpoint condition is false and keep going.
75
76 # ...setup an always false conditional breakpoint
77
78 gdb_test "break handler if 0" "Breakpoint \[0-9\]+ .*"
79 gdb_test_no_output "set \$handler_breakpoint_number = \$bpnum"
80
81 # ...setup the signal
82
83 gdb_test "next" "signal \\(SIGUSR1.*" "next to signal"
84 gdb_test "next" "alarm \\(.*" "next to alarm #1"
85 gdb_test "next" "\\+\\+count; /\\* first \\*/" \
86 "next to ++count #1"
87 sleep 2
88
89 # ...call the function
90
91 gdb_test "p func1 ()" "^\\\$$decimal = void" \
92 "p func1 () #1"
93
94 # ...veryfiy that the cout was updated
95
96 gdb_test "p count" "= 2" "p count #1"
97
98 # Now run the same test but with a breakpoint that does stop.
99
100 # ...set up the breakpoint and signal
101
102 gdb_test "condition \$handler_breakpoint_number" "now unconditional\\."
103 gdb_test "next" "alarm \\(.*" "next to alarm #2"
104 gdb_test "next" "\\+\\+count; /\\* second \\*/" \
105 "next to ++count #2"
106 sleep 2
107
108 # ...call the function, which is immediatly interrupted
109
110 gdb_test "p func1 ()" \
111 "Breakpoint \[0-9\]*, handler.*
112 The program being debugged stopped while in a function called from GDB.*" \
113 "p func1 () #2"
114
115 # ...verify the backtrace
116
117 gdb_test "backtrace" \
118 "#0 handler.*#1 .signal handler called.*#2 func1.*#3 .function called from gdb.*#4.*main.*" \
119 "backtrace from handler when calling func1"
120
121 # ...and continue (silently returning)
122
123 gdb_test "continue" "Continuing\\."
124
125 # ...and then count should have been incremented
126
127 gdb_test "p count" "= 5" "p count #2"
128
129
130 # Verify that "info signals" produces reasonable output.
131
132 gdb_test_sequence "info signals" "" \
133 [list "SIGHUP" "SIGINT" "SIGQUIT" "SIGILL" "SIGTRAP" "SIGABRT" \
134 "SIGEMT" "SIGFPE" "SIGKILL" "SIGBUS" "SIGSEGV" "SIGSYS" \
135 "SIGPIPE" "SIGALRM" "SIGTERM" "SIGURG" "SIGSTOP" \
136 "SIGTSTP" "SIGCONT" "SIGCHLD" "SIGTTIN" "SIGTTOU" "SIGIO" \
137 "SIGXCPU" "SIGXFSZ" "SIGVTALRM" "SIGPROF" "SIGWINCH" \
138 "SIGLOST" "SIGUSR1" "SIGUSR2" "SIGPWR" "SIGPOLL" \
139 "SIGWIND" "SIGPHONE" "SIGWAITING" "SIGLWP" "SIGDANGER" \
140 "SIGGRANT" "SIGRETRACT" "SIGMSG" "SIGSOUND" "SIGSAK" \
141 "SIGPRIO" "SIG33" "SIG34" "SIG35" "SIG36" "SIG37" "SIG38" \
142 "SIG39" "SIG40" "SIG41" "SIG42" "SIG43" "SIG44" "SIG45" \
143 "SIG46" "SIG47" "SIG48" "SIG49" "SIG50" "SIG51" "SIG52" \
144 "SIG53" "SIG54" "SIG55" "SIG56" "SIG57" "SIG58" "SIG59" \
145 "SIG60" "SIG61" "SIG62" "SIG63" \
146 "Use the \"handle\" command to change these tables"]
147
148 # Verify that "info signal" correctly handles an argument, be it a
149 # symbolic signal name, or an integer ID.
150
151 gdb_test "info signal SIGTRAP" \
152 "SIGTRAP\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*No\[ \t\]*Trace/breakpoint trap.*"
153
154 gdb_test "info signal 5" \
155 "SIGTRAP\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*No\[ \t\]*Trace/breakpoint trap.*"
156
157 # Verify that "handle" with illegal arguments is gracefully, um,
158 # handled.
159
160 gdb_test "handle" \
161 "Argument required .signal to handle.*" \
162 "handle without arguments"
163
164 gdb_test "handle SIGFOO" \
165 "Unrecognized or ambiguous flag word: \"SIGFOO\".*" \
166 "handle with bogus SIG"
167
168 gdb_test "handle SIGHUP frump" \
169 "Unrecognized or ambiguous flag word: \"frump\".*" \
170 "handle SIG with bogus action"
171
172 # Verify that "handle" can take multiple actions per SIG, and that
173 # in the case of conflicting actions, that the rightmost action
174 # "wins".
175
176 gdb_test "handle SIGHUP print noprint" \
177 "SIGHUP\[ \t\]*No\[ \t\]*No\[ \t\]*Yes\[ \t\]*Hangup.*" \
178 "handle SIG with multiple conflicting actions"
179
180 # Exercise all the various actions. (We don't care what the
181 # outcome is, this is just to ensure that they all can be parsed.)
182
183 gdb_test "handle SIGHUP print noprint stop nostop ignore noignore pass nopass" \
184 "Signal.*" \
185 "handle SIG parses all legal actions"
186
187 # Verify that we can "handle" multiple signals at once,
188 # interspersed with actions.
189
190 gdb_test "handle SIG63 print SIGILL" \
191 "SIGILL\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Illegal instruction.*SIG63\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Real-time event 63.*" \
192 "handle multiple SIGs"
193
194 # Verify that "handle" can take a numeric argument for the signal
195 # ID, rather than a symbolic name. (This may not be portable;
196 # works for HP-UX.)
197
198 # Also note that this testpoint overrides SIGTRAP, which on HP-UX
199 # at least, is used to implement single-steps and breakpoints.
200 # Don't expect to run the inferior after this!
201
202 set test "override SIGTRAP"
203 gdb_test_multiple "handle 5 nopass" "$test" {
204 -re "SIGTRAP is used by the debugger.*Are you sure you want to change it.*y or n.*" {
205 gdb_test "y" \
206 "SIGTRAP\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*No\[ \t\]*Trace/breakpoint trap.*" \
207 "$test"
208 }
209 }
210
211 # GDB doesn't seem to allow numeric signal IDs larger than 15. Verify
212 # that restriction. ??rehrauer: Not sure if this is a feature or a
213 # bug, actually. Why is the range 1-15?
214
215 gdb_test "handle 58" \
216 "Only signals 1-15 are valid as numeric signals.*Use \"info signals\" for a list of symbolic signals.*" \
217 "invalid signal number rejected"
218
219 # Verify that we can accept a signal ID range (number-number).
220 # ??rehrauer: This feature isn't documented on the quick-reference
221 # card.
222
223 gdb_test "handle 13-15" \
224 "SIGPIPE.*SIGALRM.*SIGTERM.*" \
225 "handle multiple SIGs via integer range"
226
227 # Bizarrely enough, GDB also allows you to reverse the range stat,
228 # stop IDs. E.g., "3-1" and "1-3" mean the same thing. Probably
229 # this isn't documented, but the code anticipates it, so we'd best
230 # test it...
231
232 gdb_test "handle 15-13" \
233 "SIGPIPE.*SIGALRM.*SIGTERM.*" \
234 "handle multiple SIGs via reverse integer range"
235
236 # SIGINT is used by the debugger as well. Verify that we can
237 # change our minds about changing it.
238
239 set test "override SIGINT"
240 gdb_test_multiple "handle SIGINT nopass" "$test" {
241 -re "SIGINT is used by the debugger.*Are you sure you want to change it.*y or n.*" {
242 gdb_test_multiple "n" "$test" {
243 -re "Not confirmed, unchanged.*Signal.*$gdb_prompt $" {
244 # "Signal ..." should not be in the output.
245 fail gdb/8812 "$test"
246 }
247 -re "Not confirmed, unchanged.*$gdb_prompt $" {
248 pass "$test"
249 }
250 }
251 }
252 }
253
254 # Verify that GDB responds gracefully to the "signal" command with
255 # a missing argument.
256
257 gdb_test "signal" \
258 "Argument required .signal number..*" \
259 "signal without arguments disallowed"
260
261 # Verify that we can successfully send a signal other than 0 to
262 # the inferior. (This probably causes the inferior to run away.
263 # Be prepared to rerun to main for further testing.)
264
265 gdb_test "signal SIGUSR1" "Breakpoint.*handler.*"
266 gdb_test "bt" \
267 "#0 handler .*#1 .signal handler called.*\#2 .*main.*" \
268 "backtrace for SIGUSR1"
269 }