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