Add support for --start option in -exec-run GDB/MI command.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / sigstep.exp
CommitLineData
28e7fd62 1# Copyright 2004-2013 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 $" {
bbc8b958 68 setup_kfail gdb/1736 "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} $" {
bbc8b958 80 setup_kfail gdb/1639 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.
bbc8b958
TT
109 setup_kfail gdb/1736 "i?86-*-linux*"
110 setup_kfail gdb/1736 "*-*-openbsd*"
04f6ecf2
DJ
111 fail "$test (could not set breakpoint)"
112 return
113 }
8608915f 114 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
bbc8b958 115 setup_kfail gdb/1736 "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} $" {
42edda50
AC
162 kfail gdb/1639 "$test (program exited)"
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
272skip_to_handler_entry step
273skip_to_handler_entry next
274skip_to_handler_entry continue
275
b04e311d
AC
276# Try stepping when there's a signal pending but no breakpoints.
277# Should skip the handler advancing to the next line.
278
279proc skip_over_handler { i } {
280 global gdb_prompt
281 global infinite_loop
282 set prefix "$i over handler"
283
284 # Run around to the done
60fe1a51 285 # You can add more patterns to this if you need them.
b04e311d
AC
286 set test "$prefix; resync"
287 gdb_test_multiple "continue" "$test" {
288 -re "done = 0.*$gdb_prompt " {
289 pass "$test"
290 }
b04e311d
AC
291 }
292
293 # Advance to the infinite loop
27d3a1a2 294 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
b04e311d
AC
295
296 # Make the signal pending
297 sleep 1
298
299 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
300}
301
302skip_over_handler step
303skip_over_handler next
304skip_over_handler continue
305
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.
309
310proc breakpoint_to_handler { i } {
311 global gdb_prompt
312 global infinite_loop
313 set prefix "$i on breakpoint, to handler"
314
315 # Run around to the done
60fe1a51 316 # You can add more patterns to this if you need them.
b04e311d
AC
317 set test "$prefix; resync"
318 gdb_test_multiple "continue" "$test" {
319 -re "done = 0.*$gdb_prompt " {
320 pass "$test"
321 }
b04e311d
AC
322 }
323
27d3a1a2
MS
324 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
325 gdb_test "break handler" ".*" "$prefix; break handler"
b04e311d
AC
326
327 # Continue to the infinite loop
328 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
329
330 # Make the signal pending
331 sleep 1
332
b04e311d 333 gdb_test "$i" " handler .*" "$prefix; performing $i"
27d3a1a2
MS
334 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
335 gdb_test "clear handler" ".*" "$prefix; clear handler"
b04e311d
AC
336}
337
338breakpoint_to_handler step
339breakpoint_to_handler next
340breakpoint_to_handler continue
341
2dedb159
AC
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.
346
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.
353
354proc breakpoint_to_handler_entry { i } {
355 global gdb_prompt
356 global infinite_loop
357 set prefix "$i on breakpoint, to handler entry"
358
359 # Run around to the done
60fe1a51 360 # You can add more patterns to this if you need them.
2dedb159
AC
361 set test "$prefix; resync"
362 gdb_test_multiple "continue" "$test" {
363 -re "done = 0.*$gdb_prompt " {
364 pass "$test"
365 }
2dedb159
AC
366 }
367
27d3a1a2
MS
368 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
369 gdb_test "break *handler" ".*" "$prefix; break handler"
2dedb159
AC
370
371 # Continue to the infinite loop
372 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
373
374 # Make the signal pending
375 sleep 1
376
2dedb159 377 gdb_test "$i" " handler .*" "$prefix; performing $i"
27d3a1a2
MS
378 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
379 gdb_test "clear *handler" ".*" "$prefix; clear handler"
2dedb159
AC
380}
381
382breakpoint_to_handler_entry step
383breakpoint_to_handler_entry next
384breakpoint_to_handler_entry continue
385
b04e311d
AC
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.
389
390proc breakpoint_over_handler { i } {
391 global gdb_prompt
392 global infinite_loop
393 set prefix "$i on breakpoint, skip handler"
394
395 # Run around to the done
60fe1a51 396 # You can add more patterns to this if you need them.
b04e311d
AC
397 set test "$prefix; resync"
398 gdb_test_multiple "continue" "$test" {
399 -re "done = 0.*$gdb_prompt " {
400 pass "$test"
401 }
b04e311d
AC
402 }
403
27d3a1a2 404 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
b04e311d
AC
405
406 # Continue to the infinite loop
407 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
408
409 # Make the signal pending
410 sleep 1
411
b04e311d 412 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
27d3a1a2 413 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
b04e311d
AC
414}
415
416breakpoint_over_handler step
417breakpoint_over_handler next
418breakpoint_over_handler continue
This page took 0.981618 seconds and 4 git commands to generate.