Reviewed and approved by Jim Blandy
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / sigstep.exp
1 # Copyright 2004 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 set prms_id 0
35 set bug_id 0
36
37 set testfile sigstep
38 set srcfile ${testfile}.c
39 set binfile ${objdir}/${subdir}/${testfile}
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
41 untested "Couldn't compile ${module}.c"
42 return -1
43 }
44
45 # get things started
46 gdb_exit
47 gdb_start
48 gdb_reinitialize_dir $srcdir/$subdir
49 gdb_load ${binfile}
50
51 gdb_test "display/i \$pc"
52
53 # Advance to main
54 if { ![runto_main] } then {
55 gdb_suppress_tests;
56 }
57
58 # Pass all the alarms straight through (but verbosely)
59 # gdb_test "handle SIGALRM print pass nostop"
60 # gdb_test "handle SIGVTALRM print pass nostop"
61 # gdb_test "handle SIGPROF print pass nostop"
62
63 # Run to the signal handler, validate the backtrace.
64 gdb_test "break handler"
65 gdb_test "continue" ".* handler .*" "continue to stepi handler"
66 send_gdb "bt\n"
67 gdb_expect_list "backtrace for nexti" ".*$gdb_prompt $" {
68 "\[\r\n\]+.0 \[^\r\n\]* handler "
69 "\[\r\n\]+.1 .signal handler called."
70 "\[\r\n\]+.2 \[^\r\n\]* main .*"
71 }
72
73 proc advance { i } {
74 global gdb_prompt
75 set prefix "$i from handler"
76
77 # Get us back into the handler
78 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
79
80 set test "$prefix; leave handler"
81 gdb_test_multiple "$i" "${test}" {
82 -re "done = 1;.*${gdb_prompt} $" {
83 send_gdb "$i\n"
84 exp_continue -continue_timer
85 }
86 -re "\} .. handler .*${gdb_prompt} $" {
87 send_gdb "$i\n"
88 exp_continue -continue_timer
89 }
90 -re "Program exited normally.*${gdb_prompt} $" {
91 setup_kfail powerpc-*-*bsd* gdb/1639
92 fail "$test (program exited)"
93 }
94 -re "(while ..done|done = 0).*${gdb_prompt} $" {
95 # After stepping out of a function /r signal-handler, GDB will
96 # advance the inferior until it is at the first instruction of
97 # a code-line. While typically things return to the middle of
98 # the "while..." (and hence GDB advances the inferior to the
99 # "return..." line) it is also possible for the return to land
100 # on the first instruction of "while...". Accept both cases.
101 pass "$test"
102 }
103 }
104 }
105
106 proc advancei { i } {
107 global gdb_prompt
108 set prefix "$i from handleri"
109 set program_exited 0
110
111 # Get us back into the handler
112 gdb_test "continue" ".* handler .*" "$prefix; continue to handler"
113
114 set test "$prefix; leave handler"
115 gdb_test_multiple "$i" "${test}" {
116 -re "Cannot insert breakpoint 0.*${gdb_prompt} $" {
117 # Some platforms use a special read-only page for signal
118 # trampolines. We can't set a breakpoint there, and we
119 # don't gracefully fall back to single-stepping.
120 setup_kfail "i?86-*-linux*" gdb/1736
121 setup_kfail "*-*-openbsd*" gdb/1736
122 fail "$test (could not set breakpoint)"
123 return
124 }
125 -re "done = 1;.*${gdb_prompt} $" {
126 send_gdb "$i\n"
127 exp_continue -continue_timer
128 }
129 -re "\} .. handler .*${gdb_prompt} $" {
130 send_gdb "$i\n"
131 exp_continue -continue_timer
132 }
133 -re "signal handler called.*${gdb_prompt} $" {
134 pass "$test"
135 }
136 -re "main .*${gdb_prompt} $" {
137 fail "$test (in main)"
138 }
139 -re "Program exited normally.*${gdb_prompt} $" {
140 fail "$test (program exited)"
141 set program_exited 1
142 }
143 -re "Make handler return now.*y or n. $" {
144 send_gdb "y\n"
145 exp_continue -continue_timer
146 }
147 }
148
149 set test "$prefix; leave signal trampoline"
150 gdb_test_multiple "$i" "${test}" {
151 -re "while .*${gdb_prompt} $" {
152 pass "$test (in main)"
153 }
154 -re "signal handler called.*${gdb_prompt} $" {
155 send_gdb "$i\n"
156 exp_continue -continue_timer
157 }
158 -re "return .*${gdb_prompt} $" {
159 fail "$test (stepped)"
160 }
161 -re "Make .*frame return now.*y or n. $" {
162 send_gdb "y\n"
163 exp_continue -continue_timer
164 }
165 -re "Program exited normally.*${gdb_prompt} $" {
166 kfail gdb/1639 "$test (program exited)"
167 set program_exited 1
168 }
169 -re "The program is not being run.*${gdb_prompt} $" {
170 if { $program_exited } {
171 # Previously kfailed with an exit
172 pass "$test (the program is not being run)"
173 } else {
174 fail "$test (the program is not being run)"
175 }
176 }
177 }
178 }
179
180 # Check that we can step/next our way out of a signal handler.
181
182 advance step
183 advancei stepi
184
185 advance next
186 advancei nexti
187
188 advancei finish
189 advancei return
190 gdb_test "set done = 1" "" "Set done as return will have skipped it"
191
192
193 # Check that we can step/next our way into / over a signal handler.
194
195 # There are at least the following cases: breakpoint @pc VS breakpoint
196 # in handler VS step / next / continue.
197
198 # Use the real-time itimer, as otherwize the process never gets enough
199 # time to expire the timer.
200
201 delete_breakpoints
202 set infinite_loop [gdb_get_line_number {while (!done)}]
203 gdb_test "set itimer = itimer_real"
204 gdb_test "break [gdb_get_line_number {done = 0}]"
205
206 # Try stepping when there's a signal pending, and a breakpoint at the
207 # handler. Should step into the signal handler.
208
209 proc skip_to_handler { i } {
210 global gdb_prompt
211 global infinite_loop
212 set prefix "$i to handler"
213
214 # Run around to the done
215 # You can add more patterns to this if you need them.
216 set test "$prefix; resync"
217 gdb_test_multiple "continue" "$test" {
218 -re "done = 0.*$gdb_prompt " {
219 pass "$test"
220 }
221 }
222
223 # Advance to the infinite loop
224 gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
225
226 # Make the signal pending
227 sleep 1
228
229 # Insert / remove the handler breakpoint.
230 gdb_test "break handler" "" "$prefix; break handler"
231 gdb_test "$i" " handler .*" "$prefix; performing $i"
232 gdb_test "clear handler" "" "$prefix; clear handler"
233 }
234
235 skip_to_handler step
236 skip_to_handler next
237 skip_to_handler continue
238
239 # Try stepping when there's a signal pending, and a breakpoint at the
240 # handler's entry-point. Should step into the signal handler stopping
241 # at the entry-point.
242
243 # Some systems (e.x., GNU/Linux as of 2004-08-30), when delivering a
244 # signal, resume the process at the first instruction of the signal
245 # handler and not the first instruction of the signal trampoline. The
246 # stack is constructed such that the signal handler still appears to
247 # have been called by the trampoline code. This test checks that it
248 # is possible to stop the inferior, even at that first instruction.
249
250 proc skip_to_handler_entry { i } {
251 global gdb_prompt
252 global infinite_loop
253 set prefix "$i to handler entry"
254
255 # Run around to the done
256 # You can add more patterns to this if you need them.
257 set test "$prefix; resync"
258 gdb_test_multiple "continue" "$test" {
259 -re "done = 0.*$gdb_prompt " {
260 pass "$test"
261 }
262 }
263
264 # Advance to the infinite loop
265 gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
266
267 # Make the signal pending
268 sleep 1
269
270 # Insert / remove the handler breakpoint.
271 gdb_test "break *handler" "" "$prefix; break handler"
272 gdb_test "$i" " handler .*" "$prefix; performing $i"
273 gdb_test "clear *handler" "" "$prefix; clear handler"
274 }
275
276 skip_to_handler_entry step
277 skip_to_handler_entry next
278 skip_to_handler_entry continue
279
280 # Try stepping when there's a signal pending but no breakpoints.
281 # Should skip the handler advancing to the next line.
282
283 proc skip_over_handler { i } {
284 global gdb_prompt
285 global infinite_loop
286 set prefix "$i over handler"
287
288 # Run around to the done
289 # You can add more patterns to this if you need them.
290 set test "$prefix; resync"
291 gdb_test_multiple "continue" "$test" {
292 -re "done = 0.*$gdb_prompt " {
293 pass "$test"
294 }
295 }
296
297 # Advance to the infinite loop
298 gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop"
299
300 # Make the signal pending
301 sleep 1
302
303 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
304 }
305
306 skip_over_handler step
307 skip_over_handler next
308 skip_over_handler continue
309
310 # Try stepping when there's a signal pending, a pre-existing
311 # breakpoint at the current instruction, and a breakpoint in the
312 # handler. Should advance to the signal handler.
313
314 proc breakpoint_to_handler { i } {
315 global gdb_prompt
316 global infinite_loop
317 set prefix "$i on breakpoint, to handler"
318
319 # Run around to the done
320 # You can add more patterns to this if you need them.
321 set test "$prefix; resync"
322 gdb_test_multiple "continue" "$test" {
323 -re "done = 0.*$gdb_prompt " {
324 pass "$test"
325 }
326 }
327
328 gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
329 gdb_test "break handler" "" "$prefix; break handler"
330
331 # Continue to the infinite loop
332 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
333
334 # Make the signal pending
335 sleep 1
336
337 setup_kfail "i*86-*-*" gdb/1738
338 gdb_test "$i" " handler .*" "$prefix; performing $i"
339 gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
340 gdb_test "clear handler" "" "$prefix; clear handler"
341 }
342
343 breakpoint_to_handler step
344 breakpoint_to_handler next
345 breakpoint_to_handler continue
346
347 # Try stepping when there's a signal pending, and a breakpoint at the
348 # handler's entry instruction and a breakpoint at the current
349 # instruction. Should step into the signal handler and breakpoint at
350 # that entry instruction.
351
352 # Some systems (e.x., GNU/Linux as of 2004-08-30), when delivering a
353 # signal, resume the process at the first instruction of the signal
354 # handler and not the first instruction of the signal trampoline. The
355 # stack is constructed such that the signal handler still appears to
356 # have been called by the trampoline code. This test checks that it
357 # is possible to stop the inferior, even at that first instruction.
358
359 proc breakpoint_to_handler_entry { i } {
360 global gdb_prompt
361 global infinite_loop
362 set prefix "$i on breakpoint, to handler entry"
363
364 # Run around to the done
365 # You can add more patterns to this if you need them.
366 set test "$prefix; resync"
367 gdb_test_multiple "continue" "$test" {
368 -re "done = 0.*$gdb_prompt " {
369 pass "$test"
370 }
371 }
372
373 gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
374 gdb_test "break *handler" "" "$prefix; break handler"
375
376 # Continue to the infinite loop
377 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
378
379 # Make the signal pending
380 sleep 1
381
382 setup_kfail "i*86-*-*" gdb/1738
383 gdb_test "$i" " handler .*" "$prefix; performing $i"
384 gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
385 gdb_test "clear *handler" "" "$prefix; clear handler"
386 }
387
388 breakpoint_to_handler_entry step
389 breakpoint_to_handler_entry next
390 breakpoint_to_handler_entry continue
391
392 # Try stepping when there's a signal pending, and a pre-existing
393 # breakpoint at the current instruction, and no breakpoint in the
394 # handler. Should advance to the next line.
395
396 proc breakpoint_over_handler { i } {
397 global gdb_prompt
398 global infinite_loop
399 set prefix "$i on breakpoint, skip handler"
400
401 # Run around to the done
402 # You can add more patterns to this if you need them.
403 set test "$prefix; resync"
404 gdb_test_multiple "continue" "$test" {
405 -re "done = 0.*$gdb_prompt " {
406 pass "$test"
407 }
408 }
409
410 gdb_test "break $infinite_loop" "" "$prefix; break infinite loop"
411
412 # Continue to the infinite loop
413 gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop"
414
415 # Make the signal pending
416 sleep 1
417
418 gdb_test "$i" "done = 0.*" "$prefix; performing $i"
419 gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop"
420 }
421
422 breakpoint_over_handler step
423 breakpoint_over_handler next
424 breakpoint_over_handler continue
This page took 0.048774 seconds and 4 git commands to generate.