1 # Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
28 # test running programs
34 set srcfile ${testfile}.c
35 set binfile ${objdir}/${subdir}/${testfile}
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
38 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
41 proc rerun_to_main {} {
44 if [target_info exists use_gdb_stub] {
47 -re ".*Breakpoint .*main .*$gdb_prompt $"\
48 {pass "rerun to main" ; return 0}
50 {fail "rerun to main" ; return 0}
51 timeout {fail "(timeout) rerun to main" ; return 0}
56 -re "Starting program.*$gdb_prompt $"\
57 {pass "rerun to main" ; return 0}
59 {fail "rerun to main" ; return 0}
60 timeout {fail "(timeout) rerun to main" ; return 0}
67 gdb_reinitialize_dir $srcdir/$subdir
70 if ![runto_main] then { fail "enable/disable break tests suppressed" }
72 # Verify that we can set a breakpoint (the location is irrelevant),
73 # then enable it (yes, it's already enabled by default), then hit it.
75 send_gdb "break marker1\n"
77 -re "Breakpoint (\[0-9\]*) at .*, line 4\[38\].*$gdb_prompt $"\
78 {pass "break marker1"}
80 {fail "break marker1"}
81 timeout {fail "(timeout) break marker1"}
84 send_gdb "enable $expect_out(1,string)\n"
87 {pass "enable break marker1"}
88 timeout {fail "(timeout) enable break marker1"}
91 send_gdb "info break $expect_out(1,string)\n"
93 -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*$gdb_prompt $"\
94 {pass "info break marker1"}
96 {fail "info break marker1"}
97 timeout {fail "(timeout) info break marker1"}
100 send_gdb "continue\n"
102 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $"\
103 {pass "continue to break marker1"}
105 {fail "continue to break marker1"}
106 timeout {fail "(timeout) continue to break marker1"}
109 send_gdb "delete $expect_out(1,string)\n"
112 {pass "delete break marker1"}
113 timeout {fail "(timeout) delete break marker1"}
116 # Verify that we can set a breakpoint to be self-disabling after
117 # the first time it triggers.
119 send_gdb "break marker2\n"
121 -re "Breakpoint (\[0-9\]*) at .*, line 4\[49\].*$gdb_prompt $"\
122 {pass "break marker2"}
124 {fail "break marker2"}
125 timeout {fail "(timeout) break marker2"}
128 send_gdb "enable once $expect_out(1,string)\n"
131 {pass "enable once break marker2"}
132 timeout {fail "(timeout) enable once break marker2"}
135 send_gdb "info break $expect_out(1,string)\n"
137 -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+y.*$gdb_prompt $"\
138 {pass "info auto-disabled break marker2"}
140 {fail "info auto-disabled break marker2"}
141 timeout {fail "(timeout) info auto-disabled break marker2"}
144 send_gdb "continue\n"
146 -re "Breakpoint \[0-9\]*, marker2.*$gdb_prompt $"\
147 {pass "continue to auto-disabled break marker2"}
149 {fail "continue to auto-disabled break marker2"}
150 timeout {fail "(timeout) continue to auto-disabled break marker2"}
153 send_gdb "info break $expect_out(1,string)\n"
155 -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+n.*$gdb_prompt $"\
156 {pass "info auto-disabled break marker2"}
158 {fail "info auto-disabled break marker2"}
159 timeout {fail "(timeout) info auto-disabled break marker2"}
162 # Verify that we don't stop at a disabled breakpoint.
164 gdb_continue_to_end "no stop"
166 gdb_continue_to_end "no stop at auto-disabled break marker2"
168 # Verify that we can set a breakpoint to be self-deleting after
169 # the first time it triggers.
171 if ![runto_main] then { fail "enable/disable break tests suppressed" }
173 send_gdb "break marker3\n"
175 -re "Breakpoint (\[0-9\]*) at .*, line (45|50).*$gdb_prompt $"\
176 {pass "break marker3"}
178 {fail "break marker3"}
179 timeout {fail "(timeout) break marker3"}
182 send_gdb "enable del $expect_out(1,string)\n"
185 {pass "enable del break marker3"}
186 timeout {fail "(timeout) enable del break marker3"}
189 send_gdb "info break $expect_out(1,string)\n"
191 -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*$gdb_prompt $"\
192 {pass "info auto-deleted break marker2"}
194 {fail "info auto-deleted break marker2"}
195 timeout {fail "(timeout) info auto-deleted break marker2"}
198 send_gdb "continue\n"
200 -re ".*marker3 .*:(45|50).*$gdb_prompt $"\
201 {pass "continue to auto-deleted break marker3"}
202 -re "Breakpoint \[0-9\]*, marker3.*$gdb_prompt $"\
203 {fail "continue to auto-deleted break marker3"}
205 {fail "continue to auto-deleted break marker3"}
206 timeout {fail "(timeout) continue to break marker3"}
209 send_gdb "info break $expect_out(1,string)\n"
211 -re ".*No breakpoint or watchpoint number.*$gdb_prompt $"\
212 {pass "info auto-deleted break marker3"}
213 -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\].*$gdb_prompt $"\
214 {fail "info auto-deleted break marker3"}
216 {fail "info auto-deleted break marker3"}
217 timeout {fail "(timeout) info auto-deleted break marker3"}
220 # Verify that we can set a breakpoint and manually disable it (we've
221 # already proven that disabled bp's don't trigger).
223 send_gdb "break marker4\n"
225 -re "Breakpoint (\[0-9\]*) at .*, line (46|51).*$gdb_prompt $"\
226 {pass "break marker4"}
228 {fail "break marker4"}
229 timeout {fail "(timeout) break marker4"}
232 send_gdb "disable $expect_out(1,string)\n"
235 {pass "disable break marker4"}
236 timeout {fail "(timeout) disable break marker4"}
239 send_gdb "info break $expect_out(1,string)\n"
241 -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*$gdb_prompt $"\
242 {pass "info break marker4"}
244 {fail "info break marker4"}
245 timeout {fail "(timeout) info break marker4"}
248 # Verify that we can set a breakpoint with an ignore count N, which
249 # should cause the next N triggers of the bp to be ignored. (This is
250 # a flavor of enablement/disablement, after all.)
252 if ![runto_main] then { fail "enable/disable break tests suppressed" }
254 send_gdb "break marker1\n"
256 -re "Breakpoint (\[0-9\]*) at .*, line 4\[38\].*$gdb_prompt $"\
257 {pass "break marker1"}
259 {fail "break marker1"}
260 timeout {fail "(timeout) break marker1"}
263 # Verify that an ignore of a non-existent breakpoint is gracefully
266 send_gdb "ignore 999 2\n"
268 -re "No breakpoint number 999..*$gdb_prompt $"\
269 {pass "ignore non-existent break"}
271 {fail "ignore non-existent break"}
272 timeout {fail "(timeout) ignore non-existent break"}
275 # Verify that a missing ignore count is gracefully handled.
277 send_gdb "ignore $expect_out(1,string) \n"
279 -re "Second argument .specified ignore-count. is missing..*$gdb_prompt $"\
280 {pass "ignore break with missing ignore count"}
282 {fail "ignore break with missing ignore count"}
283 timeout {fail "(timeout) ignore break with missing ignore count"}
286 # Verify that a negative or zero ignore count is handled gracefully
287 # (they both are treated the same).
289 send_gdb "ignore $expect_out(1,string) -1\n"
291 -re "Will stop next time breakpoint \[0-9\]* is reached..*$gdb_prompt $"\
292 {pass "ignore break marker1 -1"}
294 {fail "ignore break marker1 -1"}
295 timeout {fail "(timeout) ignore break marker1 -1"}
298 send_gdb "ignore $expect_out(1,string) 0\n"
300 -re "Will stop next time breakpoint \[0-9\]* is reached..*$gdb_prompt $"\
301 {pass "ignore break marker1 0"}
303 {fail "ignore break marker1 0"}
304 timeout {fail "(timeout) ignore break marker1 0"}
307 send_gdb "ignore $expect_out(1,string) 1\n"
309 -re "Will ignore next crossing of breakpoint \[0-9\]*.*$gdb_prompt $"\
310 {pass "ignore break marker1"}
312 {fail "ignore break marker1"}
313 timeout {fail "(timeout) ignore break marker1"}
316 send_gdb "info break $expect_out(1,string)\n"
318 -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*ignore next 1 hits.*$gdb_prompt $"\
319 {pass "info ignored break marker1"}
321 {fail "info ignored break marker1"}
322 timeout {fail "(timeout) info ignored break marker1"}
325 gdb_continue_to_end "no stop at ignored break marker1"
328 send_gdb "continue\n"
330 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $"\
331 {pass "continue to break marker1"}
333 {fail "continue to break marker1"}
334 timeout {fail "(timeout) continue to break marker1"}
337 # Verify that we can specify both an ignore count and an auto-delete.
339 if ![runto_main] then { fail "enable/disable break tests suppressed" }
341 send_gdb "break marker1\n"
343 -re "Breakpoint (\[0-9\]*) at .*, line 4\[38\].*$gdb_prompt $"\
344 {pass "break marker1"}
346 {fail "break marker1"}
347 timeout {fail "(timeout) break marker1"}
350 send_gdb "ignore $expect_out(1,string) 1\n"
352 -re "Will ignore next crossing of breakpoint \[0-9\]*.*$gdb_prompt $"\
353 {pass "ignore break marker1"}
355 {fail "ignore break marker1"}
356 timeout {fail "(timeout) ignore break marker1"}
359 send_gdb "enable del $expect_out(1,string)\n"
362 {pass "enable del break marker1"}
363 timeout {fail "(timeout) enable del break marker1"}
366 send_gdb "info break $expect_out(1,string)\n"
368 -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*ignore next 1 hits.*$gdb_prompt $"\
369 {pass "info break marker1"}
371 {fail "info break marker1"}
372 timeout {fail "(timeout) info break marker2"}
375 gdb_continue_to_end "no stop at ignored & auto-deleted break marker1"
378 send_gdb "continue\n"
380 -re ".*marker1 .*:4\[38\].*$gdb_prompt $"\
381 {pass "continue to ignored & auto-deleted break marker1"}
382 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $"\
383 {fail "continue to ignored & auto-deleted break marker1"}
385 {fail "continue to ignored & auto-deleted break marker1"}
386 timeout {fail "(timeout) continue to ignored & auto-deleted break marker1"}
389 # Verify that a disabled breakpoint's ignore count isn't updated when
390 # the bp is encountered.
392 if ![runto_main] then { fail "enable/disable break tests suppressed" }
394 send_gdb "break marker1\n"
396 -re "Breakpoint (\[0-9\]*) at .*, line 4\[38\].*$gdb_prompt $"\
397 {pass "break marker1"}
399 {fail "break marker1"}
400 timeout {fail "(timeout) break marker1"}
403 send_gdb "ignore $expect_out(1,string) 10\n"
405 -re "Will ignore next 10 crossings of breakpoint \[0-9\]*.*$gdb_prompt $"\
406 {pass "ignore break marker1"}
408 {fail "ignore break marker1"}
409 timeout {fail "(timeout) ignore break marker1"}
412 send_gdb "disable $expect_out(1,string)\n"
415 {pass "disable break marker1"}
416 timeout {fail "(timeout) disable break marker1"}
419 gdb_continue_to_end "no stop at ignored & disabled break marker1"
422 send_gdb "info break $expect_out(1,string)\n"
424 -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*ignore next 10 hits.*$gdb_prompt $"\
425 {pass "info ignored & disabled break marker1"}
427 {fail "info ignored & disabled break marker1"}
428 timeout {fail "(timeout) info ignored & disabled break marker1"}
431 # Verify that GDB correctly handles the "continue" command with an argument,
432 # which is an ignore count to set on the currently stopped-at breakpoint.
433 # (Also verify that GDB gracefully handles the case where the inferior
434 # isn't stopped at a breakpoint.)
436 if ![runto_main] then { fail "enable/disable break tests suppressed" }
438 send_gdb "break 79\n"
440 -re "Breakpoint \[0-9\]*.*, line 79.*$gdb_prompt $"\
441 {pass "prepare to continue with ignore count"}
443 {fail "prepare to continue with ignore count"}
444 timeout {fail "(timeout) prepare to continue with ignore count"}
446 send_gdb "continue 2\n"
448 -re "Will ignore next crossing of breakpoint \[0-9\]*. Continuing..*$gdb_prompt $"\
449 {pass "continue with ignore count"}
451 {fail "continue with ignore count"}
452 timeout {fail "(timeout) continue with ignore count"}
457 -re ".*81\[ \t\]*marker1.*$gdb_prompt $"\
458 {pass "step after continue with ignore count"}
460 {fail "step after continue with ignore count"}
461 timeout {fail "(timeout) step after continue with ignore count"}
464 # ??rehrauer: Huh. This appears to be an actual bug. (No big
465 # surprise, since this feature hasn't been tested...) Looks like
466 # GDB is currently trying to set the ignore count of bp # -1!
469 send_gdb "continue 2\n"
471 -re "Not stopped at any breakpoint; argument ignored..*$gdb_prompt $"\
472 {pass "continue with ignore count, not stopped at bpt"}
473 -re "No breakpoint number -1.*$gdb_prompt $"\
474 {xfail "(DTS'd) continue with ignore count, not stopped at bpt"}
476 {fail "continue with ignore count, not stopped at bpt"}
477 timeout {fail "(timeout) step after continue with ignore count, not stopped at bpt"}