1 # Copyright 2004, 2005, 2006, 2007, 2008, 2009 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."
37 set srcfile ${testfile}.c
38 set binfile ${objdir}/${subdir}/${testfile}
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40 untested "Couldn't compile ${srcfile}.c"
47 gdb_reinitialize_dir $srcdir/$subdir
50 gdb_test "display/i \$pc"
53 if { ![runto_main] } then {
57 # Pass all the alarms straight through (but verbosely)
58 # gdb_test "handle SIGALRM print pass nostop"
59 # gdb_test "handle SIGVTALRM print pass nostop"
60 # gdb_test "handle SIGPROF print pass nostop"
62 # Run to the signal handler, validate the backtrace.
63 gdb_test "break handler"
64 gdb_test "continue" ".* handler .*" "continue to stepi handler"
66 gdb_expect_list "backtrace for nexti" ".*$gdb_prompt $" {
67 "\[\r\n\]+.0 \[^\r\n\]* handler "
68 "\[\r\n\]+.1 .signal handler called."
69 "\[\r\n\]+.2 \[^\r\n\]* main .*"
74 set prefix "$i from handler"
76 # Get us back into the handler
77 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
79 set test "$prefix; leave handler"
80 gdb_test_multiple "$i" "${test}" {
81 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
82 setup_kfail "sparc*-*-openbsd*" gdb/1736
83 fail "$test (could not insert single-step breakpoint)"
85 -re "done = 1;.*${gdb_prompt} $" {
87 exp_continue -continue_timer
89 -re "\} .. handler .*${gdb_prompt} $" {
91 exp_continue -continue_timer
93 -re "Program exited normally.*${gdb_prompt} $" {
94 setup_kfail powerpc-*-*bsd* gdb/1639
95 fail "$test (program exited)"
97 -re "(while ..done|done = 0).*${gdb_prompt} $" {
98 # After stepping out of a function /r signal-handler, GDB will
99 # advance the inferior until it is at the first instruction of
100 # a code-line. While typically things return to the middle of
101 # the "while..." (and hence GDB advances the inferior to the
102 # "return..." line) it is also possible for the return to land
103 # on the first instruction of "while...". Accept both cases.
109 proc advancei { i } {
111 set prefix "$i from handleri"
114 # Get us back into the handler
115 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
117 set test "$prefix; leave handler"
118 gdb_test_multiple "$i" "${test}" {
119 -re "Cannot insert breakpoint 0.*${gdb_prompt} $" {
120 # Some platforms use a special read-only page for signal
121 # trampolines. We can't set a breakpoint there, and we
122 # don't gracefully fall back to single-stepping.
123 setup_kfail "i?86-*-linux*" gdb/1736
124 setup_kfail "*-*-openbsd*" gdb/1736
125 fail "$test (could not set breakpoint)"
128 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
129 setup_kfail "sparc*-*-openbsd*" gdb/1736
130 fail "$test (could not insert single-step breakpoint)"
132 -re "Breakpoint \[0-9\]*, handler .*${gdb_prompt} $" {
133 fail "$test (hit breakpoint again)"
135 -re "done = 1;.*${gdb_prompt} $" {
137 exp_continue -continue_timer
139 -re "\} .. handler .*${gdb_prompt} $" {
141 exp_continue -continue_timer
143 -re "signal handler called.*${gdb_prompt} $" {
146 -re "main .*${gdb_prompt} $" {
147 fail "$test (in main)"
149 -re "Program exited normally.*${gdb_prompt} $" {
150 fail "$test (program exited)"
153 -re "Make handler return now.*y or n. $" {
155 exp_continue -continue_timer
159 set test "$prefix; leave signal trampoline"
160 gdb_test_multiple "$i" "${test}" {
161 -re "while .*${gdb_prompt} $" {
162 pass "$test (in main)"
164 -re "signal handler called.*${gdb_prompt} $" {
166 exp_continue -continue_timer
168 -re "return .*${gdb_prompt} $" {
169 fail "$test (stepped)"
171 -re "Make .*frame return now.*y or n. $" {
173 exp_continue -continue_timer
175 -re "Program exited normally.*${gdb_prompt} $" {
176 kfail gdb/1639 "$test (program exited)"
179 -re "The program is not being run.*${gdb_prompt} $" {
180 if { $program_exited } {
181 # Previously kfailed with an exit
182 pass "$test (the program is not being run)"
184 fail "$test (the program is not being run)"
190 # Check that we can step/next our way out of a signal handler.
200 gdb_test "set done = 1" "" "Set done as return will have skipped it"
203 # Check that we can step/next our way into / over a signal handler.
205 # There are at least the following cases: breakpoint @pc VS breakpoint
206 # in handler VS step / next / continue.
208 # Use the real-time itimer, as otherwize the process never gets enough
209 # time to expire the timer.
212 set infinite_loop [gdb_get_line_number {while (!done)}]
213 gdb_test "set itimer = itimer_real"
214 gdb_test "break [gdb_get_line_number {done = 0}]"
216 # Try stepping when there's a signal pending, and a breakpoint at the
217 # handler. Should step into the signal handler.
219 proc skip_to_handler { i } {
222 set prefix "$i to handler"
224 # Run around to the done
225 # You can add more patterns to this if you need them.
226 set test "$prefix; resync"
227 gdb_test_multiple "continue" "$test" {
228 -re "done = 0.*$gdb_prompt " {
233 # Advance to the infinite loop
234 gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
236 # Make the signal pending
239 # Insert / remove the handler breakpoint.
240 gdb_test "break handler" "" "$prefix; break handler"
241 gdb_test "$i" " handler .*" "$prefix; performing $i"
242 gdb_test "clear handler" "" "$prefix; clear handler"
247 skip_to_handler continue
249 # Try stepping when there's a signal pending, and a breakpoint at the
250 # handler's entry-point. Should step into the signal handler stopping
251 # at the entry-point.
253 # Some systems (e.x., GNU/Linux as of 2004-08-30), when delivering a
254 # signal, resume the process at the first instruction of the signal
255 # handler and not the first instruction of the signal trampoline. The
256 # stack is constructed such that the signal handler still appears to
257 # have been called by the trampoline code. This test checks that it
258 # is possible to stop the inferior, even at that first instruction.
260 proc skip_to_handler_entry { i } {
263 set prefix "$i to handler entry"
265 # Run around to the done
266 # You can add more patterns to this if you need them.
267 set test "$prefix; resync"
268 gdb_test_multiple "continue" "$test" {
269 -re "done = 0.*$gdb_prompt " {
274 # Advance to the infinite loop
275 gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
277 # Make the signal pending
280 # Insert / remove the handler breakpoint.
281 gdb_test "break *handler" "" "$prefix; break handler"
282 gdb_test "$i" " handler .*" "$prefix; performing $i"
283 gdb_test "clear *handler" "" "$prefix; clear handler"
286 skip_to_handler_entry step
287 skip_to_handler_entry next
288 skip_to_handler_entry continue
290 # Try stepping when there's a signal pending but no breakpoints.
291 # Should skip the handler advancing to the next line.
293 proc skip_over_handler { i } {
296 set prefix "$i over handler"
298 # Run around to the done
299 # You can add more patterns to this if you need them.
300 set test "$prefix; resync"
301 gdb_test_multiple "continue" "$test" {
302 -re "done = 0.*$gdb_prompt " {
307 # Advance to the infinite loop
308 gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
310 # Make the signal pending
313 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
316 skip_over_handler step
317 skip_over_handler next
318 skip_over_handler continue
320 # Try stepping when there's a signal pending, a pre-existing
321 # breakpoint at the current instruction, and a breakpoint in the
322 # handler. Should advance to the signal handler.
324 proc breakpoint_to_handler { i } {
327 set prefix "$i on breakpoint, to handler"
329 # Run around to the done
330 # You can add more patterns to this if you need them.
331 set test "$prefix; resync"
332 gdb_test_multiple "continue" "$test" {
333 -re "done = 0.*$gdb_prompt " {
338 gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
339 gdb_test "break handler" "" "$prefix; break handler"
341 # Continue to the infinite loop
342 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
344 # Make the signal pending
347 gdb_test "$i" " handler .*" "$prefix; performing $i"
348 gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
349 gdb_test "clear handler" "" "$prefix; clear handler"
352 breakpoint_to_handler step
353 breakpoint_to_handler next
354 breakpoint_to_handler continue
356 # Try stepping when there's a signal pending, and a breakpoint at the
357 # handler's entry instruction and a breakpoint at the current
358 # instruction. Should step into the signal handler and breakpoint at
359 # that entry instruction.
361 # Some systems (e.x., GNU/Linux as of 2004-08-30), when delivering a
362 # signal, resume the process at the first instruction of the signal
363 # handler and not the first instruction of the signal trampoline. The
364 # stack is constructed such that the signal handler still appears to
365 # have been called by the trampoline code. This test checks that it
366 # is possible to stop the inferior, even at that first instruction.
368 proc breakpoint_to_handler_entry { i } {
371 set prefix "$i on breakpoint, to handler entry"
373 # Run around to the done
374 # You can add more patterns to this if you need them.
375 set test "$prefix; resync"
376 gdb_test_multiple "continue" "$test" {
377 -re "done = 0.*$gdb_prompt " {
382 gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
383 gdb_test "break *handler" "" "$prefix; break handler"
385 # Continue to the infinite loop
386 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
388 # Make the signal pending
391 gdb_test "$i" " handler .*" "$prefix; performing $i"
392 gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
393 gdb_test "clear *handler" "" "$prefix; clear handler"
396 breakpoint_to_handler_entry step
397 breakpoint_to_handler_entry next
398 breakpoint_to_handler_entry continue
400 # Try stepping when there's a signal pending, and a pre-existing
401 # breakpoint at the current instruction, and no breakpoint in the
402 # handler. Should advance to the next line.
404 proc breakpoint_over_handler { i } {
407 set prefix "$i on breakpoint, skip handler"
409 # Run around to the done
410 # You can add more patterns to this if you need them.
411 set test "$prefix; resync"
412 gdb_test_multiple "continue" "$test" {
413 -re "done = 0.*$gdb_prompt " {
418 gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
420 # Continue to the infinite loop
421 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
423 # Make the signal pending
426 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
427 gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
430 breakpoint_over_handler step
431 breakpoint_over_handler next
432 breakpoint_over_handler continue