gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / ena-dis-br.exp
CommitLineData
9c7bb332
AC
1# This testcase is part of GDB, the GNU debugger.
2
0b302171
JB
3# Copyright 1997-1999, 2003-2004, 2007-2012 Free Software Foundation,
4# Inc.
c906108c
SS
5
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
e22f8b7c 8# the Free Software Foundation; either version 3 of the License, or
c906108c 9# (at your option) any later version.
e22f8b7c 10#
c906108c
SS
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.
e22f8b7c 15#
c906108c 16# You should have received a copy of the GNU General Public License
e22f8b7c 17# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 18
c906108c
SS
19#
20# test running programs
21#
c906108c
SS
22
23set testfile "break"
24set srcfile ${testfile}.c
a1dea79a 25set srcfile1 ${testfile}1.c
c906108c
SS
26set binfile ${objdir}/${subdir}/${testfile}
27
fc91c6c2 28if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
b60f0898
JB
29 untested ena-dis-br.exp
30 return -1
a1dea79a
FF
31}
32
fc91c6c2 33if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
b60f0898
JB
34 untested ena-dis-br.exp
35 return -1
a1dea79a
FF
36}
37
fc91c6c2 38if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
39 untested ena-dis-br.exp
40 return -1
c906108c
SS
41}
42
43gdb_exit
44gdb_start
45gdb_reinitialize_dir $srcdir/$subdir
46gdb_load ${binfile}
47
a1dea79a 48set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
816338b5 49set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
a1dea79a
FF
50set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
51set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
52set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
53set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
54set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
55set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile1]
56set bp_location16 [gdb_get_line_number "set breakpoint 16 here" $srcfile1]
57set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile1]
58set bp_location18 [gdb_get_line_number "set breakpoint 18 here" $srcfile1]
59
c906108c
SS
60if ![runto_main] then { fail "enable/disable break tests suppressed" }
61
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.
c906108c 64
9c7bb332
AC
65proc break_at { breakpoint where } {
66 global gdb_prompt
67 global expect_out
c906108c 68
9c7bb332
AC
69 set test "break $breakpoint"
70 set bp 0
71 gdb_test_multiple "$test" "$test" {
72 -re "Breakpoint (\[0-9\]*) at .*$where.*$gdb_prompt $" {
73 set bp $expect_out(1,string)
74 pass "$test"
75 }
76 }
77 return $bp
c906108c
SS
78}
79
9c7bb332 80set bp [break_at "marker1" " line ($bp_location15|$bp_location16)"]
c906108c 81
27d3a1a2 82gdb_test_no_output "enable $bp" "enable break marker1"
c906108c 83
9c7bb332
AC
84gdb_test "info break $bp" \
85 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*" \
86 "info break marker1"
c906108c 87
9c7bb332
AC
88# See the comments in condbreak.exp for "run until breakpoint at
89# marker1" for an explanation of the xfail below.
90set test "continue to break marker1"
91gdb_test_multiple "continue" "$test" {
92 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
93 pass "$test"
94 }
95 -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
96 xfail "$test"
97 }
c906108c
SS
98}
99
27d3a1a2 100gdb_test_no_output "delete $bp" "delete break marker1"
c906108c 101
9c7bb332
AC
102# Verify that we can set a breakpoint to be self-disabling after the
103# first time it triggers.
104set bp [break_at "marker2" " line ($bp_location8|$bp_location9)"]
c906108c 105
27d3a1a2 106gdb_test_no_output "enable once $bp" "enable once break marker2"
9c7bb332
AC
107
108gdb_test "info break $bp" \
109 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+y.*" \
110 "info auto-disabled break marker2"
111
112# See the comments in condbreak.exp for "run until breakpoint at
113# marker1" for an explanation of the xfail below.
114set test "continue to auto-disabled break marker2"
115gdb_test_multiple "continue" "$test" {
116 -re "Breakpoint \[0-9\]*, marker2.*$gdb_prompt $" {
117 pass "$test"
118 }
119 -re "Breakpoint \[0-9\]*, $hex in marker2.*$gdb_prompt $" {
120 xfail "$test"
121 }
c906108c
SS
122}
123
9c7bb332
AC
124gdb_test "info break $bp" \
125 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+n.*" \
126 "info auto-disabled break marker2"
127
c906108c 128# Verify that we don't stop at a disabled breakpoint.
7a292a7a
SS
129gdb_continue_to_end "no stop"
130rerun_to_main
131gdb_continue_to_end "no stop at auto-disabled break marker2"
c906108c 132
9c7bb332
AC
133# Verify that we can set a breakpoint to be self-deleting after the
134# first time it triggers.
135if ![runto_main] then {
136 fail "enable/disable break tests suppressed"
c906108c
SS
137}
138
9c7bb332 139set bp [break_at "marker3" " line ($bp_location17|$bp_location18)"]
c906108c 140
27d3a1a2 141gdb_test_no_output "enable del $bp" "enable del break marker3"
c906108c 142
9c7bb332
AC
143gdb_test "info break $bp" \
144 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*" \
145 "info auto-deleted break marker2"
c906108c 146
9c7bb332
AC
147gdb_test "continue" \
148 ".*marker3 .*:($bp_location17|$bp_location18).*" \
149 "continue to auto-deleted break marker3"
150
151gdb_test "info break $bp" \
e5a67952 152 ".*No breakpoint or watchpoint matching.*" \
9c7bb332 153 "info auto-deleted break marker3"
c906108c
SS
154
155# Verify that we can set a breakpoint and manually disable it (we've
156# already proven that disabled bp's don't trigger).
c906108c 157
9c7bb332 158set bp [break_at "marker4" " line ($bp_location14|$bp_location13).*"]
c906108c 159
27d3a1a2 160gdb_test_no_output "disable $bp" "disable break marker4"
9c7bb332
AC
161
162gdb_test "info break $bp" \
163 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*" \
164 "info break marker4"
c906108c 165
816338b5
SS
166if ![runto_main] then {
167 fail "enable/disable break tests suppressed"
168}
169
170# Test enable count by stopping at a location until it is disabled
171# and passes through.
172
173set bp [break_at $bp_location7 "line $bp_location7"]
174
175set bp2 [break_at marker1 " line ($bp_location15|$bp_location16)"]
176
177gdb_test_no_output "enable count 2 $bp" "disable break with count"
178
179gdb_test "continue" \
180 ".*factorial .*:$bp_location7.*" \
181 "continue from enable count, first time"
182
183gdb_test "continue" \
184 ".*factorial .*:$bp_location7.*" \
185 "continue from enable count, second time"
186
187gdb_test "continue" \
188 ".*marker1 .*:($bp_location15|$bp_location16).*" \
189 "continue through enable count, now disabled"
190
c906108c
SS
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.)
c906108c 194
9c7bb332
AC
195if ![runto_main] then {
196 fail "enable/disable break tests suppressed"
c906108c
SS
197}
198
9c7bb332
AC
199set bp [break_at "marker1" " line ($bp_location15|$bp_location16).*"]
200
c906108c
SS
201# Verify that an ignore of a non-existent breakpoint is gracefully
202# handled.
9c7bb332
AC
203
204gdb_test "ignore 999 2" \
205 "No breakpoint number 999..*" \
206 "ignore non-existent break"
c906108c
SS
207
208# Verify that a missing ignore count is gracefully handled.
9c7bb332
AC
209
210gdb_test "ignore $bp" \
211 "Second argument .specified ignore-count. is missing..*" \
212 "ignore break with missing ignore count"
c906108c
SS
213
214# Verify that a negative or zero ignore count is handled gracefully
215# (they both are treated the same).
c906108c 216
9c7bb332
AC
217gdb_test "ignore $bp -1" \
218 "Will stop next time breakpoint \[0-9\]* is reached..*" \
219 "ignore break marker1 -1"
c906108c 220
9c7bb332
AC
221gdb_test "ignore $bp 0" \
222 "Will stop next time breakpoint \[0-9\]* is reached..*" \
223 "ignore break marker1 0"
c906108c 224
9c7bb332
AC
225gdb_test "ignore $bp 1" \
226 "Will ignore next crossing of breakpoint \[0-9\]*.*" \
227 "ignore break marker1"
228
229gdb_test "info break $bp" \
230 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*ignore next 1 hits.*" \
231 "info ignored break marker1"
c906108c 232
7a292a7a
SS
233gdb_continue_to_end "no stop at ignored break marker1"
234rerun_to_main
c906108c 235
11cf8741
JM
236# See the comments in condbreak.exp for "run until breakpoint at marker1"
237# for an explanation of the xfail below.
9c7bb332
AC
238set test "continue to break marker1, 2nd time"
239gdb_test_multiple "continue" "$test" {
240 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
241 pass "continue to break marker1, 2nd time"
242 }
243 -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
244 xfail "continue to break marker1, 2nd time"
245 }
c906108c
SS
246}
247
248# Verify that we can specify both an ignore count and an auto-delete.
c906108c 249
9c7bb332
AC
250if ![runto_main] then {
251 fail "enable/disable break tests suppressed"
c906108c
SS
252}
253
9c7bb332 254set bp [break_at marker1 " line ($bp_location15|$bp_location16).*"]
c906108c 255
9c7bb332
AC
256gdb_test "ignore $bp 1" \
257 "Will ignore next crossing of breakpoint \[0-9\]*.*" \
258 "ignore break marker1"
c906108c 259
27d3a1a2 260gdb_test_no_output "enable del $bp" "enable del break marker1"
9c7bb332
AC
261
262gdb_test "info break $bp" \
263 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*ignore next 1 hits.*" \
264 "info break marker1"
c906108c 265
7a292a7a
SS
266gdb_continue_to_end "no stop at ignored & auto-deleted break marker1"
267rerun_to_main
c906108c 268
9c7bb332
AC
269gdb_test "continue" \
270 ".*marker1 .*:($bp_location15|$bp_location16).*" \
271 "continue to ignored & auto-deleted break marker1"
c906108c
SS
272
273# Verify that a disabled breakpoint's ignore count isn't updated when
274# the bp is encountered.
c906108c 275
9c7bb332
AC
276if ![runto_main] then {
277 fail "enable/disable break tests suppressed"
c906108c
SS
278}
279
9c7bb332 280set bp [break_at marker1 " line ($bp_location15|$bp_location16)"]
c906108c 281
9c7bb332
AC
282gdb_test "ignore $bp 10" \
283 "Will ignore next 10 crossings of breakpoint \[0-9\]*.*" \
284 "ignore break marker1"
285
27d3a1a2 286gdb_test_no_output "disable $bp" "disable break marker1"
c906108c 287
7a292a7a
SS
288gdb_continue_to_end "no stop at ignored & disabled break marker1"
289rerun_to_main
c906108c 290
9c7bb332
AC
291gdb_test "info break $bp" \
292 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*ignore next 10 hits.*" \
293 "info ignored & disabled break marker1"
c906108c
SS
294
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.)
299#
300if ![runto_main] then { fail "enable/disable break tests suppressed" }
301
9c7bb332
AC
302gdb_test "break $bp_location1" \
303 "Breakpoint \[0-9\]*.*, line $bp_location1.*" \
304 "prepare to continue with ignore count"
305
306gdb_test "continue 2" \
307 "Will ignore next crossing of breakpoint \[0-9\]*. Continuing..*" \
308 "continue with ignore count"
309
310gdb_test "next" ".*$bp_location11\[ \t\]*marker1.*" \
311 step after continue with ignore count"
312
313set test "continue with ignore count, not stopped at bpt"
314gdb_test_multiple "continue 2" "$test" {
315 -re "Not stopped at any breakpoint; argument ignored.*$gdb_prompt $" {
316 pass "$test"
317 }
318 -re "No breakpoint number -1.*$gdb_prompt $" {
319 kfail gdb/1689 "$test"
320 }
c906108c
SS
321}
322
323gdb_exit
324return 0
This page took 1.465138 seconds and 4 git commands to generate.