1 # Copyright 1997, 1998, 1999, 2003, 2004 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 if [target_info exists gdb,nosignals] {
18 verbose "Skipping signals.exp because of nosignals."
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."
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}] {
42 if {$hp_cc_compiler} {
48 proc signal_tests_1 {} {
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"
56 # Set up an alarm, wait for it to be come pending then do a
57 # next to see what happens.
59 gdb_test "next" "\\+\\+count; /\\* first \\*/" \
62 gdb_test "next" "alarm .*" \
63 "next over first count and SIGALRM to 2nd alarm"
65 # Now do the same thing but with a breakpoint in the SIGALRM
66 # handler so that we stop there.
68 gdb_test "break handler" "Breakpoint \[0-9\]+ .*"
69 gdb_test "next" "\\+\\+count; /\\* second \\*/" \
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"
78 # Let the signal handler return allowing main to advance to
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"
85 # While still in func1, force a signal, check the backtrace.
87 gdb_test "signal SIGUSR1" "Breakpoint.*handler.*"
89 "#0 handler .*#1 .signal handler called.*#2 func1 .*\#3 .*main.*" \
90 "backtrace for SIGUSR1"
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
102 set test "continue to func2"
103 gdb_test_multiple "continue" "$test" {
104 -re "Breakpoint.*func2.*$gdb_prompt $" {
107 -re "Breakpoint.*func1.*$gdb_prompt $" {
109 gdb_test "continue" "Breakpoint.*func2.*" \
110 "extra continue to func2"
114 # In running to func2, the 2rd alarm call will have been set
115 # up, let it be delivered.
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"
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.
129 set test "continue to program exit"
130 gdb_test_multiple "continue" "$test" {
131 -re "Program exited with code 010\\." {
134 -re "Breakpoint.*func2.*$gdb_prompt $" {
136 gdb_test "continue" "Program exited with code 010\\." \
137 "extra continue to program exit"
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.
150 proc test_handle_all_print {} {
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"
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.*"
164 set timeout $oldtimeout
165 verbose "Timeout restored to $timeout seconds" 2
167 test_handle_all_print
171 gdb_reinitialize_dir $srcdir/$subdir
175 if [runto_main] then {
177 # Since count is a static variable outside main, runto_main is no
178 # guarantee that count will be 0 at this point.
180 gdb_test "set variable count = 0" ""
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.
188 # ...setup an always false conditional breakpoint
190 gdb_test "break handler if 0" "Breakpoint \[0-9\]+ .*"
191 gdb_test "set \$handler_breakpoint_number = \$bpnum" ""
193 # ...setup the signal
195 gdb_test "next" "signal \\(SIGUSR1.*" "next to signal"
196 gdb_test "next" "alarm \\(.*" "next to alarm #1"
197 gdb_test "next" "\\+\\+count; /\\* first \\*/" \
201 # ...call the function
203 gdb_test "p func1 ()" "^p func1 \\(\\)\r\n.\[0-9\]* = $void" \
206 # ...veryfiy that the cout was updated
208 gdb_test "p count" "= 2" "p count #1"
210 # Now run the same test but with a breakpoint that does stop.
212 # ...set up the breakpoint and signal
214 gdb_test "condition \$handler_breakpoint_number" "now unconditional\\."
215 gdb_test "next" "alarm \\(.*" "next to alarm #2"
216 gdb_test "next" "\\+\\+count; /\\* second \\*/" \
220 # ...call the function, which is immediatly interrupted
222 gdb_test "p func1 ()" \
223 "Breakpoint \[0-9\]*, handler.*
224 The program being debugged stopped while in a function called from GDB.*" \
227 # ...verify the backtrace
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"
233 # ...and continue (silently returning)
235 gdb_test "continue" "Continuing\\."
237 # ...and then count should have been incremented
239 gdb_test "p count" "= 5" "p count #2"
242 # Verify that "info signals" produces reasonable output.
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.*" \
247 # Verify that "info signal" correctly handles an argument, be it a
248 # symbolic signal name, or an integer ID.
250 gdb_test "info signal SIGTRAP" \
251 "SIGTRAP\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*No\[ \t\]*Trace/breakpoint trap.*" \
252 "info signal SIGTRAP"
254 gdb_test "info signal 5" \
255 "SIGTRAP\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*No\[ \t\]*Trace/breakpoint trap.*" \
258 # Verify that "handle" with illegal arguments is gracefully, um,
262 "Argument required .signal to handle.*" \
263 "handle without arguments"
265 gdb_test "handle SIGFOO" \
266 "Unrecognized or ambiguous flag word: \"SIGFOO\".*" \
267 "handle with bogus SIG"
269 gdb_test "handle SIGHUP frump" \
270 "Unrecognized or ambiguous flag word: \"frump\".*" \
271 "handle SIG with bogus action"
273 # Verify that "handle" can take multiple actions per SIG, and that
274 # in the case of conflicting actions, that the rightmost action
277 gdb_test "handle SIGHUP print noprint" \
278 "SIGHUP\[ \t\]*No\[ \t\]*No\[ \t\]*Yes\[ \t\]*Hangup.*" \
279 "handle SIG with multiple conflicting actions"
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.)
284 gdb_test "handle SIGHUP print noprint stop nostop ignore noignore pass nopass" \
286 "handle SIG parses all legal actions"
288 # Verify that we can "handle" multiple signals at once,
289 # interspersed with actions.
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"
295 # Verify that "handle" can take a numeric argument for the signal
296 # ID, rather than a symbolic name. (This may not be portable;
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!
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.*" {
307 "SIGTRAP\[ \t\]*Yes\[ \t\]*Yes\[ \t\]*No\[ \t\]*Trace/breakpoint trap.*" \
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?
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"
320 # Verify that we can accept a signal ID range (number-number).
321 # ??rehrauer: This feature isn't documented on the quick-reference
324 gdb_test "handle 13-15" \
325 "SIGPIPE.*SIGALRM.*SIGTERM.*" \
326 "handle multiple SIGs via integer range"
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
333 gdb_test "handle 15-13" \
334 "SIGPIPE.*SIGALRM.*SIGTERM.*" \
335 "handle multiple SIGs via reverse integer range"
337 # SIGINT is used by the debugger as well. Verify that we can
338 # change our minds about changing it.
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"
348 -re "Not confirmed, unchanged.*$gdb_prompt $" {
355 # Verify that GDB responds gracefully to the "signal" command with
356 # a missing argument.
359 "Argument required .signal number..*" \
360 "signal without arguments disallowed"
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.)
366 gdb_test "signal 5" \
367 "Continuing with signal SIGTRAP.*" \