1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 1997-1999, 2003-2004, 2007-2012 Free Software Foundation,
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # test running programs
24 set srcfile ${testfile}.c
25 set srcfile1 ${testfile}1.c
26 set binfile ${objdir}/${subdir}/${testfile}
28 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
29 untested ena-dis-br.exp
33 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
34 untested ena-dis-br.exp
38 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
39 untested ena-dis-br.exp
45 gdb_reinitialize_dir $srcdir/$subdir
48 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
49 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
50 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
51 set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
52 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
53 set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
54 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
55 set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile1]
56 set bp_location16 [gdb_get_line_number "set breakpoint 16 here" $srcfile1]
57 set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile1]
58 set bp_location18 [gdb_get_line_number "set breakpoint 18 here" $srcfile1]
60 if ![runto_main] then { fail "enable/disable break tests suppressed" }
62 # Verify that we can set a breakpoint (the location is irrelevant),
63 # then enable it (yes, it's already enabled by default), then hit it.
65 proc break_at { breakpoint where } {
69 set test "break $breakpoint"
71 gdb_test_multiple "$test" "$test" {
72 -re "Breakpoint (\[0-9\]*) at .*$where.*$gdb_prompt $" {
73 set bp $expect_out(1,string)
80 set bp [break_at "marker1" " line ($bp_location15|$bp_location16)"]
82 gdb_test_no_output "enable $bp" "enable break marker1"
84 gdb_test "info break $bp" \
85 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*" \
88 # See the comments in condbreak.exp for "run until breakpoint at
89 # marker1" for an explanation of the xfail below.
90 set test "continue to break marker1"
91 gdb_test_multiple "continue" "$test" {
92 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
95 -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
100 gdb_test_no_output "delete $bp" "delete break marker1"
102 # Verify that we can set a breakpoint to be self-disabling after the
103 # first time it triggers.
104 set bp [break_at "marker2" " line ($bp_location8|$bp_location9)"]
106 gdb_test_no_output "enable once $bp" "enable once break marker2"
108 gdb_test "info break $bp" \
109 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+y.*" \
110 "info auto-disabled break marker2"
112 # See the comments in condbreak.exp for "run until breakpoint at
113 # marker1" for an explanation of the xfail below.
114 set test "continue to auto-disabled break marker2"
115 gdb_test_multiple "continue" "$test" {
116 -re "Breakpoint \[0-9\]*, marker2.*$gdb_prompt $" {
119 -re "Breakpoint \[0-9\]*, $hex in marker2.*$gdb_prompt $" {
124 gdb_test "info break $bp" \
125 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+n.*" \
126 "info auto-disabled break marker2"
128 # Verify that we don't stop at a disabled breakpoint.
129 gdb_continue_to_end "no stop"
131 gdb_continue_to_end "no stop at auto-disabled break marker2"
133 # Verify that we can set a breakpoint to be self-deleting after the
134 # first time it triggers.
135 if ![runto_main] then {
136 fail "enable/disable break tests suppressed"
139 set bp [break_at "marker3" " line ($bp_location17|$bp_location18)"]
141 gdb_test_no_output "enable del $bp" "enable del break marker3"
143 gdb_test "info break $bp" \
144 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*" \
145 "info auto-deleted break marker2"
147 gdb_test "continue" \
148 ".*marker3 .*:($bp_location17|$bp_location18).*" \
149 "continue to auto-deleted break marker3"
151 gdb_test "info break $bp" \
152 ".*No breakpoint or watchpoint matching.*" \
153 "info auto-deleted break marker3"
155 # Verify that we can set a breakpoint and manually disable it (we've
156 # already proven that disabled bp's don't trigger).
158 set bp [break_at "marker4" " line ($bp_location14|$bp_location13).*"]
160 gdb_test_no_output "disable $bp" "disable break marker4"
162 gdb_test "info break $bp" \
163 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*" \
166 if ![runto_main] then {
167 fail "enable/disable break tests suppressed"
170 # Test enable count by stopping at a location until it is disabled
171 # and passes through.
173 set bp [break_at $bp_location7 "line $bp_location7"]
175 set bp2 [break_at marker1 " line ($bp_location15|$bp_location16)"]
177 gdb_test_no_output "enable count 2 $bp" "disable break with count"
179 gdb_test "continue" \
180 ".*factorial .*:$bp_location7.*" \
181 "continue from enable count, first time"
183 gdb_test "continue" \
184 ".*factorial .*:$bp_location7.*" \
185 "continue from enable count, second time"
187 gdb_test "continue" \
188 ".*marker1 .*:($bp_location15|$bp_location16).*" \
189 "continue through enable count, now disabled"
191 # Verify that we can set a breakpoint with an ignore count N, which
192 # should cause the next N triggers of the bp to be ignored. (This is
193 # a flavor of enablement/disablement, after all.)
195 if ![runto_main] then {
196 fail "enable/disable break tests suppressed"
199 set bp [break_at "marker1" " line ($bp_location15|$bp_location16).*"]
201 # Verify that an ignore of a non-existent breakpoint is gracefully
204 gdb_test "ignore 999 2" \
205 "No breakpoint number 999..*" \
206 "ignore non-existent break"
208 # Verify that a missing ignore count is gracefully handled.
210 gdb_test "ignore $bp" \
211 "Second argument .specified ignore-count. is missing..*" \
212 "ignore break with missing ignore count"
214 # Verify that a negative or zero ignore count is handled gracefully
215 # (they both are treated the same).
217 gdb_test "ignore $bp -1" \
218 "Will stop next time breakpoint \[0-9\]* is reached..*" \
219 "ignore break marker1 -1"
221 gdb_test "ignore $bp 0" \
222 "Will stop next time breakpoint \[0-9\]* is reached..*" \
223 "ignore break marker1 0"
225 gdb_test "ignore $bp 1" \
226 "Will ignore next crossing of breakpoint \[0-9\]*.*" \
227 "ignore break marker1"
229 gdb_test "info break $bp" \
230 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*ignore next 1 hits.*" \
231 "info ignored break marker1"
233 gdb_continue_to_end "no stop at ignored break marker1"
236 # See the comments in condbreak.exp for "run until breakpoint at marker1"
237 # for an explanation of the xfail below.
238 set test "continue to break marker1, 2nd time"
239 gdb_test_multiple "continue" "$test" {
240 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
241 pass "continue to break marker1, 2nd time"
243 -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
244 xfail "continue to break marker1, 2nd time"
248 # Verify that we can specify both an ignore count and an auto-delete.
250 if ![runto_main] then {
251 fail "enable/disable break tests suppressed"
254 set bp [break_at marker1 " line ($bp_location15|$bp_location16).*"]
256 gdb_test "ignore $bp 1" \
257 "Will ignore next crossing of breakpoint \[0-9\]*.*" \
258 "ignore break marker1"
260 gdb_test_no_output "enable del $bp" "enable del break marker1"
262 gdb_test "info break $bp" \
263 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*ignore next 1 hits.*" \
266 gdb_continue_to_end "no stop at ignored & auto-deleted break marker1"
269 gdb_test "continue" \
270 ".*marker1 .*:($bp_location15|$bp_location16).*" \
271 "continue to ignored & auto-deleted break marker1"
273 # Verify that a disabled breakpoint's ignore count isn't updated when
274 # the bp is encountered.
276 if ![runto_main] then {
277 fail "enable/disable break tests suppressed"
280 set bp [break_at marker1 " line ($bp_location15|$bp_location16)"]
282 gdb_test "ignore $bp 10" \
283 "Will ignore next 10 crossings of breakpoint \[0-9\]*.*" \
284 "ignore break marker1"
286 gdb_test_no_output "disable $bp" "disable break marker1"
288 gdb_continue_to_end "no stop at ignored & disabled break marker1"
291 gdb_test "info break $bp" \
292 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*ignore next 10 hits.*" \
293 "info ignored & disabled break marker1"
295 # Verify that GDB correctly handles the "continue" command with an argument,
296 # which is an ignore count to set on the currently stopped-at breakpoint.
297 # (Also verify that GDB gracefully handles the case where the inferior
298 # isn't stopped at a breakpoint.)
300 if ![runto_main] then { fail "enable/disable break tests suppressed" }
302 gdb_test "break $bp_location1" \
303 "Breakpoint \[0-9\]*.*, line $bp_location1.*" \
304 "prepare to continue with ignore count"
306 gdb_test "continue 2" \
307 "Will ignore next crossing of breakpoint \[0-9\]*. Continuing..*" \
308 "continue with ignore count"
310 gdb_test "next" ".*$bp_location11\[ \t\]*marker1.*" \
311 step after continue with ignore count"
313 set test "continue with ignore count, not stopped at bpt"
314 gdb_test_multiple "continue 2" "$test" {
315 -re "Not stopped at any breakpoint; argument ignored.*$gdb_prompt $" {
318 -re "No breakpoint number -1.*$gdb_prompt $" {
319 kfail gdb/1689 "$test"