Commit | Line | Data |
---|---|---|
4c38e0a4 JB |
1 | # Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
2 | # Free Software Foundation, Inc. | |
f0fd9238 AC |
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 | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
f0fd9238 | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
f0fd9238 AC |
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. | |
e22f8b7c | 13 | # |
f0fd9238 | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
f0fd9238 AC |
16 | |
17 | ||
18 | # The program sigstep.c creates a very simple backtrace containing one | |
b04e311d AC |
19 | # signal handler and signal trampoline. A flag is set and then the |
20 | # handler returns. This is repeated at infinitum. | |
f0fd9238 AC |
21 | |
22 | # This test runs the program up to the signal handler, and then | |
b04e311d | 23 | # attempts to step/next out of the handler and back into main. |
f0fd9238 AC |
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 | ||
f0fd9238 AC |
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}] != "" } { | |
ef783a7d | 39 | untested "Couldn't compile ${srcfile}.c" |
f0fd9238 AC |
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 | |
b04e311d | 73 | set prefix "$i from handler" |
f0fd9238 AC |
74 | |
75 | # Get us back into the handler | |
b04e311d | 76 | gdb_test "continue" ".* handler .*" "$prefix; continue to handler" |
f0fd9238 | 77 | |
b04e311d | 78 | set test "$prefix; leave handler" |
f0fd9238 | 79 | gdb_test_multiple "$i" "${test}" { |
8608915f | 80 | -re "Could not insert single-step breakpoint.*$gdb_prompt $" { |
bbc8b958 | 81 | setup_kfail gdb/1736 "sparc*-*-openbsd*" |
8608915f MK |
82 | fail "$test (could not insert single-step breakpoint)" |
83 | } | |
f0fd9238 AC |
84 | -re "done = 1;.*${gdb_prompt} $" { |
85 | send_gdb "$i\n" | |
714e341b | 86 | exp_continue -continue_timer |
f0fd9238 AC |
87 | } |
88 | -re "\} .. handler .*${gdb_prompt} $" { | |
89 | send_gdb "$i\n" | |
714e341b | 90 | exp_continue -continue_timer |
f0fd9238 AC |
91 | } |
92 | -re "Program exited normally.*${gdb_prompt} $" { | |
bbc8b958 | 93 | setup_kfail gdb/1639 powerpc-*-*bsd* |
42edda50 | 94 | fail "$test (program exited)" |
61bcae62 | 95 | } |
b04e311d | 96 | -re "(while ..done|done = 0).*${gdb_prompt} $" { |
61bcae62 AC |
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. | |
f0fd9238 AC |
103 | pass "$test" |
104 | } | |
105 | } | |
106 | } | |
107 | ||
108 | proc advancei { i } { | |
109 | global gdb_prompt | |
b04e311d | 110 | set prefix "$i from handleri" |
f0fd9238 AC |
111 | set program_exited 0 |
112 | ||
113 | # Get us back into the handler | |
b04e311d | 114 | gdb_test "continue" ".* handler .*" "$prefix; continue to handler" |
f0fd9238 | 115 | |
b04e311d | 116 | set test "$prefix; leave handler" |
f0fd9238 | 117 | gdb_test_multiple "$i" "${test}" { |
04f6ecf2 DJ |
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. | |
bbc8b958 TT |
122 | setup_kfail gdb/1736 "i?86-*-linux*" |
123 | setup_kfail gdb/1736 "*-*-openbsd*" | |
04f6ecf2 DJ |
124 | fail "$test (could not set breakpoint)" |
125 | return | |
126 | } | |
8608915f | 127 | -re "Could not insert single-step breakpoint.*$gdb_prompt $" { |
bbc8b958 | 128 | setup_kfail gdb/1736 "sparc*-*-openbsd*" |
8608915f MK |
129 | fail "$test (could not insert single-step breakpoint)" |
130 | } | |
2fa63963 DJ |
131 | -re "Breakpoint \[0-9\]*, handler .*${gdb_prompt} $" { |
132 | fail "$test (hit breakpoint again)" | |
133 | } | |
f0fd9238 AC |
134 | -re "done = 1;.*${gdb_prompt} $" { |
135 | send_gdb "$i\n" | |
714e341b | 136 | exp_continue -continue_timer |
f0fd9238 AC |
137 | } |
138 | -re "\} .. handler .*${gdb_prompt} $" { | |
139 | send_gdb "$i\n" | |
714e341b | 140 | exp_continue -continue_timer |
f0fd9238 AC |
141 | } |
142 | -re "signal handler called.*${gdb_prompt} $" { | |
143 | pass "$test" | |
144 | } | |
f0fd9238 AC |
145 | -re "main .*${gdb_prompt} $" { |
146 | fail "$test (in main)" | |
147 | } | |
42edda50 AC |
148 | -re "Program exited normally.*${gdb_prompt} $" { |
149 | fail "$test (program exited)" | |
150 | set program_exited 1 | |
151 | } | |
f0fd9238 AC |
152 | -re "Make handler return now.*y or n. $" { |
153 | send_gdb "y\n" | |
714e341b | 154 | exp_continue -continue_timer |
f0fd9238 AC |
155 | } |
156 | } | |
157 | ||
b04e311d | 158 | set test "$prefix; leave signal trampoline" |
f0fd9238 AC |
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" | |
714e341b | 165 | exp_continue -continue_timer |
f0fd9238 AC |
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" | |
714e341b | 172 | exp_continue -continue_timer |
f0fd9238 | 173 | } |
42edda50 AC |
174 | -re "Program exited normally.*${gdb_prompt} $" { |
175 | kfail gdb/1639 "$test (program exited)" | |
176 | set program_exited 1 | |
177 | } | |
f0fd9238 AC |
178 | -re "The program is not being run.*${gdb_prompt} $" { |
179 | if { $program_exited } { | |
180 | # Previously kfailed with an exit | |
42edda50 | 181 | pass "$test (the program is not being run)" |
f0fd9238 | 182 | } else { |
42edda50 | 183 | fail "$test (the program is not being run)" |
f0fd9238 AC |
184 | } |
185 | } | |
186 | } | |
187 | } | |
188 | ||
b04e311d AC |
189 | # Check that we can step/next our way out of a signal handler. |
190 | ||
f0fd9238 AC |
191 | advance step |
192 | advancei stepi | |
193 | ||
194 | advance next | |
195 | advancei nexti | |
196 | ||
197 | advancei finish | |
198 | advancei return | |
27d3a1a2 | 199 | gdb_test_no_output "set done = 1" "Set done as return will have skipped it" |
b04e311d AC |
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)}] | |
27d3a1a2 | 212 | gdb_test_no_output "set itimer = itimer_real" |
b04e311d AC |
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 | |
60fe1a51 | 224 | # You can add more patterns to this if you need them. |
b04e311d AC |
225 | set test "$prefix; resync" |
226 | gdb_test_multiple "continue" "$test" { | |
227 | -re "done = 0.*$gdb_prompt " { | |
228 | pass "$test" | |
229 | } | |
b04e311d AC |
230 | } |
231 | ||
232 | # Advance to the infinite loop | |
27d3a1a2 | 233 | gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop" |
b04e311d AC |
234 | |
235 | # Make the signal pending | |
236 | sleep 1 | |
237 | ||
238 | # Insert / remove the handler breakpoint. | |
27d3a1a2 | 239 | gdb_test "break handler" ".*" "$prefix; break handler" |
b04e311d | 240 | gdb_test "$i" " handler .*" "$prefix; performing $i" |
27d3a1a2 | 241 | gdb_test "clear handler" ".*" "$prefix; clear handler" |
b04e311d AC |
242 | } |
243 | ||
244 | skip_to_handler step | |
245 | skip_to_handler next | |
246 | skip_to_handler continue | |
247 | ||
2dedb159 AC |
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 | |
60fe1a51 | 265 | # You can add more patterns to this if you need them. |
2dedb159 AC |
266 | set test "$prefix; resync" |
267 | gdb_test_multiple "continue" "$test" { | |
268 | -re "done = 0.*$gdb_prompt " { | |
269 | pass "$test" | |
270 | } | |
2dedb159 AC |
271 | } |
272 | ||
273 | # Advance to the infinite loop | |
27d3a1a2 | 274 | gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop" |
2dedb159 AC |
275 | |
276 | # Make the signal pending | |
277 | sleep 1 | |
278 | ||
279 | # Insert / remove the handler breakpoint. | |
27d3a1a2 | 280 | gdb_test "break *handler" ".*" "$prefix; break handler" |
2dedb159 | 281 | gdb_test "$i" " handler .*" "$prefix; performing $i" |
27d3a1a2 | 282 | gdb_test "clear *handler" ".*" "$prefix; clear handler" |
2dedb159 AC |
283 | } |
284 | ||
285 | skip_to_handler_entry step | |
286 | skip_to_handler_entry next | |
287 | skip_to_handler_entry continue | |
288 | ||
b04e311d AC |
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 | |
60fe1a51 | 298 | # You can add more patterns to this if you need them. |
b04e311d AC |
299 | set test "$prefix; resync" |
300 | gdb_test_multiple "continue" "$test" { | |
301 | -re "done = 0.*$gdb_prompt " { | |
302 | pass "$test" | |
303 | } | |
b04e311d AC |
304 | } |
305 | ||
306 | # Advance to the infinite loop | |
27d3a1a2 | 307 | gdb_test "advance $infinite_loop" ".*" "$prefix; advance to infinite loop" |
b04e311d AC |
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 | |
60fe1a51 | 329 | # You can add more patterns to this if you need them. |
b04e311d AC |
330 | set test "$prefix; resync" |
331 | gdb_test_multiple "continue" "$test" { | |
332 | -re "done = 0.*$gdb_prompt " { | |
333 | pass "$test" | |
334 | } | |
b04e311d AC |
335 | } |
336 | ||
27d3a1a2 MS |
337 | gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop" |
338 | gdb_test "break handler" ".*" "$prefix; break handler" | |
b04e311d AC |
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 | ||
b04e311d | 346 | gdb_test "$i" " handler .*" "$prefix; performing $i" |
27d3a1a2 MS |
347 | gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop" |
348 | gdb_test "clear handler" ".*" "$prefix; clear handler" | |
b04e311d AC |
349 | } |
350 | ||
351 | breakpoint_to_handler step | |
352 | breakpoint_to_handler next | |
353 | breakpoint_to_handler continue | |
354 | ||
2dedb159 AC |
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 | |
60fe1a51 | 373 | # You can add more patterns to this if you need them. |
2dedb159 AC |
374 | set test "$prefix; resync" |
375 | gdb_test_multiple "continue" "$test" { | |
376 | -re "done = 0.*$gdb_prompt " { | |
377 | pass "$test" | |
378 | } | |
2dedb159 AC |
379 | } |
380 | ||
27d3a1a2 MS |
381 | gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop" |
382 | gdb_test "break *handler" ".*" "$prefix; break handler" | |
2dedb159 AC |
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 | ||
2dedb159 | 390 | gdb_test "$i" " handler .*" "$prefix; performing $i" |
27d3a1a2 MS |
391 | gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop" |
392 | gdb_test "clear *handler" ".*" "$prefix; clear handler" | |
2dedb159 AC |
393 | } |
394 | ||
395 | breakpoint_to_handler_entry step | |
396 | breakpoint_to_handler_entry next | |
397 | breakpoint_to_handler_entry continue | |
398 | ||
b04e311d AC |
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 | |
60fe1a51 | 409 | # You can add more patterns to this if you need them. |
b04e311d AC |
410 | set test "$prefix; resync" |
411 | gdb_test_multiple "continue" "$test" { | |
412 | -re "done = 0.*$gdb_prompt " { | |
413 | pass "$test" | |
414 | } | |
b04e311d AC |
415 | } |
416 | ||
27d3a1a2 | 417 | gdb_test "break $infinite_loop" ".*" "$prefix; break infinite loop" |
b04e311d AC |
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 | ||
b04e311d | 425 | gdb_test "$i" "done = 0.*" "$prefix; performing $i" |
27d3a1a2 | 426 | gdb_test "clear $infinite_loop" ".*" "$prefix; clear infinite loop" |
b04e311d AC |
427 | } |
428 | ||
429 | breakpoint_over_handler step | |
430 | breakpoint_over_handler next | |
431 | breakpoint_over_handler continue |