gdb:
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / sigstep.exp
1 # Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010
2 # Free Software Foundation, Inc.
3
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.
8 #
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.
13 #
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/>.
16
17
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.
21
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.
24
25 if [target_info exists gdb,nosignals] {
26 verbose "Skipping sigstep.exp because of nosignals."
27 continue
28 }
29
30 if $tracelevel then {
31 strace $tracelevel
32 }
33
34
35 set testfile sigstep
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"
40 return -1
41 }
42
43 # get things started
44 gdb_exit
45 gdb_start
46 gdb_reinitialize_dir $srcdir/$subdir
47 gdb_load ${binfile}
48
49 gdb_test "display/i \$pc"
50
51 # Advance to main
52 if { ![runto_main] } then {
53 gdb_suppress_tests;
54 }
55
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"
60
61 # Run to the signal handler, validate the backtrace.
62 gdb_test "break handler"
63 gdb_test "continue" ".* handler .*" "continue to stepi handler"
64 send_gdb "bt\n"
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 .*"
69 }
70
71 proc advance { i } {
72 global gdb_prompt
73 set prefix "$i from handler"
74
75 # Get us back into the handler
76 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
77
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)"
83 }
84 -re "done = 1;.*${gdb_prompt} $" {
85 send_gdb "$i\n"
86 exp_continue -continue_timer
87 }
88 -re "\} .. handler .*${gdb_prompt} $" {
89 send_gdb "$i\n"
90 exp_continue -continue_timer
91 }
92 -re "Program exited normally.*${gdb_prompt} $" {
93 setup_kfail gdb/1639 powerpc-*-*bsd*
94 fail "$test (program exited)"
95 }
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.
103 pass "$test"
104 }
105 }
106 }
107
108 proc advancei { i } {
109 global gdb_prompt
110 set prefix "$i from handleri"
111 set program_exited 0
112
113 # Get us back into the handler
114 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
115
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)"
125 return
126 }
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)"
130 }
131 -re "Breakpoint \[0-9\]*, handler .*${gdb_prompt} $" {
132 fail "$test (hit breakpoint again)"
133 }
134 -re "done = 1;.*${gdb_prompt} $" {
135 send_gdb "$i\n"
136 exp_continue -continue_timer
137 }
138 -re "\} .. handler .*${gdb_prompt} $" {
139 send_gdb "$i\n"
140 exp_continue -continue_timer
141 }
142 -re "signal handler called.*${gdb_prompt} $" {
143 pass "$test"
144 }
145 -re "main .*${gdb_prompt} $" {
146 fail "$test (in main)"
147 }
148 -re "Program exited normally.*${gdb_prompt} $" {
149 fail "$test (program exited)"
150 set program_exited 1
151 }
152 -re "Make handler return now.*y or n. $" {
153 send_gdb "y\n"
154 exp_continue -continue_timer
155 }
156 }
157
158 set test "$prefix; leave signal trampoline"
159 gdb_test_multiple "$i" "${test}" {
160 -re "while .*${gdb_prompt} $" {
161 pass "$test (in main)"
162 }
163 -re "signal handler called.*${gdb_prompt} $" {
164 send_gdb "$i\n"
165 exp_continue -continue_timer
166 }
167 -re "return .*${gdb_prompt} $" {
168 fail "$test (stepped)"
169 }
170 -re "Make .*frame return now.*y or n. $" {
171 send_gdb "y\n"
172 exp_continue -continue_timer
173 }
174 -re "Program exited normally.*${gdb_prompt} $" {
175 kfail gdb/1639 "$test (program exited)"
176 set program_exited 1
177 }
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)"
182 } else {
183 fail "$test (the program is not being run)"
184 }
185 }
186 }
187 }
188
189 # Check that we can step/next our way out of a signal handler.
190
191 advance step
192 advancei stepi
193
194 advance next
195 advancei nexti
196
197 advancei finish
198 advancei return
199 gdb_test_no_output "set done = 1" "Set done as return will have skipped it"
200
201
202 # Check that we can step/next our way into / over a signal handler.
203
204 # There are at least the following cases: breakpoint @pc VS breakpoint
205 # in handler VS step / next / continue.
206
207 # Use the real-time itimer, as otherwize the process never gets enough
208 # time to expire the timer.
209
210 delete_breakpoints
211 set infinite_loop [gdb_get_line_number {while (!done)}]
212 gdb_test_no_output "set itimer = itimer_real"
213 gdb_test "break [gdb_get_line_number {done = 0}]"
214
215 # Try stepping when there's a signal pending, and a breakpoint at the
216 # handler. Should step into the signal handler.
217
218 proc skip_to_handler { i } {
219 global gdb_prompt
220 global infinite_loop
221 set prefix "$i to handler"
222
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 " {
228 pass "$test"
229 }
230 }
231
232 # Advance to the infinite loop
233 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
234
235 # Make the signal pending
236 sleep 1
237
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"
242 }
243
244 skip_to_handler step
245 skip_to_handler next
246 skip_to_handler continue
247
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.
251
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.
258
259 proc skip_to_handler_entry { i } {
260 global gdb_prompt
261 global infinite_loop
262 set prefix "$i to handler entry"
263
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 " {
269 pass "$test"
270 }
271 }
272
273 # Advance to the infinite loop
274 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
275
276 # Make the signal pending
277 sleep 1
278
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"
283 }
284
285 skip_to_handler_entry step
286 skip_to_handler_entry next
287 skip_to_handler_entry continue
288
289 # Try stepping when there's a signal pending but no breakpoints.
290 # Should skip the handler advancing to the next line.
291
292 proc skip_over_handler { i } {
293 global gdb_prompt
294 global infinite_loop
295 set prefix "$i over handler"
296
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 " {
302 pass "$test"
303 }
304 }
305
306 # Advance to the infinite loop
307 gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop"
308
309 # Make the signal pending
310 sleep 1
311
312 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
313 }
314
315 skip_over_handler step
316 skip_over_handler next
317 skip_over_handler continue
318
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.
322
323 proc breakpoint_to_handler { i } {
324 global gdb_prompt
325 global infinite_loop
326 set prefix "$i on breakpoint, to handler"
327
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 " {
333 pass "$test"
334 }
335 }
336
337 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
338 gdb_test "break handler" ".*" "$prefix; break handler"
339
340 # Continue to the infinite loop
341 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
342
343 # Make the signal pending
344 sleep 1
345
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"
349 }
350
351 breakpoint_to_handler step
352 breakpoint_to_handler next
353 breakpoint_to_handler continue
354
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.
359
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.
366
367 proc breakpoint_to_handler_entry { i } {
368 global gdb_prompt
369 global infinite_loop
370 set prefix "$i on breakpoint, to handler entry"
371
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 " {
377 pass "$test"
378 }
379 }
380
381 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
382 gdb_test "break *handler" ".*" "$prefix; break handler"
383
384 # Continue to the infinite loop
385 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
386
387 # Make the signal pending
388 sleep 1
389
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"
393 }
394
395 breakpoint_to_handler_entry step
396 breakpoint_to_handler_entry next
397 breakpoint_to_handler_entry continue
398
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.
402
403 proc breakpoint_over_handler { i } {
404 global gdb_prompt
405 global infinite_loop
406 set prefix "$i on breakpoint, skip handler"
407
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 " {
413 pass "$test"
414 }
415 }
416
417 gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop"
418
419 # Continue to the infinite loop
420 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
421
422 # Make the signal pending
423 sleep 1
424
425 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
426 gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop"
427 }
428
429 breakpoint_over_handler step
430 breakpoint_over_handler next
431 breakpoint_over_handler continue
This page took 0.041498 seconds and 4 git commands to generate.