1 # Copyright 2004-2012 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 3 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, see <http://www.gnu.org/licenses/>.
17 # The program sigstep.c creates a very simple backtrace containing one
18 # signal handler and signal trampoline. A flag is set and then the
19 # handler returns. This is repeated at infinitum.
21 # This test runs the program up to the signal handler, and then
22 # attempts to step/next out of the handler and back into main.
24 if [target_info exists gdb,nosignals] {
25 verbose "Skipping sigstep.exp because of nosignals."
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
38 untested "Couldn't compile ${srcfile}.c"
45 gdb_reinitialize_dir $srcdir/$subdir
48 gdb_test "display/i \$pc"
51 if { ![runto_main] } then {
55 # Pass all the alarms straight through (but verbosely)
56 # gdb_test "handle SIGALRM print pass nostop"
57 # gdb_test "handle SIGVTALRM print pass nostop"
58 # gdb_test "handle SIGPROF print pass nostop"
60 # Run to the signal handler, validate the backtrace.
61 gdb_test "break handler"
62 gdb_test "continue" ".* handler .*" "continue to stepi handler"
63 gdb_test_sequence "bt" "backtrace for nexti" {
64 "\[\r\n\]+.0 \[^\r\n\]* handler "
65 "\[\r\n\]+.1 .signal handler called."
66 "\[\r\n\]+.2 \[^\r\n\]* main "
70 global gdb_prompt inferior_exited_re
71 set prefix "$i from handler"
73 # Get us back into the handler
74 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
76 set test "$prefix; leave handler"
77 gdb_test_multiple "$i" "${test}" {
78 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
79 setup_kfail gdb/1736 "sparc*-*-openbsd*"
80 fail "$test (could not insert single-step breakpoint)"
82 -re "done = 1;.*${gdb_prompt} $" {
84 exp_continue -continue_timer
86 -re "\} .. handler .*${gdb_prompt} $" {
88 exp_continue -continue_timer
90 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
91 setup_kfail gdb/1639 powerpc-*-*bsd*
92 fail "$test (program exited)"
94 -re "(while ..done|done = 0).*${gdb_prompt} $" {
95 # After stepping out of a function /r signal-handler, GDB will
96 # advance the inferior until it is at the first instruction of
97 # a code-line. While typically things return to the middle of
98 # the "while..." (and hence GDB advances the inferior to the
99 # "return..." line) it is also possible for the return to land
100 # on the first instruction of "while...". Accept both cases.
106 proc advancei { i } {
107 global gdb_prompt inferior_exited_re
108 set prefix "$i from handleri"
111 # Get us back into the handler
112 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
114 set test "$prefix; leave handler"
115 gdb_test_multiple "$i" "${test}" {
116 -re "Cannot insert breakpoint 0.*${gdb_prompt} $" {
117 # Some platforms use a special read-only page for signal
118 # trampolines. We can't set a breakpoint there, and we
119 # don't gracefully fall back to single-stepping.
120 setup_kfail gdb/1736 "i?86-*-linux*"
121 setup_kfail gdb/1736 "*-*-openbsd*"
122 fail "$test (could not set breakpoint)"
125 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
126 setup_kfail gdb/1736 "sparc*-*-openbsd*"
127 fail "$test (could not insert single-step breakpoint)"
129 -re "Breakpoint \[0-9\]*, handler .*${gdb_prompt} $" {
130 fail "$test (hit breakpoint again)"
132 -re "done = 1;.*${gdb_prompt} $" {
134 exp_continue -continue_timer
136 -re "\} .. handler .*${gdb_prompt} $" {
138 exp_continue -continue_timer
140 -re "signal handler called.*${gdb_prompt} $" {
143 -re "main .*${gdb_prompt} $" {
144 fail "$test (in main)"
146 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
147 fail "$test (program exited)"
150 -re "Make handler return now.*y or n. $" {
152 exp_continue -continue_timer
156 set test "$prefix; leave signal trampoline"
157 gdb_test_multiple "$i" "${test}" {
158 -re "while .*${gdb_prompt} $" {
159 pass "$test (in main)"
161 -re "signal handler called.*${gdb_prompt} $" {
163 exp_continue -continue_timer
165 -re "return .*${gdb_prompt} $" {
166 fail "$test (stepped)"
168 -re "Make .*frame return now.*y or n. $" {
170 exp_continue -continue_timer
172 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
173 kfail gdb/1639 "$test (program exited)"
176 -re "The program is not being run.*${gdb_prompt} $" {
177 if { $program_exited } {
178 # Previously kfailed with an exit
179 pass "$test (the program is not being run)"
181 fail "$test (the program is not being run)"
187 # Check that we can step/next our way out of a signal handler.
197 gdb_test_no_output "set done = 1" "Set done as return will have skipped it"
200 # Check that we can step/next our way into / over a signal handler.
202 # There are at least the following cases: breakpoint @pc VS breakpoint
203 # in handler VS step / next / continue.
205 # Use the real-time itimer, as otherwize the process never gets enough
206 # time to expire the timer.
209 set infinite_loop [gdb_get_line_number {while (!done)}]
210 gdb_test_no_output "set itimer = itimer_real"
211 gdb_test "break [gdb_get_line_number {done = 0}]"
213 # Try stepping when there's a signal pending, and a breakpoint at the
214 # handler. Should step into the signal handler.
216 proc skip_to_handler { i } {
219 set prefix "$i to handler"
221 # Run around to the done
222 # You can add more patterns to this if you need them.
223 set test "$prefix; resync"
224 gdb_test_multiple "continue" "$test" {
225 -re "done = 0.*$gdb_prompt " {
230 # Advance to the infinite loop
231 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
233 # Make the signal pending
236 # Insert / remove the handler breakpoint.
237 gdb_test "break handler" ".*" "$prefix; break handler"
238 gdb_test "$i" " handler .*" "$prefix; performing $i"
239 gdb_test "clear handler" ".*" "$prefix; clear handler"
244 skip_to_handler continue
246 # Try stepping when there's a signal pending, and a breakpoint at the
247 # handler's entry-point. Should step into the signal handler stopping
248 # at the entry-point.
250 # Some systems (e.x., GNU/Linux as of 2004-08-30), when delivering a
251 # signal, resume the process at the first instruction of the signal
252 # handler and not the first instruction of the signal trampoline. The
253 # stack is constructed such that the signal handler still appears to
254 # have been called by the trampoline code. This test checks that it
255 # is possible to stop the inferior, even at that first instruction.
257 proc skip_to_handler_entry { i } {
260 set prefix "$i to handler entry"
262 # Run around to the done
263 # You can add more patterns to this if you need them.
264 set test "$prefix; resync"
265 gdb_test_multiple "continue" "$test" {
266 -re "done = 0.*$gdb_prompt " {
271 # Advance to the infinite loop
272 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
274 # Make the signal pending
277 # Insert / remove the handler breakpoint.
278 gdb_test "break *handler" ".*" "$prefix; break handler"
279 gdb_test "$i" " handler .*" "$prefix; performing $i"
280 gdb_test "clear *handler" ".*" "$prefix; clear handler"
283 skip_to_handler_entry step
284 skip_to_handler_entry next
285 skip_to_handler_entry continue
287 # Try stepping when there's a signal pending but no breakpoints.
288 # Should skip the handler advancing to the next line.
290 proc skip_over_handler { i } {
293 set prefix "$i over handler"
295 # Run around to the done
296 # You can add more patterns to this if you need them.
297 set test "$prefix; resync"
298 gdb_test_multiple "continue" "$test" {
299 -re "done = 0.*$gdb_prompt " {
304 # Advance to the infinite loop
305 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
307 # Make the signal pending
310 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
313 skip_over_handler step
314 skip_over_handler next
315 skip_over_handler continue
317 # Try stepping when there's a signal pending, a pre-existing
318 # breakpoint at the current instruction, and a breakpoint in the
319 # handler. Should advance to the signal handler.
321 proc breakpoint_to_handler { i } {
324 set prefix "$i on breakpoint, to handler"
326 # Run around to the done
327 # You can add more patterns to this if you need them.
328 set test "$prefix; resync"
329 gdb_test_multiple "continue" "$test" {
330 -re "done = 0.*$gdb_prompt " {
335 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
336 gdb_test "break handler" ".*" "$prefix; break handler"
338 # Continue to the infinite loop
339 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
341 # Make the signal pending
344 gdb_test "$i" " handler .*" "$prefix; performing $i"
345 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
346 gdb_test "clear handler" ".*" "$prefix; clear handler"
349 breakpoint_to_handler step
350 breakpoint_to_handler next
351 breakpoint_to_handler continue
353 # Try stepping when there's a signal pending, and a breakpoint at the
354 # handler's entry instruction and a breakpoint at the current
355 # instruction. Should step into the signal handler and breakpoint at
356 # that entry instruction.
358 # Some systems (e.x., GNU/Linux as of 2004-08-30), when delivering a
359 # signal, resume the process at the first instruction of the signal
360 # handler and not the first instruction of the signal trampoline. The
361 # stack is constructed such that the signal handler still appears to
362 # have been called by the trampoline code. This test checks that it
363 # is possible to stop the inferior, even at that first instruction.
365 proc breakpoint_to_handler_entry { i } {
368 set prefix "$i on breakpoint, to handler entry"
370 # Run around to the done
371 # You can add more patterns to this if you need them.
372 set test "$prefix; resync"
373 gdb_test_multiple "continue" "$test" {
374 -re "done = 0.*$gdb_prompt " {
379 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
380 gdb_test "break *handler" ".*" "$prefix; break handler"
382 # Continue to the infinite loop
383 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
385 # Make the signal pending
388 gdb_test "$i" " handler .*" "$prefix; performing $i"
389 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
390 gdb_test "clear *handler" ".*" "$prefix; clear handler"
393 breakpoint_to_handler_entry step
394 breakpoint_to_handler_entry next
395 breakpoint_to_handler_entry continue
397 # Try stepping when there's a signal pending, and a pre-existing
398 # breakpoint at the current instruction, and no breakpoint in the
399 # handler. Should advance to the next line.
401 proc breakpoint_over_handler { i } {
404 set prefix "$i on breakpoint, skip handler"
406 # Run around to the done
407 # You can add more patterns to this if you need them.
408 set test "$prefix; resync"
409 gdb_test_multiple "continue" "$test" {
410 -re "done = 0.*$gdb_prompt " {
415 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
417 # Continue to the infinite loop
418 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
420 # Make the signal pending
423 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
424 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
427 breakpoint_over_handler step
428 breakpoint_over_handler next
429 breakpoint_over_handler continue