1 # Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010
2 # Free Software Foundation, Inc.
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.
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.
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/>.
18 # The program sigstep.c creates a very simple backtrace containing one
19 # signal handler and signal trampoline. A flag is set and then the
20 # handler returns. This is repeated at infinitum.
22 # This test runs the program up to the signal handler, and then
23 # attempts to step/next out of the handler and back into main.
25 if [target_info exists gdb,nosignals] {
26 verbose "Skipping sigstep.exp because of nosignals."
36 set srcfile ${testfile}.c
37 set binfile ${objdir}/${subdir}/${testfile}
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
39 untested "Couldn't compile ${srcfile}.c"
46 gdb_reinitialize_dir $srcdir/$subdir
49 gdb_test "display/i \$pc"
52 if { ![runto_main] } then {
56 # Pass all the alarms straight through (but verbosely)
57 # gdb_test "handle SIGALRM print pass nostop"
58 # gdb_test "handle SIGVTALRM print pass nostop"
59 # gdb_test "handle SIGPROF print pass nostop"
61 # Run to the signal handler, validate the backtrace.
62 gdb_test "break handler"
63 gdb_test "continue" ".* handler .*" "continue to stepi handler"
65 gdb_expect_list "backtrace for nexti" ".*$gdb_prompt $" {
66 "\[\r\n\]+.0 \[^\r\n\]* handler "
67 "\[\r\n\]+.1 .signal handler called."
68 "\[\r\n\]+.2 \[^\r\n\]* main .*"
73 set prefix "$i from handler"
75 # Get us back into the handler
76 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
78 set test "$prefix; leave handler"
79 gdb_test_multiple "$i" "${test}" {
80 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
81 setup_kfail gdb/1736 "sparc*-*-openbsd*"
82 fail "$test (could not insert single-step breakpoint)"
84 -re "done = 1;.*${gdb_prompt} $" {
86 exp_continue -continue_timer
88 -re "\} .. handler .*${gdb_prompt} $" {
90 exp_continue -continue_timer
92 -re "Program exited normally.*${gdb_prompt} $" {
93 setup_kfail gdb/1639 powerpc-*-*bsd*
94 fail "$test (program exited)"
96 -re "(while ..done|done = 0).*${gdb_prompt} $" {
97 # After stepping out of a function /r signal-handler, GDB will
98 # advance the inferior until it is at the first instruction of
99 # a code-line. While typically things return to the middle of
100 # the "while..." (and hence GDB advances the inferior to the
101 # "return..." line) it is also possible for the return to land
102 # on the first instruction of "while...". Accept both cases.
108 proc advancei { i } {
110 set prefix "$i from handleri"
113 # Get us back into the handler
114 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
116 set test "$prefix; leave handler"
117 gdb_test_multiple "$i" "${test}" {
118 -re "Cannot insert breakpoint 0.*${gdb_prompt} $" {
119 # Some platforms use a special read-only page for signal
120 # trampolines. We can't set a breakpoint there, and we
121 # don't gracefully fall back to single-stepping.
122 setup_kfail gdb/1736 "i?86-*-linux*"
123 setup_kfail gdb/1736 "*-*-openbsd*"
124 fail "$test (could not set breakpoint)"
127 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
128 setup_kfail gdb/1736 "sparc*-*-openbsd*"
129 fail "$test (could not insert single-step breakpoint)"
131 -re "Breakpoint \[0-9\]*, handler .*${gdb_prompt} $" {
132 fail "$test (hit breakpoint again)"
134 -re "done = 1;.*${gdb_prompt} $" {
136 exp_continue -continue_timer
138 -re "\} .. handler .*${gdb_prompt} $" {
140 exp_continue -continue_timer
142 -re "signal handler called.*${gdb_prompt} $" {
145 -re "main .*${gdb_prompt} $" {
146 fail "$test (in main)"
148 -re "Program exited normally.*${gdb_prompt} $" {
149 fail "$test (program exited)"
152 -re "Make handler return now.*y or n. $" {
154 exp_continue -continue_timer
158 set test "$prefix; leave signal trampoline"
159 gdb_test_multiple "$i" "${test}" {
160 -re "while .*${gdb_prompt} $" {
161 pass "$test (in main)"
163 -re "signal handler called.*${gdb_prompt} $" {
165 exp_continue -continue_timer
167 -re "return .*${gdb_prompt} $" {
168 fail "$test (stepped)"
170 -re "Make .*frame return now.*y or n. $" {
172 exp_continue -continue_timer
174 -re "Program exited normally.*${gdb_prompt} $" {
175 kfail gdb/1639 "$test (program exited)"
178 -re "The program is not being run.*${gdb_prompt} $" {
179 if { $program_exited } {
180 # Previously kfailed with an exit
181 pass "$test (the program is not being run)"
183 fail "$test (the program is not being run)"
189 # Check that we can step/next our way out of a signal handler.
199 gdb_test "set done = 1" "" "Set done as return will have skipped it"
202 # Check that we can step/next our way into / over a signal handler.
204 # There are at least the following cases: breakpoint @pc VS breakpoint
205 # in handler VS step / next / continue.
207 # Use the real-time itimer, as otherwize the process never gets enough
208 # time to expire the timer.
211 set infinite_loop [gdb_get_line_number {while (!done)}]
212 gdb_test "set itimer = itimer_real"
213 gdb_test "break [gdb_get_line_number {done = 0}]"
215 # Try stepping when there's a signal pending, and a breakpoint at the
216 # handler. Should step into the signal handler.
218 proc skip_to_handler { i } {
221 set prefix "$i to handler"
223 # Run around to the done
224 # You can add more patterns to this if you need them.
225 set test "$prefix; resync"
226 gdb_test_multiple "continue" "$test" {
227 -re "done = 0.*$gdb_prompt " {
232 # Advance to the infinite loop
233 gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
235 # Make the signal pending
238 # Insert / remove the handler breakpoint.
239 gdb_test "break handler" "" "$prefix; break handler"
240 gdb_test "$i" " handler .*" "$prefix; performing $i"
241 gdb_test "clear handler" "" "$prefix; clear handler"
246 skip_to_handler continue
248 # Try stepping when there's a signal pending, and a breakpoint at the
249 # handler's entry-point. Should step into the signal handler stopping
250 # at the entry-point.
252 # Some systems (e.x., GNU/Linux as of 2004-08-30), when delivering a
253 # signal, resume the process at the first instruction of the signal
254 # handler and not the first instruction of the signal trampoline. The
255 # stack is constructed such that the signal handler still appears to
256 # have been called by the trampoline code. This test checks that it
257 # is possible to stop the inferior, even at that first instruction.
259 proc skip_to_handler_entry { i } {
262 set prefix "$i to handler entry"
264 # Run around to the done
265 # You can add more patterns to this if you need them.
266 set test "$prefix; resync"
267 gdb_test_multiple "continue" "$test" {
268 -re "done = 0.*$gdb_prompt " {
273 # Advance to the infinite loop
274 gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
276 # Make the signal pending
279 # Insert / remove the handler breakpoint.
280 gdb_test "break *handler" "" "$prefix; break handler"
281 gdb_test "$i" " handler .*" "$prefix; performing $i"
282 gdb_test "clear *handler" "" "$prefix; clear handler"
285 skip_to_handler_entry step
286 skip_to_handler_entry next
287 skip_to_handler_entry continue
289 # Try stepping when there's a signal pending but no breakpoints.
290 # Should skip the handler advancing to the next line.
292 proc skip_over_handler { i } {
295 set prefix "$i over handler"
297 # Run around to the done
298 # You can add more patterns to this if you need them.
299 set test "$prefix; resync"
300 gdb_test_multiple "continue" "$test" {
301 -re "done = 0.*$gdb_prompt " {
306 # Advance to the infinite loop
307 gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
309 # Make the signal pending
312 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
315 skip_over_handler step
316 skip_over_handler next
317 skip_over_handler continue
319 # Try stepping when there's a signal pending, a pre-existing
320 # breakpoint at the current instruction, and a breakpoint in the
321 # handler. Should advance to the signal handler.
323 proc breakpoint_to_handler { i } {
326 set prefix "$i on breakpoint, to handler"
328 # Run around to the done
329 # You can add more patterns to this if you need them.
330 set test "$prefix; resync"
331 gdb_test_multiple "continue" "$test" {
332 -re "done = 0.*$gdb_prompt " {
337 gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
338 gdb_test "break handler" "" "$prefix; break handler"
340 # Continue to the infinite loop
341 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
343 # Make the signal pending
346 gdb_test "$i" " handler .*" "$prefix; performing $i"
347 gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
348 gdb_test "clear handler" "" "$prefix; clear handler"
351 breakpoint_to_handler step
352 breakpoint_to_handler next
353 breakpoint_to_handler continue
355 # Try stepping when there's a signal pending, and a breakpoint at the
356 # handler's entry instruction and a breakpoint at the current
357 # instruction. Should step into the signal handler and breakpoint at
358 # that entry instruction.
360 # Some systems (e.x., GNU/Linux as of 2004-08-30), when delivering a
361 # signal, resume the process at the first instruction of the signal
362 # handler and not the first instruction of the signal trampoline. The
363 # stack is constructed such that the signal handler still appears to
364 # have been called by the trampoline code. This test checks that it
365 # is possible to stop the inferior, even at that first instruction.
367 proc breakpoint_to_handler_entry { i } {
370 set prefix "$i on breakpoint, to handler entry"
372 # Run around to the done
373 # You can add more patterns to this if you need them.
374 set test "$prefix; resync"
375 gdb_test_multiple "continue" "$test" {
376 -re "done = 0.*$gdb_prompt " {
381 gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
382 gdb_test "break *handler" "" "$prefix; break handler"
384 # Continue to the infinite loop
385 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
387 # Make the signal pending
390 gdb_test "$i" " handler .*" "$prefix; performing $i"
391 gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
392 gdb_test "clear *handler" "" "$prefix; clear handler"
395 breakpoint_to_handler_entry step
396 breakpoint_to_handler_entry next
397 breakpoint_to_handler_entry continue
399 # Try stepping when there's a signal pending, and a pre-existing
400 # breakpoint at the current instruction, and no breakpoint in the
401 # handler. Should advance to the next line.
403 proc breakpoint_over_handler { i } {
406 set prefix "$i on breakpoint, skip handler"
408 # Run around to the done
409 # You can add more patterns to this if you need them.
410 set test "$prefix; resync"
411 gdb_test_multiple "continue" "$test" {
412 -re "done = 0.*$gdb_prompt " {
417 gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
419 # Continue to the infinite loop
420 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
422 # Make the signal pending
425 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
426 gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
429 breakpoint_over_handler step
430 breakpoint_over_handler next
431 breakpoint_over_handler continue