update bug numbers (GNATS -> Bugzilla) in a few signal related tests
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / sigstep.exp
CommitLineData
ecd75fc8 1# Copyright 2004-2014 Free Software Foundation, Inc.
f0fd9238
AC
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
f0fd9238 6# (at your option) any later version.
e22f8b7c 7#
f0fd9238
AC
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#
f0fd9238 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/>.
f0fd9238
AC
15
16
17# The program sigstep.c creates a very simple backtrace containing one
b04e311d
AC
18# signal handler and signal trampoline. A flag is set and then the
19# handler returns. This is repeated at infinitum.
f0fd9238
AC
20
21# This test runs the program up to the signal handler, and then
b04e311d 22# attempts to step/next out of the handler and back into main.
f0fd9238
AC
23
24if [target_info exists gdb,nosignals] {
25 verbose "Skipping sigstep.exp because of nosignals."
26 continue
27}
28
f0fd9238 29
0ab77f5f
TT
30standard_testfile
31
32if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
33 untested $testfile.exp
f0fd9238
AC
34 return -1
35}
36
f0fd9238
AC
37gdb_test "display/i \$pc"
38
39# Advance to main
40if { ![runto_main] } then {
4ec70201 41 gdb_suppress_tests
f0fd9238
AC
42}
43
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"
48
49# Run to the signal handler, validate the backtrace.
50gdb_test "break handler"
51gdb_test "continue" ".* handler .*" "continue to stepi handler"
5fa290c1 52gdb_test_sequence "bt" "backtrace for nexti" {
f0fd9238
AC
53 "\[\r\n\]+.0 \[^\r\n\]* handler "
54 "\[\r\n\]+.1 .signal handler called."
5fa290c1 55 "\[\r\n\]+.2 \[^\r\n\]* main "
f0fd9238
AC
56}
57
58proc advance { i } {
fda326dd 59 global gdb_prompt inferior_exited_re
b04e311d 60 set prefix "$i from handler"
f0fd9238
AC
61
62 # Get us back into the handler
b04e311d 63 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
f0fd9238 64
b04e311d 65 set test "$prefix; leave handler"
f0fd9238 66 gdb_test_multiple "$i" "${test}" {
8608915f 67 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
a5b6e449 68 setup_kfail gdb/8841 "sparc*-*-openbsd*"
8608915f
MK
69 fail "$test (could not insert single-step breakpoint)"
70 }
f0fd9238
AC
71 -re "done = 1;.*${gdb_prompt} $" {
72 send_gdb "$i\n"
714e341b 73 exp_continue -continue_timer
f0fd9238
AC
74 }
75 -re "\} .. handler .*${gdb_prompt} $" {
76 send_gdb "$i\n"
714e341b 77 exp_continue -continue_timer
f0fd9238 78 }
fda326dd 79 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
a5b6e449 80 setup_kfail gdb/8744 powerpc-*-*bsd*
42edda50 81 fail "$test (program exited)"
61bcae62 82 }
b04e311d 83 -re "(while ..done|done = 0).*${gdb_prompt} $" {
61bcae62
AC
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.
f0fd9238
AC
90 pass "$test"
91 }
92 }
93}
94
95proc advancei { i } {
fda326dd 96 global gdb_prompt inferior_exited_re
b04e311d 97 set prefix "$i from handleri"
f0fd9238
AC
98 set program_exited 0
99
100 # Get us back into the handler
b04e311d 101 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
f0fd9238 102
b04e311d 103 set test "$prefix; leave handler"
f0fd9238 104 gdb_test_multiple "$i" "${test}" {
04f6ecf2
DJ
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.
a5b6e449
PA
109 setup_kfail gdb/8841 "i?86-*-linux*"
110 setup_kfail gdb/8841 "*-*-openbsd*"
04f6ecf2
DJ
111 fail "$test (could not set breakpoint)"
112 return
113 }
8608915f 114 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
a5b6e449 115 setup_kfail gdb/8841 "sparc*-*-openbsd*"
8608915f
MK
116 fail "$test (could not insert single-step breakpoint)"
117 }
2fa63963
DJ
118 -re "Breakpoint \[0-9\]*, handler .*${gdb_prompt} $" {
119 fail "$test (hit breakpoint again)"
120 }
f0fd9238
AC
121 -re "done = 1;.*${gdb_prompt} $" {
122 send_gdb "$i\n"
714e341b 123 exp_continue -continue_timer
f0fd9238
AC
124 }
125 -re "\} .. handler .*${gdb_prompt} $" {
126 send_gdb "$i\n"
714e341b 127 exp_continue -continue_timer
f0fd9238
AC
128 }
129 -re "signal handler called.*${gdb_prompt} $" {
130 pass "$test"
131 }
f0fd9238
AC
132 -re "main .*${gdb_prompt} $" {
133 fail "$test (in main)"
134 }
fda326dd 135 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
42edda50
AC
136 fail "$test (program exited)"
137 set program_exited 1
138 }
f0fd9238
AC
139 -re "Make handler return now.*y or n. $" {
140 send_gdb "y\n"
714e341b 141 exp_continue -continue_timer
f0fd9238
AC
142 }
143 }
144
b04e311d 145 set test "$prefix; leave signal trampoline"
f0fd9238
AC
146 gdb_test_multiple "$i" "${test}" {
147 -re "while .*${gdb_prompt} $" {
148 pass "$test (in main)"
149 }
150 -re "signal handler called.*${gdb_prompt} $" {
151 send_gdb "$i\n"
714e341b 152 exp_continue -continue_timer
f0fd9238
AC
153 }
154 -re "return .*${gdb_prompt} $" {
155 fail "$test (stepped)"
156 }
157 -re "Make .*frame return now.*y or n. $" {
158 send_gdb "y\n"
714e341b 159 exp_continue -continue_timer
f0fd9238 160 }
fda326dd 161 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
a5b6e449 162 kfail gdb/8744 "$test (program exited)"
42edda50
AC
163 set program_exited 1
164 }
f0fd9238
AC
165 -re "The program is not being run.*${gdb_prompt} $" {
166 if { $program_exited } {
167 # Previously kfailed with an exit
42edda50 168 pass "$test (the program is not being run)"
f0fd9238 169 } else {
42edda50 170 fail "$test (the program is not being run)"
f0fd9238
AC
171 }
172 }
173 }
174}
175
b04e311d
AC
176# Check that we can step/next our way out of a signal handler.
177
f0fd9238
AC
178advance step
179advancei stepi
180
181advance next
182advancei nexti
183
184advancei finish
185advancei return
27d3a1a2 186gdb_test_no_output "set done = 1" "Set done as return will have skipped it"
b04e311d
AC
187
188
189# Check that we can step/next our way into / over a signal handler.
190
191# There are at least the following cases: breakpoint @pc VS breakpoint
192# in handler VS step / next / continue.
193
194# Use the real-time itimer, as otherwize the process never gets enough
195# time to expire the timer.
196
197delete_breakpoints
198set infinite_loop [gdb_get_line_number {while (!done)}]
27d3a1a2 199gdb_test_no_output "set itimer = itimer_real"
b04e311d
AC
200gdb_test "break [gdb_get_line_number {done = 0}]"
201
202# Try stepping when there's a signal pending, and a breakpoint at the
203# handler. Should step into the signal handler.
204
205proc skip_to_handler { i } {
206 global gdb_prompt
207 global infinite_loop
208 set prefix "$i to handler"
209
210 # Run around to the done
60fe1a51 211 # You can add more patterns to this if you need them.
b04e311d
AC
212 set test "$prefix; resync"
213 gdb_test_multiple "continue" "$test" {
214 -re "done = 0.*$gdb_prompt " {
215 pass "$test"
216 }
b04e311d
AC
217 }
218
219 # Advance to the infinite loop
27d3a1a2 220 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
b04e311d
AC
221
222 # Make the signal pending
223 sleep 1
224
225 # Insert / remove the handler breakpoint.
27d3a1a2 226 gdb_test "break handler" ".*" "$prefix; break handler"
b04e311d 227 gdb_test "$i" " handler .*" "$prefix; performing $i"
27d3a1a2 228 gdb_test "clear handler" ".*" "$prefix; clear handler"
b04e311d
AC
229}
230
231skip_to_handler step
232skip_to_handler next
233skip_to_handler continue
234
2dedb159
AC
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.
238
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.
245
246proc skip_to_handler_entry { i } {
247 global gdb_prompt
248 global infinite_loop
249 set prefix "$i to handler entry"
250
251 # Run around to the done
60fe1a51 252 # You can add more patterns to this if you need them.
2dedb159
AC
253 set test "$prefix; resync"
254 gdb_test_multiple "continue" "$test" {
255 -re "done = 0.*$gdb_prompt " {
256 pass "$test"
257 }
2dedb159
AC
258 }
259
260 # Advance to the infinite loop
27d3a1a2 261 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
2dedb159
AC
262
263 # Make the signal pending
264 sleep 1
265
266 # Insert / remove the handler breakpoint.
27d3a1a2 267 gdb_test "break *handler" ".*" "$prefix; break handler"
2dedb159 268 gdb_test "$i" " handler .*" "$prefix; performing $i"
27d3a1a2 269 gdb_test "clear *handler" ".*" "$prefix; clear handler"
2dedb159
AC
270}
271
e5f8a7cc
PA
272foreach cmd {"stepi" "nexti" "step" "next" "continue"} {
273 skip_to_handler_entry $cmd
274}
275
276# Get the address of where a single-step should land.
277
278proc get_next_pc {test} {
279 global gdb_prompt
280 global hex
281
282 set next ""
283 gdb_test_multiple "x/2i \$pc" $test {
284 -re "$hex .*:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
285 set next $expect_out(1,string)
286 pass $test
287 }
288 }
289
290 return $next
291}
292
293# Test that the command skipped over the handler.
294
295proc test_skip_handler {prefix i} {
296 if {$i == "stepi" || $i == "nexti"} {
297 set next_pc [get_next_pc "$prefix; get next PC"]
298 gdb_test "$i" "dummy = 0.*" "$prefix; performing $i"
299 gdb_test "p /x \$pc" " = $next_pc" "$prefix; advanced"
300 } else {
301 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
302 }
303}
2dedb159 304
b04e311d
AC
305# Try stepping when there's a signal pending but no breakpoints.
306# Should skip the handler advancing to the next line.
307
308proc skip_over_handler { i } {
309 global gdb_prompt
310 global infinite_loop
311 set prefix "$i over handler"
312
313 # Run around to the done
60fe1a51 314 # You can add more patterns to this if you need them.
b04e311d
AC
315 set test "$prefix; resync"
316 gdb_test_multiple "continue" "$test" {
317 -re "done = 0.*$gdb_prompt " {
318 pass "$test"
319 }
b04e311d
AC
320 }
321
322 # Advance to the infinite loop
27d3a1a2 323 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
b04e311d
AC
324
325 # Make the signal pending
326 sleep 1
e5f8a7cc
PA
327
328 test_skip_handler $prefix $i
b04e311d
AC
329}
330
e5f8a7cc
PA
331foreach cmd {"stepi" "nexti" "step" "next" "continue"} {
332 skip_over_handler $cmd
333}
b04e311d
AC
334
335# Try stepping when there's a signal pending, a pre-existing
336# breakpoint at the current instruction, and a breakpoint in the
337# handler. Should advance to the signal handler.
338
339proc breakpoint_to_handler { i } {
340 global gdb_prompt
341 global infinite_loop
342 set prefix "$i on breakpoint, to handler"
343
344 # Run around to the done
60fe1a51 345 # You can add more patterns to this if you need them.
b04e311d
AC
346 set test "$prefix; resync"
347 gdb_test_multiple "continue" "$test" {
348 -re "done = 0.*$gdb_prompt " {
349 pass "$test"
350 }
b04e311d
AC
351 }
352
27d3a1a2
MS
353 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
354 gdb_test "break handler" ".*" "$prefix; break handler"
b04e311d
AC
355
356 # Continue to the infinite loop
357 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
358
359 # Make the signal pending
360 sleep 1
361
b04e311d 362 gdb_test "$i" " handler .*" "$prefix; performing $i"
27d3a1a2
MS
363 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
364 gdb_test "clear handler" ".*" "$prefix; clear handler"
b04e311d
AC
365}
366
367breakpoint_to_handler step
368breakpoint_to_handler next
369breakpoint_to_handler continue
370
2dedb159
AC
371# Try stepping when there's a signal pending, and a breakpoint at the
372# handler's entry instruction and a breakpoint at the current
373# instruction. Should step into the signal handler and breakpoint at
374# that entry instruction.
375
376# Some systems (e.x., GNU/Linux as of 2004-08-30), when delivering a
377# signal, resume the process at the first instruction of the signal
378# handler and not the first instruction of the signal trampoline. The
379# stack is constructed such that the signal handler still appears to
380# have been called by the trampoline code. This test checks that it
381# is possible to stop the inferior, even at that first instruction.
382
383proc breakpoint_to_handler_entry { i } {
384 global gdb_prompt
385 global infinite_loop
386 set prefix "$i on breakpoint, to handler entry"
387
388 # Run around to the done
60fe1a51 389 # You can add more patterns to this if you need them.
2dedb159
AC
390 set test "$prefix; resync"
391 gdb_test_multiple "continue" "$test" {
392 -re "done = 0.*$gdb_prompt " {
393 pass "$test"
394 }
2dedb159
AC
395 }
396
27d3a1a2
MS
397 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
398 gdb_test "break *handler" ".*" "$prefix; break handler"
2dedb159
AC
399
400 # Continue to the infinite loop
401 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
402
403 # Make the signal pending
404 sleep 1
405
2dedb159 406 gdb_test "$i" " handler .*" "$prefix; performing $i"
27d3a1a2
MS
407 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
408 gdb_test "clear *handler" ".*" "$prefix; clear handler"
2dedb159
AC
409}
410
411breakpoint_to_handler_entry step
412breakpoint_to_handler_entry next
413breakpoint_to_handler_entry continue
414
b04e311d
AC
415# Try stepping when there's a signal pending, and a pre-existing
416# breakpoint at the current instruction, and no breakpoint in the
e5f8a7cc 417# handler. Should advance to the next line/instruction.
b04e311d
AC
418
419proc breakpoint_over_handler { i } {
420 global gdb_prompt
421 global infinite_loop
422 set prefix "$i on breakpoint, skip handler"
423
424 # Run around to the done
60fe1a51 425 # You can add more patterns to this if you need them.
b04e311d
AC
426 set test "$prefix; resync"
427 gdb_test_multiple "continue" "$test" {
428 -re "done = 0.*$gdb_prompt " {
429 pass "$test"
430 }
b04e311d
AC
431 }
432
27d3a1a2 433 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
b04e311d
AC
434
435 # Continue to the infinite loop
436 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
437
438 # Make the signal pending
439 sleep 1
440
e5f8a7cc 441 test_skip_handler $prefix $i
27d3a1a2 442 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
b04e311d
AC
443}
444
e5f8a7cc
PA
445foreach cmd {"stepi" "nexti" "step" "next" "continue"} {
446 breakpoint_over_handler $cmd
447}
This page took 1.0762 seconds and 4 git commands to generate.