Commit | Line | Data |
---|---|---|
f0fd9238 AC |
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 | |
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 | ||
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 | |
b04e311d | 75 | set prefix "$i from handler" |
f0fd9238 AC |
76 | |
77 | # Get us back into the handler | |
b04e311d | 78 | gdb_test "continue" ".* handler .*" "$prefix; continue to handler" |
f0fd9238 | 79 | |
b04e311d | 80 | set test "$prefix; leave handler" |
f0fd9238 | 81 | gdb_test_multiple "$i" "${test}" { |
8608915f MK |
82 | -re "Could not insert single-step breakpoint.*$gdb_prompt $" { |
83 | setup_kfail "sparc*-*-openbsd*" gdb/1736 | |
84 | fail "$test (could not insert single-step breakpoint)" | |
85 | } | |
f0fd9238 AC |
86 | -re "done = 1;.*${gdb_prompt} $" { |
87 | send_gdb "$i\n" | |
714e341b | 88 | exp_continue -continue_timer |
f0fd9238 AC |
89 | } |
90 | -re "\} .. handler .*${gdb_prompt} $" { | |
91 | send_gdb "$i\n" | |
714e341b | 92 | exp_continue -continue_timer |
f0fd9238 AC |
93 | } |
94 | -re "Program exited normally.*${gdb_prompt} $" { | |
42edda50 AC |
95 | setup_kfail powerpc-*-*bsd* gdb/1639 |
96 | fail "$test (program exited)" | |
61bcae62 | 97 | } |
b04e311d | 98 | -re "(while ..done|done = 0).*${gdb_prompt} $" { |
61bcae62 AC |
99 | # After stepping out of a function /r signal-handler, GDB will |
100 | # advance the inferior until it is at the first instruction of | |
101 | # a code-line. While typically things return to the middle of | |
102 | # the "while..." (and hence GDB advances the inferior to the | |
103 | # "return..." line) it is also possible for the return to land | |
104 | # on the first instruction of "while...". Accept both cases. | |
f0fd9238 AC |
105 | pass "$test" |
106 | } | |
107 | } | |
108 | } | |
109 | ||
110 | proc advancei { i } { | |
111 | global gdb_prompt | |
b04e311d | 112 | set prefix "$i from handleri" |
f0fd9238 AC |
113 | set program_exited 0 |
114 | ||
115 | # Get us back into the handler | |
b04e311d | 116 | gdb_test "continue" ".* handler .*" "$prefix; continue to handler" |
f0fd9238 | 117 | |
b04e311d | 118 | set test "$prefix; leave handler" |
f0fd9238 | 119 | gdb_test_multiple "$i" "${test}" { |
04f6ecf2 DJ |
120 | -re "Cannot insert breakpoint 0.*${gdb_prompt} $" { |
121 | # Some platforms use a special read-only page for signal | |
122 | # trampolines. We can't set a breakpoint there, and we | |
123 | # don't gracefully fall back to single-stepping. | |
124 | setup_kfail "i?86-*-linux*" gdb/1736 | |
598b7a6f | 125 | setup_kfail "*-*-openbsd*" gdb/1736 |
04f6ecf2 DJ |
126 | fail "$test (could not set breakpoint)" |
127 | return | |
128 | } | |
8608915f MK |
129 | -re "Could not insert single-step breakpoint.*$gdb_prompt $" { |
130 | setup_kfail "sparc*-*-openbsd*" gdb/1736 | |
131 | fail "$test (could not insert single-step breakpoint)" | |
132 | } | |
f0fd9238 AC |
133 | -re "done = 1;.*${gdb_prompt} $" { |
134 | send_gdb "$i\n" | |
714e341b | 135 | exp_continue -continue_timer |
f0fd9238 AC |
136 | } |
137 | -re "\} .. handler .*${gdb_prompt} $" { | |
138 | send_gdb "$i\n" | |
714e341b | 139 | exp_continue -continue_timer |
f0fd9238 AC |
140 | } |
141 | -re "signal handler called.*${gdb_prompt} $" { | |
142 | pass "$test" | |
143 | } | |
f0fd9238 AC |
144 | -re "main .*${gdb_prompt} $" { |
145 | fail "$test (in main)" | |
146 | } | |
42edda50 AC |
147 | -re "Program exited normally.*${gdb_prompt} $" { |
148 | fail "$test (program exited)" | |
149 | set program_exited 1 | |
150 | } | |
f0fd9238 AC |
151 | -re "Make handler return now.*y or n. $" { |
152 | send_gdb "y\n" | |
714e341b | 153 | exp_continue -continue_timer |
f0fd9238 AC |
154 | } |
155 | } | |
156 | ||
b04e311d | 157 | set test "$prefix; leave signal trampoline" |
f0fd9238 AC |
158 | gdb_test_multiple "$i" "${test}" { |
159 | -re "while .*${gdb_prompt} $" { | |
160 | pass "$test (in main)" | |
161 | } | |
162 | -re "signal handler called.*${gdb_prompt} $" { | |
163 | send_gdb "$i\n" | |
714e341b | 164 | exp_continue -continue_timer |
f0fd9238 AC |
165 | } |
166 | -re "return .*${gdb_prompt} $" { | |
167 | fail "$test (stepped)" | |
168 | } | |
169 | -re "Make .*frame return now.*y or n. $" { | |
170 | send_gdb "y\n" | |
714e341b | 171 | exp_continue -continue_timer |
f0fd9238 | 172 | } |
42edda50 AC |
173 | -re "Program exited normally.*${gdb_prompt} $" { |
174 | kfail gdb/1639 "$test (program exited)" | |
175 | set program_exited 1 | |
176 | } | |
f0fd9238 AC |
177 | -re "The program is not being run.*${gdb_prompt} $" { |
178 | if { $program_exited } { | |
179 | # Previously kfailed with an exit | |
42edda50 | 180 | pass "$test (the program is not being run)" |
f0fd9238 | 181 | } else { |
42edda50 | 182 | fail "$test (the program is not being run)" |
f0fd9238 AC |
183 | } |
184 | } | |
185 | } | |
186 | } | |
187 | ||
b04e311d AC |
188 | # Check that we can step/next our way out of a signal handler. |
189 | ||
f0fd9238 AC |
190 | advance step |
191 | advancei stepi | |
192 | ||
193 | advance next | |
194 | advancei nexti | |
195 | ||
196 | advancei finish | |
197 | advancei return | |
b04e311d AC |
198 | gdb_test "set done = 1" "" "Set done as return will have skipped it" |
199 | ||
200 | ||
201 | # Check that we can step/next our way into / over a signal handler. | |
202 | ||
203 | # There are at least the following cases: breakpoint @pc VS breakpoint | |
204 | # in handler VS step / next / continue. | |
205 | ||
206 | # Use the real-time itimer, as otherwize the process never gets enough | |
207 | # time to expire the timer. | |
208 | ||
209 | delete_breakpoints | |
210 | set infinite_loop [gdb_get_line_number {while (!done)}] | |
211 | gdb_test "set itimer = itimer_real" | |
212 | gdb_test "break [gdb_get_line_number {done = 0}]" | |
213 | ||
214 | # Try stepping when there's a signal pending, and a breakpoint at the | |
215 | # handler. Should step into the signal handler. | |
216 | ||
217 | proc skip_to_handler { i } { | |
218 | global gdb_prompt | |
219 | global infinite_loop | |
220 | set prefix "$i to handler" | |
221 | ||
222 | # Run around to the done | |
60fe1a51 | 223 | # You can add more patterns to this if you need them. |
b04e311d AC |
224 | set test "$prefix; resync" |
225 | gdb_test_multiple "continue" "$test" { | |
226 | -re "done = 0.*$gdb_prompt " { | |
227 | pass "$test" | |
228 | } | |
b04e311d AC |
229 | } |
230 | ||
231 | # Advance to the infinite loop | |
232 | gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop" | |
233 | ||
234 | # Make the signal pending | |
235 | sleep 1 | |
236 | ||
237 | # Insert / remove the handler breakpoint. | |
238 | gdb_test "break handler" "" "$prefix; break handler" | |
239 | gdb_test "$i" " handler .*" "$prefix; performing $i" | |
240 | gdb_test "clear handler" "" "$prefix; clear handler" | |
241 | } | |
242 | ||
243 | skip_to_handler step | |
244 | skip_to_handler next | |
245 | skip_to_handler continue | |
246 | ||
2dedb159 AC |
247 | # Try stepping when there's a signal pending, and a breakpoint at the |
248 | # handler's entry-point. Should step into the signal handler stopping | |
249 | # at the entry-point. | |
250 | ||
251 | # Some systems (e.x., GNU/Linux as of 2004-08-30), when delivering a | |
252 | # signal, resume the process at the first instruction of the signal | |
253 | # handler and not the first instruction of the signal trampoline. The | |
254 | # stack is constructed such that the signal handler still appears to | |
255 | # have been called by the trampoline code. This test checks that it | |
256 | # is possible to stop the inferior, even at that first instruction. | |
257 | ||
258 | proc skip_to_handler_entry { i } { | |
259 | global gdb_prompt | |
260 | global infinite_loop | |
261 | set prefix "$i to handler entry" | |
262 | ||
263 | # Run around to the done | |
60fe1a51 | 264 | # You can add more patterns to this if you need them. |
2dedb159 AC |
265 | set test "$prefix; resync" |
266 | gdb_test_multiple "continue" "$test" { | |
267 | -re "done = 0.*$gdb_prompt " { | |
268 | pass "$test" | |
269 | } | |
2dedb159 AC |
270 | } |
271 | ||
272 | # Advance to the infinite loop | |
273 | gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop" | |
274 | ||
275 | # Make the signal pending | |
276 | sleep 1 | |
277 | ||
278 | # Insert / remove the handler breakpoint. | |
279 | gdb_test "break *handler" "" "$prefix; break handler" | |
280 | gdb_test "$i" " handler .*" "$prefix; performing $i" | |
281 | gdb_test "clear *handler" "" "$prefix; clear handler" | |
282 | } | |
283 | ||
284 | skip_to_handler_entry step | |
285 | skip_to_handler_entry next | |
286 | skip_to_handler_entry continue | |
287 | ||
b04e311d AC |
288 | # Try stepping when there's a signal pending but no breakpoints. |
289 | # Should skip the handler advancing to the next line. | |
290 | ||
291 | proc skip_over_handler { i } { | |
292 | global gdb_prompt | |
293 | global infinite_loop | |
294 | set prefix "$i over handler" | |
295 | ||
296 | # Run around to the done | |
60fe1a51 | 297 | # You can add more patterns to this if you need them. |
b04e311d AC |
298 | set test "$prefix; resync" |
299 | gdb_test_multiple "continue" "$test" { | |
300 | -re "done = 0.*$gdb_prompt " { | |
301 | pass "$test" | |
302 | } | |
b04e311d AC |
303 | } |
304 | ||
305 | # Advance to the infinite loop | |
306 | gdb_test "advance $infinite_loop" "" "$prefix; advance to infinite loop" | |
307 | ||
308 | # Make the signal pending | |
309 | sleep 1 | |
310 | ||
311 | gdb_test "$i" "done = 0.*" "$prefix; performing $i" | |
312 | } | |
313 | ||
314 | skip_over_handler step | |
315 | skip_over_handler next | |
316 | skip_over_handler continue | |
317 | ||
318 | # Try stepping when there's a signal pending, a pre-existing | |
319 | # breakpoint at the current instruction, and a breakpoint in the | |
320 | # handler. Should advance to the signal handler. | |
321 | ||
322 | proc breakpoint_to_handler { i } { | |
323 | global gdb_prompt | |
324 | global infinite_loop | |
325 | set prefix "$i on breakpoint, to handler" | |
326 | ||
327 | # Run around to the done | |
60fe1a51 | 328 | # You can add more patterns to this if you need them. |
b04e311d AC |
329 | set test "$prefix; resync" |
330 | gdb_test_multiple "continue" "$test" { | |
331 | -re "done = 0.*$gdb_prompt " { | |
332 | pass "$test" | |
333 | } | |
b04e311d AC |
334 | } |
335 | ||
336 | gdb_test "break $infinite_loop" "" "$prefix; break infinite loop" | |
337 | gdb_test "break handler" "" "$prefix; break handler" | |
338 | ||
339 | # Continue to the infinite loop | |
340 | gdb_test "continue" "while ..done.*" "$prefix; continue to infinite loop" | |
341 | ||
342 | # Make the signal pending | |
343 | sleep 1 | |
344 | ||
345 | setup_kfail "i*86-*-*" gdb/1738 | |
346 | gdb_test "$i" " handler .*" "$prefix; performing $i" | |
347 | gdb_test "clear $infinite_loop" "" "$prefix; clear infinite loop" | |
348 | gdb_test "clear handler" "" "$prefix; clear handler" | |
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 | ||
381 | gdb_test "break $infinite_loop" "" "$prefix; break infinite loop" | |
382 | gdb_test "break *handler" "" "$prefix; break handler" | |
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 | ||
390 | setup_kfail "i*86-*-*" gdb/1738 | |
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 |