2004-07-20 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / signals.exp
1 # Copyright 1997, 1998, 1999, 2003, 2004 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 if [target_info exists gdb,nosignals] {
18 verbose "Skipping signals.exp because of nosignals."
19 continue
20 }
21
22 if $tracelevel then {
23 strace $tracelevel
24 }
25
26 set prms_id 0
27 set bug_id 0
28
29 set testfile signals
30 set srcfile ${testfile}.c
31 set binfile ${objdir}/${subdir}/${testfile}
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
33 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
34 }
35
36 # Create and source the file that provides information about the compiler
37 # used to compile the test case.
38 if [get_compiler_info ${binfile}] {
39 return -1;
40 }
41
42 if {$hp_cc_compiler} {
43 set void 0
44 } else {
45 set void void
46 }
47
48 proc signal_tests_1 {} {
49 global gdb_prompt
50 if [runto_main] then {
51 gdb_test "next" "signal \\(SIGUSR1.*" \
52 "next over signal call; SIGALRM handler"
53 gdb_test "next" "alarm \\(.*" \
54 "next over signal call; SIGUSR1 handler"
55
56 # Set up an alarm, wait for it to be come pending then do a
57 # next to see what happens.
58
59 gdb_test "next" "\\+\\+count; /\\* first \\*/" \
60 "next over 1st alarm"
61 sleep 2
62 gdb_test "next" "alarm .*" \
63 "next over first count and SIGALRM to 2nd alarm"
64
65 # Now do the same thing but with a breakpoint in the SIGALRM
66 # handler so that we stop there.
67
68 gdb_test "break handler" "Breakpoint \[0-9\]+ .*"
69 gdb_test "next" "\\+\\+count; /\\* second \\*/" \
70 "next over 2nd alarm"
71 sleep 2
72 gdb_test "next" "Breakpoint.*handler.*" \
73 "next over second count, but jump to handler"
74 gdb_test "backtrace" \
75 "#0.*handler.*#1.*signal handler.*#2.* main .*" \
76 "backtrace for 2nd alarm"
77
78 # Let the signal handler return allowing main to advance to
79 # func1.
80
81 gdb_test "break func1" "Breakpoint \[0-9\]+ .*"
82 gdb_test "break func2" "Breakpoint \[0-9\]+ .*"
83 gdb_test "continue" "Breakpoint.*func1.*" "continue to func1"
84
85 # While still in func1, force a signal, check the backtrace.
86
87 gdb_test "signal SIGUSR1" "Breakpoint.*handler.*"
88 gdb_test "bt" \
89 "#0 handler .*#1 .signal handler called.*#2 func1 .*\#3 .*main.*" \
90 "backtrace for SIGUSR1"
91
92 # The problem here is that the breakpoint at func1 will be
93 # inserted, and when the system finishes with the signal
94 # handler it will try to execute there. For GDB to try to
95 # remember that it was going to step over a breakpoint when a
96 # signal happened, distinguish this case from the case where
97 # func1 is called from the signal handler, etc., seems
98 # exceedingly difficult. So don't expect this to get fixed
99 # anytime soon.
100
101 setup_xfail "*-*-*"
102 set test "continue to func2"
103 gdb_test_multiple "continue" "$test" {
104 -re "Breakpoint.*func2.*$gdb_prompt $" {
105 pass "$test"
106 }
107 -re "Breakpoint.*func1.*$gdb_prompt $" {
108 fail "$test"
109 gdb_test "continue" "Breakpoint.*func2.*" \
110 "extra continue to func2"
111 }
112 }
113
114 # In running to func2, the 2rd alarm call will have been set
115 # up, let it be delivered.
116
117 sleep 2
118 gdb_test "continue" "Breakpoint.*handler.*" \
119 "continue to handler for 3rd alarm call"
120 gdb_test "backtrace" \
121 "#0 handler.*#1.*signal handler called.*#2 func2.*#3.*main.*" \
122 "backtrace for 3rd alarm"
123
124 # If we succeeded a continue will return from the handler to
125 # func2. GDB now has `forgotten' that it intended to step
126 # over the breakpoint at func2 and will stop at func2.
127
128 setup_xfail "*-*-*"
129 set test "continue to program exit"
130 gdb_test_multiple "continue" "$test" {
131 -re "Program exited with code 010\\." {
132 pass "$test"
133 }
134 -re "Breakpoint.*func2.*$gdb_prompt $" {
135 fail "$test"
136 gdb_test "continue" "Program exited with code 010\\." \
137 "extra continue to program exit"
138 }
139 }
140 }
141 }
142
143 gdb_exit
144 gdb_start
145
146 # This will need to be updated as the exact list of signals changes,
147 # but I want to test that TARGET_SIGNAL_0, TARGET_SIGNAL_DEFAULT, and
148 # TARGET_SIGNAL_UNKNOWN are skipped.
149
150 proc test_handle_all_print {} {
151 global timeout
152 # Increase timeout and expect input buffer for large output from gdb.
153 # Allow blank or TAB as whitespace characters.
154 set oldtimeout $timeout
155 set timeout [expr "$timeout + 360"]
156 verbose "Timeout is now $timeout seconds" 2
157 if { ![istarget "*-*-linux*"]
158 && ( [istarget "*-*-gnu*"]
159 || [istarget "*-*-mach*"] ) } {
160 gdb_test "handle all print" "Signal\[ \]+Stop\[ \]+Print\[ \]+Pass to program\[ \]+Description\r\nSIGHUP\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Hangup.*SIG63\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Real-time event 63.*EXC_BREAKPOINT\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Breakpoint"
161 } else {
162 gdb_test "handle all print" "Signal\[ \]+Stop\[ \]+Print\[ \]+Pass to program\[ \]+Description\r\nSIGHUP\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Hangup.*SIG63\[ \]+Yes\[ \]+Yes\[ \]+Yes\[ \]+Real-time event 63.*"
163 }
164 set timeout $oldtimeout
165 verbose "Timeout restored to $timeout seconds" 2
166 }
167 test_handle_all_print
168
169 gdb_exit
170 gdb_start
171 gdb_reinitialize_dir $srcdir/$subdir
172 gdb_load $binfile
173 signal_tests_1
174
175 if [runto_main] then {
176
177 # Since count is a static variable outside main, runto_main is no
178 # guarantee that count will be 0 at this point.
179
180 gdb_test "set variable count = 0" ""
181
182 # Test an inferior function call that takes a signal that hits a
183 # breakpoint (with a false condition). When GDB tries to run the
184 # stack dummy, it will hit the breakpoint at handler. Provided it
185 # doesn't lose its cool, this is not a problem, it just has to
186 # note that the breakpoint condition is false and keep going.
187
188 # ...setup an always false conditional breakpoint
189
190 gdb_test "break handler if 0" "Breakpoint \[0-9\]+ .*"
191 gdb_test "set \$handler_breakpoint_number = \$bpnum" ""
192
193 # ...setup the signal
194
195 gdb_test "next" "signal \\(SIGUSR1.*" "next to signal"
196 gdb_test "next" "alarm \\(.*" "next to alarm #1"
197 gdb_test "next" "\\+\\+count; /\\* first \\*/" \
198 "next to ++count #1"
199 sleep 2
200
201 # ...call the function
202
203 gdb_test "p func1 ()" "^p func1 \\(\\)\r\n.\[0-9\]* = $void" \
204 "p func1 () #1"
205
206 # ...veryfiy that the cout was updated
207
208 gdb_test "p count" "= 2" "p count #1"
209
210 # Now run the same test but with a breakpoint that does stop.
211
212 # ...set up the breakpoint and signal
213
214 gdb_test "condition \$handler_breakpoint_number" "now unconditional\\."
215 gdb_test "next" "alarm \\(.*" "next to alarm #2"
216 gdb_test "next" "\\+\\+count; /\\* second \\*/" \
217 "next to ++count #2"
218 sleep 2
219
220 # ...call the function, which is immediatly interrupted
221
222 gdb_test "p func1 ()" \
223 "Breakpoint \[0-9\]*, handler.*
224 The program being debugged stopped while in a function called from GDB.*" \
225 "p func1 () #2"
226
227 # ...verify the backtrace
228
229 gdb_test "backtrace" \
230 "#0 handler.*#1 .signal handler called.*#2 func1.*#3 .function called from gdb.*#4.*main.*" \
231 "backtrace from handler when calling func1"
232
233 # ...and continue (silently returning)
234
235 gdb_test "continue" "Continuing\\."
236
237 # ...and then count should have been incremented
238
239 gdb_test "p count" "= 5" "p count #2"
240
241
242 # Verify that "info signals" produces reasonable output.
243
244 gdb_test "info signals" "SIGHUP.*SIGINT.*SIGQUIT.*SIGILL.*SIGTRAP.*SIGABRT.*SIGEMT.*SIGFPE.*SIGKILL.*SIGBUS.*SIGSEGV.*SIGSYS.*SIGPIPE.*SIGALRM.*SIGTERM.*SIGURG.*SIGSTOP.*SIGTSTP.*SIGCONT.*SIGCHLD.*SIGTTIN.*SIGTTOU.*SIGIO.*SIGXCPU.*SIGXFSZ.*SIGVTALRM.*SIGPROF.*SIGWINCH.*SIGLOST.*SIGUSR1.*SIGUSR2.*SIGPWR.*SIGPOLL.*SIGWIND.*SIGPHONE.*SIGWAITING.*SIGLWP.*SIGDANGER.*SIGGRANT.*SIGRETRACT.*SIGMSG.*SIGSOUND.*SIGSAK.*SIGPRIO.*SIG33.*SIG34.*SIG35.*SIG36.*SIG37.*SIG38.*SIG39.*SIG40.*SIG41.*SIG42.*SIG43.*SIG44.*SIG45.*SIG46.*SIG47.*SIG48.*SIG49.*SIG50.*SIG51.*SIG52.*SIG53.*SIG54.*SIG55.*SIG56.*SIG57.*SIG58.*SIG59.*SIG60.*SIG61.*SIG62.*SIG63.*Use the \"handle\" command to change these tables.*" \
245 "info signals"
246
247 # Verify that "info signal" correctly handles an argument, be it a
248 # symbolic signal name, or an integer ID.
249
250 gdb_test "info signal SIGTRAP" \
251 "SIGTRAP\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*No\[ \t\]*Trace/breakpoint trap.*" \
252 "info signal SIGTRAP"
253
254 gdb_test "info signal 5" \
255 "SIGTRAP\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*No\[ \t\]*Trace/breakpoint trap.*" \
256 "info signal 5"
257
258 # Verify that "handle" with illegal arguments is gracefully, um,
259 # handled.
260
261 gdb_test "handle" \
262 "Argument required .signal to handle.*" \
263 "handle without arguments"
264
265 gdb_test "handle SIGFOO" \
266 "Unrecognized or ambiguous flag word: \"SIGFOO\".*" \
267 "handle with bogus SIG"
268
269 gdb_test "handle SIGHUP frump" \
270 "Unrecognized or ambiguous flag word: \"frump\".*" \
271 "handle SIG with bogus action"
272
273 # Verify that "handle" can take multiple actions per SIG, and that
274 # in the case of conflicting actions, that the rightmost action
275 # "wins".
276
277 gdb_test "handle SIGHUP print noprint" \
278 "SIGHUP\[ \t\]*No\[ \t\]*No\[ \t\]*Yes\[ \t\]*Hangup.*" \
279 "handle SIG with multiple conflicting actions"
280
281 # Exercise all the various actions. (We don't care what the
282 # outcome is, this is just to ensure that they all can be parsed.)
283
284 gdb_test "handle SIGHUP print noprint stop nostop ignore noignore pass nopass" \
285 "Signal.*" \
286 "handle SIG parses all legal actions"
287
288 # Verify that we can "handle" multiple signals at once,
289 # interspersed with actions.
290
291 gdb_test "handle SIG63 print SIGILL" \
292 "SIGILL\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Illegal instruction.*SIG63\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*Real-time event 63.*" \
293 "handle multiple SIGs"
294
295 # Verify that "handle" can take a numeric argument for the signal
296 # ID, rather than a symbolic name. (This may not be portable;
297 # works for HP-UX.)
298
299 # Also note that this testpoint overrides SIGTRAP, which on HP-UX
300 # at least, is used to implement single-steps and breakpoints.
301 # Don't expect to run the inferior after this!
302
303 set test "override SIGTRAP"
304 gdb_test_multiple "handle 5 nopass" "$test" {
305 -re "SIGTRAP is used by the debugger.*Are you sure you want to change it.*y or n.*" {
306 gdb_test "y" \
307 "SIGTRAP\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*No\[ \t\]*Trace/breakpoint trap.*" \
308 "$test"
309 }
310 }
311
312 # GDB doesn't seem to allow numeric signal IDs larger than 15. Verify
313 # that restriction. ??rehrauer: Not sure if this is a feature or a
314 # bug, actually. Why is the range 1-15?
315
316 gdb_test "handle 58" \
317 "Only signals 1-15 are valid as numeric signals.*Use \"info signals\" for a list of symbolic signals.*" \
318 "invalid signal number rejected"
319
320 # Verify that we can accept a signal ID range (number-number).
321 # ??rehrauer: This feature isn't documented on the quick-reference
322 # card.
323
324 gdb_test "handle 13-15" \
325 "SIGPIPE.*SIGALRM.*SIGTERM.*" \
326 "handle multiple SIGs via integer range"
327
328 # Bizarrely enough, GDB also allows you to reverse the range stat,
329 # stop IDs. E.g., "3-1" and "1-3" mean the same thing. Probably
330 # this isn't documented, but the code anticipates it, so we'd best
331 # test it...
332
333 gdb_test "handle 15-13" \
334 "SIGPIPE.*SIGALRM.*SIGTERM.*" \
335 "handle multiple SIGs via reverse integer range"
336
337 # SIGINT is used by the debugger as well. Verify that we can
338 # change our minds about changing it.
339
340 set test "override SIGINT"
341 gdb_test_multiple "handle SIGINT nopass" "$test" {
342 -re "SIGINT is used by the debugger.*Are you sure you want to change it.*y or n.*" {
343 gdb_test_multiple "n" "$test" {
344 -re "Not confirmed, unchanged.*Signal.*$gdb_prompt $" {
345 # "Signal ..." should not be in the output.
346 kfail gdb/1707 "$test"
347 }
348 -re "Not confirmed, unchanged.*$gdb_prompt $" {
349 pass "$test"
350 }
351 }
352 }
353 }
354
355 # Verify that GDB responds gracefully to the "signal" command with
356 # a missing argument.
357
358 gdb_test "signal" \
359 "Argument required .signal number..*" \
360 "signal without arguments disallowed"
361
362 # Verify that we can successfully send a signal other than 0 to
363 # the inferior. (This probably causes the inferior to run away.
364 # Be prepared to rerun to main for further testing.)
365
366 gdb_test "signal 5" \
367 "Continuing with signal SIGTRAP.*" \
368 "sent signal 5"
369
370 }
371
372 return 0
This page took 0.038594 seconds and 5 git commands to generate.