1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 1997, 1998, 1999, 2003, 2004, 2007 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # test running programs
31 set srcfile ${testfile}.c
32 set srcfile1 ${testfile}1.c
33 set binfile ${objdir}/${subdir}/${testfile}
35 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
36 untested ena-dis-br.exp
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
41 untested ena-dis-br.exp
45 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
46 untested ena-dis-br.exp
52 gdb_reinitialize_dir $srcdir/$subdir
55 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
56 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
57 set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
58 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
59 set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
60 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
61 set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile1]
62 set bp_location16 [gdb_get_line_number "set breakpoint 16 here" $srcfile1]
63 set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile1]
64 set bp_location18 [gdb_get_line_number "set breakpoint 18 here" $srcfile1]
66 if ![runto_main] then { fail "enable/disable break tests suppressed" }
68 # Verify that we can set a breakpoint (the location is irrelevant),
69 # then enable it (yes, it's already enabled by default), then hit it.
71 proc break_at { breakpoint where } {
75 set test "break $breakpoint"
77 gdb_test_multiple "$test" "$test" {
78 -re "Breakpoint (\[0-9\]*) at .*$where.*$gdb_prompt $" {
79 set bp $expect_out(1,string)
86 set bp [break_at "marker1" " line ($bp_location15|$bp_location16)"]
88 gdb_test "enable $bp" "" "enable break marker1"
90 gdb_test "info break $bp" \
91 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*" \
94 # See the comments in condbreak.exp for "run until breakpoint at
95 # marker1" for an explanation of the xfail below.
96 set test "continue to break marker1"
97 gdb_test_multiple "continue" "$test" {
98 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
101 -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
106 gdb_test "delete $bp" "" "delete break marker1"
108 # Verify that we can set a breakpoint to be self-disabling after the
109 # first time it triggers.
110 set bp [break_at "marker2" " line ($bp_location8|$bp_location9)"]
112 gdb_test "enable once $bp" "" "enable once break marker2"
114 gdb_test "info break $bp" \
115 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+y.*" \
116 "info auto-disabled break marker2"
118 # See the comments in condbreak.exp for "run until breakpoint at
119 # marker1" for an explanation of the xfail below.
120 set test "continue to auto-disabled break marker2"
121 gdb_test_multiple "continue" "$test" {
122 -re "Breakpoint \[0-9\]*, marker2.*$gdb_prompt $" {
125 -re "Breakpoint \[0-9\]*, $hex in marker2.*$gdb_prompt $" {
130 gdb_test "info break $bp" \
131 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+n.*" \
132 "info auto-disabled break marker2"
134 # Verify that we don't stop at a disabled breakpoint.
135 gdb_continue_to_end "no stop"
137 gdb_continue_to_end "no stop at auto-disabled break marker2"
139 # Verify that we can set a breakpoint to be self-deleting after the
140 # first time it triggers.
141 if ![runto_main] then {
142 fail "enable/disable break tests suppressed"
145 set bp [break_at "marker3" " line ($bp_location17|$bp_location18)"]
147 gdb_test "enable del $bp" "" "enable del break marker3"
149 gdb_test "info break $bp" \
150 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*" \
151 "info auto-deleted break marker2"
153 gdb_test "continue" \
154 ".*marker3 .*:($bp_location17|$bp_location18).*" \
155 "continue to auto-deleted break marker3"
157 gdb_test "info break $bp" \
158 ".*No breakpoint or watchpoint number.*" \
159 "info auto-deleted break marker3"
161 # Verify that we can set a breakpoint and manually disable it (we've
162 # already proven that disabled bp's don't trigger).
164 set bp [break_at "marker4" " line ($bp_location14|$bp_location13).*"]
166 gdb_test "disable $bp" "" "disable break marker4"
168 gdb_test "info break $bp" \
169 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*" \
172 # Verify that we can set a breakpoint with an ignore count N, which
173 # should cause the next N triggers of the bp to be ignored. (This is
174 # a flavor of enablement/disablement, after all.)
176 if ![runto_main] then {
177 fail "enable/disable break tests suppressed"
180 set bp [break_at "marker1" " line ($bp_location15|$bp_location16).*"]
182 # Verify that an ignore of a non-existent breakpoint is gracefully
185 gdb_test "ignore 999 2" \
186 "No breakpoint number 999..*" \
187 "ignore non-existent break"
189 # Verify that a missing ignore count is gracefully handled.
191 gdb_test "ignore $bp" \
192 "Second argument .specified ignore-count. is missing..*" \
193 "ignore break with missing ignore count"
195 # Verify that a negative or zero ignore count is handled gracefully
196 # (they both are treated the same).
198 gdb_test "ignore $bp -1" \
199 "Will stop next time breakpoint \[0-9\]* is reached..*" \
200 "ignore break marker1 -1"
202 gdb_test "ignore $bp 0" \
203 "Will stop next time breakpoint \[0-9\]* is reached..*" \
204 "ignore break marker1 0"
206 gdb_test "ignore $bp 1" \
207 "Will ignore next crossing of breakpoint \[0-9\]*.*" \
208 "ignore break marker1"
210 gdb_test "info break $bp" \
211 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*ignore next 1 hits.*" \
212 "info ignored break marker1"
214 gdb_continue_to_end "no stop at ignored break marker1"
217 # See the comments in condbreak.exp for "run until breakpoint at marker1"
218 # for an explanation of the xfail below.
219 set test "continue to break marker1, 2nd time"
220 gdb_test_multiple "continue" "$test" {
221 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
222 pass "continue to break marker1, 2nd time"
224 -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
225 xfail "continue to break marker1, 2nd time"
229 # Verify that we can specify both an ignore count and an auto-delete.
231 if ![runto_main] then {
232 fail "enable/disable break tests suppressed"
235 set bp [break_at marker1 " line ($bp_location15|$bp_location16).*"]
237 gdb_test "ignore $bp 1" \
238 "Will ignore next crossing of breakpoint \[0-9\]*.*" \
239 "ignore break marker1"
241 gdb_test "enable del $bp" "" "enable del break marker1"
243 gdb_test "info break $bp" \
244 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*ignore next 1 hits.*" \
247 gdb_continue_to_end "no stop at ignored & auto-deleted break marker1"
250 gdb_test "continue" \
251 ".*marker1 .*:($bp_location15|$bp_location16).*" \
252 "continue to ignored & auto-deleted break marker1"
254 # Verify that a disabled breakpoint's ignore count isn't updated when
255 # the bp is encountered.
257 if ![runto_main] then {
258 fail "enable/disable break tests suppressed"
261 set bp [break_at marker1 " line ($bp_location15|$bp_location16)"]
263 gdb_test "ignore $bp 10" \
264 "Will ignore next 10 crossings of breakpoint \[0-9\]*.*" \
265 "ignore break marker1"
267 gdb_test "disable $bp" "" "disable break marker1"
269 gdb_continue_to_end "no stop at ignored & disabled break marker1"
272 gdb_test "info break $bp" \
273 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*ignore next 10 hits.*" \
274 "info ignored & disabled break marker1"
276 # Verify that GDB correctly handles the "continue" command with an argument,
277 # which is an ignore count to set on the currently stopped-at breakpoint.
278 # (Also verify that GDB gracefully handles the case where the inferior
279 # isn't stopped at a breakpoint.)
281 if ![runto_main] then { fail "enable/disable break tests suppressed" }
283 gdb_test "break $bp_location1" \
284 "Breakpoint \[0-9\]*.*, line $bp_location1.*" \
285 "prepare to continue with ignore count"
287 gdb_test "continue 2" \
288 "Will ignore next crossing of breakpoint \[0-9\]*. Continuing..*" \
289 "continue with ignore count"
291 gdb_test "next" ".*$bp_location11\[ \t\]*marker1.*" \
292 step after continue with ignore count"
294 set test "continue with ignore count, not stopped at bpt"
295 gdb_test_multiple "continue 2" "$test" {
296 -re "Not stopped at any breakpoint; argument ignored.*$gdb_prompt $" {
299 -re "No breakpoint number -1.*$gdb_prompt $" {
300 kfail gdb/1689 "$test"