1 # Copyright 2004-2013 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."
32 if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
33 untested $testfile.exp
37 gdb_test "display/i \$pc"
40 if { ![runto_main] } then {
44 # Pass all the alarms straight through (but verbosely)
45 # gdb_test "handle SIGALRM print pass nostop"
46 # gdb_test "handle SIGVTALRM print pass nostop"
47 # gdb_test "handle SIGPROF print pass nostop"
49 # Run to the signal handler, validate the backtrace.
50 gdb_test "break handler"
51 gdb_test "continue" ".* handler .*" "continue to stepi handler"
52 gdb_test_sequence "bt" "backtrace for nexti" {
53 "\[\r\n\]+.0 \[^\r\n\]* handler "
54 "\[\r\n\]+.1 .signal handler called."
55 "\[\r\n\]+.2 \[^\r\n\]* main "
59 global gdb_prompt inferior_exited_re
60 set prefix "$i from handler"
62 # Get us back into the handler
63 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
65 set test "$prefix; leave handler"
66 gdb_test_multiple "$i" "${test}" {
67 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
68 setup_kfail gdb/1736 "sparc*-*-openbsd*"
69 fail "$test (could not insert single-step breakpoint)"
71 -re "done = 1;.*${gdb_prompt} $" {
73 exp_continue -continue_timer
75 -re "\} .. handler .*${gdb_prompt} $" {
77 exp_continue -continue_timer
79 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
80 setup_kfail gdb/1639 powerpc-*-*bsd*
81 fail "$test (program exited)"
83 -re "(while ..done|done = 0).*${gdb_prompt} $" {
84 # After stepping out of a function /r signal-handler, GDB will
85 # advance the inferior until it is at the first instruction of
86 # a code-line. While typically things return to the middle of
87 # the "while..." (and hence GDB advances the inferior to the
88 # "return..." line) it is also possible for the return to land
89 # on the first instruction of "while...". Accept both cases.
96 global gdb_prompt inferior_exited_re
97 set prefix "$i from handleri"
100 # Get us back into the handler
101 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
103 set test "$prefix; leave handler"
104 gdb_test_multiple "$i" "${test}" {
105 -re "Cannot insert breakpoint 0.*${gdb_prompt} $" {
106 # Some platforms use a special read-only page for signal
107 # trampolines. We can't set a breakpoint there, and we
108 # don't gracefully fall back to single-stepping.
109 setup_kfail gdb/1736 "i?86-*-linux*"
110 setup_kfail gdb/1736 "*-*-openbsd*"
111 fail "$test (could not set breakpoint)"
114 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
115 setup_kfail gdb/1736 "sparc*-*-openbsd*"
116 fail "$test (could not insert single-step breakpoint)"
118 -re "Breakpoint \[0-9\]*, handler .*${gdb_prompt} $" {
119 fail "$test (hit breakpoint again)"
121 -re "done = 1;.*${gdb_prompt} $" {
123 exp_continue -continue_timer
125 -re "\} .. handler .*${gdb_prompt} $" {
127 exp_continue -continue_timer
129 -re "signal handler called.*${gdb_prompt} $" {
132 -re "main .*${gdb_prompt} $" {
133 fail "$test (in main)"
135 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
136 fail "$test (program exited)"
139 -re "Make handler return now.*y or n. $" {
141 exp_continue -continue_timer
145 set test "$prefix; leave signal trampoline"
146 gdb_test_multiple "$i" "${test}" {
147 -re "while .*${gdb_prompt} $" {
148 pass "$test (in main)"
150 -re "signal handler called.*${gdb_prompt} $" {
152 exp_continue -continue_timer
154 -re "return .*${gdb_prompt} $" {
155 fail "$test (stepped)"
157 -re "Make .*frame return now.*y or n. $" {
159 exp_continue -continue_timer
161 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
162 kfail gdb/1639 "$test (program exited)"
165 -re "The program is not being run.*${gdb_prompt} $" {
166 if { $program_exited } {
167 # Previously kfailed with an exit
168 pass "$test (the program is not being run)"
170 fail "$test (the program is not being run)"
176 # Check that we can step/next our way out of a signal handler.
186 gdb_test_no_output "set done = 1" "Set done as return will have skipped it"
189 # Check that we can step/next our way into / over a signal handler.
191 # There are at least the following cases: breakpoint @pc VS breakpoint
192 # in handler VS step / next / continue.
194 # Use the real-time itimer, as otherwize the process never gets enough
195 # time to expire the timer.
198 set infinite_loop [gdb_get_line_number {while (!done)}]
199 gdb_test_no_output "set itimer = itimer_real"
200 gdb_test "break [gdb_get_line_number {done = 0}]"
202 # Try stepping when there's a signal pending, and a breakpoint at the
203 # handler. Should step into the signal handler.
205 proc skip_to_handler { i } {
208 set prefix "$i to handler"
210 # Run around to the done
211 # You can add more patterns to this if you need them.
212 set test "$prefix; resync"
213 gdb_test_multiple "continue" "$test" {
214 -re "done = 0.*$gdb_prompt " {
219 # Advance to the infinite loop
220 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
222 # Make the signal pending
225 # Insert / remove the handler breakpoint.
226 gdb_test "break handler" ".*" "$prefix; break handler"
227 gdb_test "$i" " handler .*" "$prefix; performing $i"
228 gdb_test "clear handler" ".*" "$prefix; clear handler"
233 skip_to_handler continue
235 # Try stepping when there's a signal pending, and a breakpoint at the
236 # handler's entry-point. Should step into the signal handler stopping
237 # at the entry-point.
239 # Some systems (e.x., GNU/Linux as of 2004-08-30), when delivering a
240 # signal, resume the process at the first instruction of the signal
241 # handler and not the first instruction of the signal trampoline. The
242 # stack is constructed such that the signal handler still appears to
243 # have been called by the trampoline code. This test checks that it
244 # is possible to stop the inferior, even at that first instruction.
246 proc skip_to_handler_entry { i } {
249 set prefix "$i to handler entry"
251 # Run around to the done
252 # You can add more patterns to this if you need them.
253 set test "$prefix; resync"
254 gdb_test_multiple "continue" "$test" {
255 -re "done = 0.*$gdb_prompt " {
260 # Advance to the infinite loop
261 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
263 # Make the signal pending
266 # Insert / remove the handler breakpoint.
267 gdb_test "break *handler" ".*" "$prefix; break handler"
268 gdb_test "$i" " handler .*" "$prefix; performing $i"
269 gdb_test "clear *handler" ".*" "$prefix; clear handler"
272 skip_to_handler_entry step
273 skip_to_handler_entry next
274 skip_to_handler_entry continue
276 # Try stepping when there's a signal pending but no breakpoints.
277 # Should skip the handler advancing to the next line.
279 proc skip_over_handler { i } {
282 set prefix "$i over handler"
284 # Run around to the done
285 # You can add more patterns to this if you need them.
286 set test "$prefix; resync"
287 gdb_test_multiple "continue" "$test" {
288 -re "done = 0.*$gdb_prompt " {
293 # Advance to the infinite loop
294 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
296 # Make the signal pending
299 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
302 skip_over_handler step
303 skip_over_handler next
304 skip_over_handler continue
306 # Try stepping when there's a signal pending, a pre-existing
307 # breakpoint at the current instruction, and a breakpoint in the
308 # handler. Should advance to the signal handler.
310 proc breakpoint_to_handler { i } {
313 set prefix "$i on breakpoint, to handler"
315 # Run around to the done
316 # You can add more patterns to this if you need them.
317 set test "$prefix; resync"
318 gdb_test_multiple "continue" "$test" {
319 -re "done = 0.*$gdb_prompt " {
324 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
325 gdb_test "break handler" ".*" "$prefix; break handler"
327 # Continue to the infinite loop
328 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
330 # Make the signal pending
333 gdb_test "$i" " handler .*" "$prefix; performing $i"
334 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
335 gdb_test "clear handler" ".*" "$prefix; clear handler"
338 breakpoint_to_handler step
339 breakpoint_to_handler next
340 breakpoint_to_handler continue
342 # Try stepping when there's a signal pending, and a breakpoint at the
343 # handler's entry instruction and a breakpoint at the current
344 # instruction. Should step into the signal handler and breakpoint at
345 # that entry instruction.
347 # Some systems (e.x., GNU/Linux as of 2004-08-30), when delivering a
348 # signal, resume the process at the first instruction of the signal
349 # handler and not the first instruction of the signal trampoline. The
350 # stack is constructed such that the signal handler still appears to
351 # have been called by the trampoline code. This test checks that it
352 # is possible to stop the inferior, even at that first instruction.
354 proc breakpoint_to_handler_entry { i } {
357 set prefix "$i on breakpoint, to handler entry"
359 # Run around to the done
360 # You can add more patterns to this if you need them.
361 set test "$prefix; resync"
362 gdb_test_multiple "continue" "$test" {
363 -re "done = 0.*$gdb_prompt " {
368 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
369 gdb_test "break *handler" ".*" "$prefix; break handler"
371 # Continue to the infinite loop
372 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
374 # Make the signal pending
377 gdb_test "$i" " handler .*" "$prefix; performing $i"
378 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
379 gdb_test "clear *handler" ".*" "$prefix; clear handler"
382 breakpoint_to_handler_entry step
383 breakpoint_to_handler_entry next
384 breakpoint_to_handler_entry continue
386 # Try stepping when there's a signal pending, and a pre-existing
387 # breakpoint at the current instruction, and no breakpoint in the
388 # handler. Should advance to the next line.
390 proc breakpoint_over_handler { i } {
393 set prefix "$i on breakpoint, skip handler"
395 # Run around to the done
396 # You can add more patterns to this if you need them.
397 set test "$prefix; resync"
398 gdb_test_multiple "continue" "$test" {
399 -re "done = 0.*$gdb_prompt " {
404 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
406 # Continue to the infinite loop
407 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
409 # Make the signal pending
412 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
413 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
416 breakpoint_over_handler step
417 breakpoint_over_handler next
418 breakpoint_over_handler continue