PR gdb/15827
[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/1736 "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/1639 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/1736 "i?86-*-linux*"
110 setup_kfail gdb/1736 "*-*-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/1736 "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/1639 "$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 skip_to_handler_entry step
273 skip_to_handler_entry next
274 skip_to_handler_entry continue
275
276 # Try stepping when there's a signal pending but no breakpoints.
277 # Should skip the handler advancing to the next line.
278
279 proc 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
285 # You can add more patterns to this if you need them.
286 set test "$prefix; resync"
287 gdb_test_multiple "continue" "$test" {
288 -re "done = 0.*$gdb_prompt " {
289 pass "$test"
290 }
291 }
292
293 # Advance to the infinite loop
294 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
295
296 # Make the signal pending
297 sleep 1
298
299 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
300 }
301
302 skip_over_handler step
303 skip_over_handler next
304 skip_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
310 proc 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
316 # You can add more patterns to this if you need them.
317 set test "$prefix; resync"
318 gdb_test_multiple "continue" "$test" {
319 -re "done = 0.*$gdb_prompt " {
320 pass "$test"
321 }
322 }
323
324 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
325 gdb_test "break handler" ".*" "$prefix; break handler"
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
333 gdb_test "$i" " handler .*" "$prefix; performing $i"
334 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
335 gdb_test "clear handler" ".*" "$prefix; clear handler"
336 }
337
338 breakpoint_to_handler step
339 breakpoint_to_handler next
340 breakpoint_to_handler continue
341
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
354 proc 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
360 # You can add more patterns to this if you need them.
361 set test "$prefix; resync"
362 gdb_test_multiple "continue" "$test" {
363 -re "done = 0.*$gdb_prompt " {
364 pass "$test"
365 }
366 }
367
368 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
369 gdb_test "break *handler" ".*" "$prefix; break handler"
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
377 gdb_test "$i" " handler .*" "$prefix; performing $i"
378 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
379 gdb_test "clear *handler" ".*" "$prefix; clear handler"
380 }
381
382 breakpoint_to_handler_entry step
383 breakpoint_to_handler_entry next
384 breakpoint_to_handler_entry continue
385
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
390 proc 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
396 # You can add more patterns to this if you need them.
397 set test "$prefix; resync"
398 gdb_test_multiple "continue" "$test" {
399 -re "done = 0.*$gdb_prompt " {
400 pass "$test"
401 }
402 }
403
404 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
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
412 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
413 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
414 }
415
416 breakpoint_over_handler step
417 breakpoint_over_handler next
418 breakpoint_over_handler continue
This page took 0.038719 seconds and 4 git commands to generate.