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