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