update bug numbers (GNATS -> Bugzilla) in a few signal related tests
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / sigstep.exp
1 # Copyright 2004-2014 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
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/>.
15
16
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.
20
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.
23
24 if [target_info exists gdb,nosignals] {
25 verbose "Skipping sigstep.exp because of nosignals."
26 continue
27 }
28
29
30 standard_testfile
31
32 if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
33 untested $testfile.exp
34 return -1
35 }
36
37 gdb_test "display/i \$pc"
38
39 # Advance to main
40 if { ![runto_main] } then {
41 gdb_suppress_tests
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.
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 "
56 }
57
58 proc advance { i } {
59 global gdb_prompt inferior_exited_re
60 set prefix "$i from handler"
61
62 # Get us back into the handler
63 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
64
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/8841 "sparc*-*-openbsd*"
69 fail "$test (could not insert single-step breakpoint)"
70 }
71 -re "done = 1;.*${gdb_prompt} $" {
72 send_gdb "$i\n"
73 exp_continue -continue_timer
74 }
75 -re "\} .. handler .*${gdb_prompt} $" {
76 send_gdb "$i\n"
77 exp_continue -continue_timer
78 }
79 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
80 setup_kfail gdb/8744 powerpc-*-*bsd*
81 fail "$test (program exited)"
82 }
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.
90 pass "$test"
91 }
92 }
93 }
94
95 proc advancei { i } {
96 global gdb_prompt inferior_exited_re
97 set prefix "$i from handleri"
98 set program_exited 0
99
100 # Get us back into the handler
101 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
102
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/8841 "i?86-*-linux*"
110 setup_kfail gdb/8841 "*-*-openbsd*"
111 fail "$test (could not set breakpoint)"
112 return
113 }
114 -re "Could not insert single-step breakpoint.*$gdb_prompt $" {
115 setup_kfail gdb/8841 "sparc*-*-openbsd*"
116 fail "$test (could not insert single-step breakpoint)"
117 }
118 -re "Breakpoint \[0-9\]*, handler .*${gdb_prompt} $" {
119 fail "$test (hit breakpoint again)"
120 }
121 -re "done = 1;.*${gdb_prompt} $" {
122 send_gdb "$i\n"
123 exp_continue -continue_timer
124 }
125 -re "\} .. handler .*${gdb_prompt} $" {
126 send_gdb "$i\n"
127 exp_continue -continue_timer
128 }
129 -re "signal handler called.*${gdb_prompt} $" {
130 pass "$test"
131 }
132 -re "main .*${gdb_prompt} $" {
133 fail "$test (in main)"
134 }
135 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
136 fail "$test (program exited)"
137 set program_exited 1
138 }
139 -re "Make handler return now.*y or n. $" {
140 send_gdb "y\n"
141 exp_continue -continue_timer
142 }
143 }
144
145 set test "$prefix; leave signal trampoline"
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"
152 exp_continue -continue_timer
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"
159 exp_continue -continue_timer
160 }
161 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
162 kfail gdb/8744 "$test (program exited)"
163 set program_exited 1
164 }
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)"
169 } else {
170 fail "$test (the program is not being run)"
171 }
172 }
173 }
174 }
175
176 # Check that we can step/next our way out of a signal handler.
177
178 advance step
179 advancei stepi
180
181 advance next
182 advancei nexti
183
184 advancei finish
185 advancei return
186 gdb_test_no_output "set done = 1" "Set done as return will have skipped it"
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
197 delete_breakpoints
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}]"
201
202 # Try stepping when there's a signal pending, and a breakpoint at the
203 # handler. Should step into the signal handler.
204
205 proc 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
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 " {
215 pass "$test"
216 }
217 }
218
219 # Advance to the infinite loop
220 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
221
222 # Make the signal pending
223 sleep 1
224
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"
229 }
230
231 skip_to_handler step
232 skip_to_handler next
233 skip_to_handler continue
234
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
246 proc 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
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 " {
256 pass "$test"
257 }
258 }
259
260 # Advance to the infinite loop
261 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
262
263 # Make the signal pending
264 sleep 1
265
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"
270 }
271
272 foreach 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
278 proc 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
295 proc 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 }
304
305 # Try stepping when there's a signal pending but no breakpoints.
306 # Should skip the handler advancing to the next line.
307
308 proc 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
314 # You can add more patterns to this if you need them.
315 set test "$prefix; resync"
316 gdb_test_multiple "continue" "$test" {
317 -re "done = 0.*$gdb_prompt " {
318 pass "$test"
319 }
320 }
321
322 # Advance to the infinite loop
323 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
324
325 # Make the signal pending
326 sleep 1
327
328 test_skip_handler $prefix $i
329 }
330
331 foreach cmd {"stepi" "nexti" "step" "next" "continue"} {
332 skip_over_handler $cmd
333 }
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
339 proc 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
345 # You can add more patterns to this if you need them.
346 set test "$prefix; resync"
347 gdb_test_multiple "continue" "$test" {
348 -re "done = 0.*$gdb_prompt " {
349 pass "$test"
350 }
351 }
352
353 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
354 gdb_test "break handler" ".*" "$prefix; break handler"
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
362 gdb_test "$i" " handler .*" "$prefix; performing $i"
363 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
364 gdb_test "clear handler" ".*" "$prefix; clear handler"
365 }
366
367 breakpoint_to_handler step
368 breakpoint_to_handler next
369 breakpoint_to_handler continue
370
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
383 proc 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
389 # You can add more patterns to this if you need them.
390 set test "$prefix; resync"
391 gdb_test_multiple "continue" "$test" {
392 -re "done = 0.*$gdb_prompt " {
393 pass "$test"
394 }
395 }
396
397 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
398 gdb_test "break *handler" ".*" "$prefix; break handler"
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
406 gdb_test "$i" " handler .*" "$prefix; performing $i"
407 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
408 gdb_test "clear *handler" ".*" "$prefix; clear handler"
409 }
410
411 breakpoint_to_handler_entry step
412 breakpoint_to_handler_entry next
413 breakpoint_to_handler_entry continue
414
415 # Try stepping when there's a signal pending, and a pre-existing
416 # breakpoint at the current instruction, and no breakpoint in the
417 # handler. Should advance to the next line/instruction.
418
419 proc 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
425 # You can add more patterns to this if you need them.
426 set test "$prefix; resync"
427 gdb_test_multiple "continue" "$test" {
428 -re "done = 0.*$gdb_prompt " {
429 pass "$test"
430 }
431 }
432
433 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
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
441 test_skip_handler $prefix $i
442 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
443 }
444
445 foreach cmd {"stepi" "nexti" "step" "next" "continue"} {
446 breakpoint_over_handler $cmd
447 }
This page took 0.047443 seconds and 5 git commands to generate.