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