OSDN Git Service

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