]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/ena-dis-br.exp
Update year range in copyright notice of all files owned by the GDB project.
[thirdparty/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
32d0add0 3# Copyright 1997-2015 Free Software Foundation, Inc.
c906108c
SS
4
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
e22f8b7c 7# the Free Software Foundation; either version 3 of the License, or
c906108c 8# (at your option) any later version.
e22f8b7c 9#
c906108c
SS
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.
e22f8b7c 14#
c906108c 15# You should have received a copy of the GNU General Public License
e22f8b7c 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 17
c906108c
SS
18#
19# test running programs
20#
c906108c 21
289f9037 22standard_testfile break.c break1.c
c906108c 23
289f9037
TT
24if {[prepare_for_testing ${testfile}.exp ${testfile} \
25 [list $srcfile $srcfile2] {debug nowarnings}]} {
26 return -1
a1dea79a
FF
27}
28
a1dea79a 29set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
816338b5 30set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
289f9037 31set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile2]
a1dea79a 32set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
289f9037
TT
33set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile2]
34set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile2]
289f9037 35set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile2]
a1dea79a 36
c906108c
SS
37if ![runto_main] then { fail "enable/disable break tests suppressed" }
38
39# Verify that we can set a breakpoint (the location is irrelevant),
40# then enable it (yes, it's already enabled by default), then hit it.
c906108c 41
9c7bb332
AC
42proc break_at { breakpoint where } {
43 global gdb_prompt
44 global expect_out
c906108c 45
9c7bb332
AC
46 set test "break $breakpoint"
47 set bp 0
48 gdb_test_multiple "$test" "$test" {
49 -re "Breakpoint (\[0-9\]*) at .*$where.*$gdb_prompt $" {
50 set bp $expect_out(1,string)
51 pass "$test"
52 }
53 }
54 return $bp
c906108c
SS
55}
56
dc7e1a77 57set bp [break_at "marker1" " line $bp_location15"]
c906108c 58
27d3a1a2 59gdb_test_no_output "enable $bp" "enable break marker1"
c906108c 60
9c7bb332
AC
61gdb_test "info break $bp" \
62 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*" \
63 "info break marker1"
c906108c 64
9c7bb332
AC
65# See the comments in condbreak.exp for "run until breakpoint at
66# marker1" for an explanation of the xfail below.
67set test "continue to break marker1"
68gdb_test_multiple "continue" "$test" {
69 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
70 pass "$test"
71 }
72 -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
73 xfail "$test"
74 }
c906108c
SS
75}
76
27d3a1a2 77gdb_test_no_output "delete $bp" "delete break marker1"
c906108c 78
9c7bb332
AC
79# Verify that we can set a breakpoint to be self-disabling after the
80# first time it triggers.
dc7e1a77 81set bp [break_at "marker2" " line $bp_location8"]
c906108c 82
27d3a1a2 83gdb_test_no_output "enable once $bp" "enable once break marker2"
9c7bb332
AC
84
85gdb_test "info break $bp" \
86 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+y.*" \
87 "info auto-disabled break marker2"
88
89# See the comments in condbreak.exp for "run until breakpoint at
90# marker1" for an explanation of the xfail below.
91set test "continue to auto-disabled break marker2"
92gdb_test_multiple "continue" "$test" {
93 -re "Breakpoint \[0-9\]*, marker2.*$gdb_prompt $" {
94 pass "$test"
95 }
96 -re "Breakpoint \[0-9\]*, $hex in marker2.*$gdb_prompt $" {
97 xfail "$test"
98 }
c906108c
SS
99}
100
9c7bb332
AC
101gdb_test "info break $bp" \
102 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+n.*" \
103 "info auto-disabled break marker2"
104
c906108c 105# Verify that we don't stop at a disabled breakpoint.
7a292a7a
SS
106gdb_continue_to_end "no stop"
107rerun_to_main
108gdb_continue_to_end "no stop at auto-disabled break marker2"
c906108c 109
9c7bb332
AC
110# Verify that we can set a breakpoint to be self-deleting after the
111# first time it triggers.
112if ![runto_main] then {
113 fail "enable/disable break tests suppressed"
c906108c
SS
114}
115
dc7e1a77 116set bp [break_at "marker3" " line $bp_location17"]
c906108c 117
27d3a1a2 118gdb_test_no_output "enable del $bp" "enable del break marker3"
c906108c 119
9c7bb332
AC
120gdb_test "info break $bp" \
121 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*" \
122 "info auto-deleted break marker2"
c906108c 123
9c7bb332 124gdb_test "continue" \
dc7e1a77 125 ".*marker3 .*:$bp_location17.*" \
9c7bb332
AC
126 "continue to auto-deleted break marker3"
127
128gdb_test "info break $bp" \
e5a67952 129 ".*No breakpoint or watchpoint matching.*" \
9c7bb332 130 "info auto-deleted break marker3"
c906108c
SS
131
132# Verify that we can set a breakpoint and manually disable it (we've
133# already proven that disabled bp's don't trigger).
c906108c 134
dc7e1a77 135set bp [break_at "marker4" " line $bp_location14.*"]
c906108c 136
27d3a1a2 137gdb_test_no_output "disable $bp" "disable break marker4"
9c7bb332
AC
138
139gdb_test "info break $bp" \
140 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*" \
141 "info break marker4"
c906108c 142
816338b5
SS
143if ![runto_main] then {
144 fail "enable/disable break tests suppressed"
145}
146
147# Test enable count by stopping at a location until it is disabled
148# and passes through.
149
150set bp [break_at $bp_location7 "line $bp_location7"]
151
dc7e1a77 152set bp2 [break_at marker1 " line $bp_location15"]
816338b5
SS
153
154gdb_test_no_output "enable count 2 $bp" "disable break with count"
155
156gdb_test "continue" \
157 ".*factorial .*:$bp_location7.*" \
158 "continue from enable count, first time"
159
160gdb_test "continue" \
161 ".*factorial .*:$bp_location7.*" \
162 "continue from enable count, second time"
163
164gdb_test "continue" \
dc7e1a77 165 ".*marker1 .*:$bp_location15.*" \
816338b5
SS
166 "continue through enable count, now disabled"
167
c906108c
SS
168# Verify that we can set a breakpoint with an ignore count N, which
169# should cause the next N triggers of the bp to be ignored. (This is
170# a flavor of enablement/disablement, after all.)
c906108c 171
9c7bb332
AC
172if ![runto_main] then {
173 fail "enable/disable break tests suppressed"
c906108c
SS
174}
175
dc7e1a77 176set bp [break_at "marker1" " line $bp_location15.*"]
9c7bb332 177
c906108c
SS
178# Verify that an ignore of a non-existent breakpoint is gracefully
179# handled.
9c7bb332
AC
180
181gdb_test "ignore 999 2" \
182 "No breakpoint number 999..*" \
183 "ignore non-existent break"
c906108c
SS
184
185# Verify that a missing ignore count is gracefully handled.
9c7bb332
AC
186
187gdb_test "ignore $bp" \
188 "Second argument .specified ignore-count. is missing..*" \
189 "ignore break with missing ignore count"
c906108c
SS
190
191# Verify that a negative or zero ignore count is handled gracefully
192# (they both are treated the same).
c906108c 193
9c7bb332
AC
194gdb_test "ignore $bp -1" \
195 "Will stop next time breakpoint \[0-9\]* is reached..*" \
196 "ignore break marker1 -1"
c906108c 197
9c7bb332
AC
198gdb_test "ignore $bp 0" \
199 "Will stop next time breakpoint \[0-9\]* is reached..*" \
200 "ignore break marker1 0"
c906108c 201
9c7bb332
AC
202gdb_test "ignore $bp 1" \
203 "Will ignore next crossing of breakpoint \[0-9\]*.*" \
204 "ignore break marker1"
205
206gdb_test "info break $bp" \
207 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*ignore next 1 hits.*" \
208 "info ignored break marker1"
c906108c 209
7a292a7a
SS
210gdb_continue_to_end "no stop at ignored break marker1"
211rerun_to_main
c906108c 212
11cf8741
JM
213# See the comments in condbreak.exp for "run until breakpoint at marker1"
214# for an explanation of the xfail below.
9c7bb332
AC
215set test "continue to break marker1, 2nd time"
216gdb_test_multiple "continue" "$test" {
217 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
218 pass "continue to break marker1, 2nd time"
219 }
220 -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
221 xfail "continue to break marker1, 2nd time"
222 }
c906108c
SS
223}
224
225# Verify that we can specify both an ignore count and an auto-delete.
c906108c 226
9c7bb332
AC
227if ![runto_main] then {
228 fail "enable/disable break tests suppressed"
c906108c
SS
229}
230
dc7e1a77 231set bp [break_at marker1 " line $bp_location15.*"]
c906108c 232
9c7bb332
AC
233gdb_test "ignore $bp 1" \
234 "Will ignore next crossing of breakpoint \[0-9\]*.*" \
235 "ignore break marker1"
c906108c 236
27d3a1a2 237gdb_test_no_output "enable del $bp" "enable del break marker1"
9c7bb332
AC
238
239gdb_test "info break $bp" \
240 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*ignore next 1 hits.*" \
241 "info break marker1"
c906108c 242
7a292a7a
SS
243gdb_continue_to_end "no stop at ignored & auto-deleted break marker1"
244rerun_to_main
c906108c 245
9c7bb332 246gdb_test "continue" \
dc7e1a77 247 ".*marker1 .*:$bp_location15.*" \
9c7bb332 248 "continue to ignored & auto-deleted break marker1"
c906108c
SS
249
250# Verify that a disabled breakpoint's ignore count isn't updated when
251# the bp is encountered.
c906108c 252
9c7bb332
AC
253if ![runto_main] then {
254 fail "enable/disable break tests suppressed"
c906108c
SS
255}
256
dc7e1a77 257set bp [break_at marker1 " line $bp_location15"]
c906108c 258
9c7bb332
AC
259gdb_test "ignore $bp 10" \
260 "Will ignore next 10 crossings of breakpoint \[0-9\]*.*" \
261 "ignore break marker1"
262
27d3a1a2 263gdb_test_no_output "disable $bp" "disable break marker1"
c906108c 264
7a292a7a
SS
265gdb_continue_to_end "no stop at ignored & disabled break marker1"
266rerun_to_main
c906108c 267
9c7bb332
AC
268gdb_test "info break $bp" \
269 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*ignore next 10 hits.*" \
270 "info ignored & disabled break marker1"
c906108c
SS
271
272# Verify that GDB correctly handles the "continue" command with an argument,
273# which is an ignore count to set on the currently stopped-at breakpoint.
274# (Also verify that GDB gracefully handles the case where the inferior
275# isn't stopped at a breakpoint.)
276#
277if ![runto_main] then { fail "enable/disable break tests suppressed" }
278
9c7bb332
AC
279gdb_test "break $bp_location1" \
280 "Breakpoint \[0-9\]*.*, line $bp_location1.*" \
281 "prepare to continue with ignore count"
282
283gdb_test "continue 2" \
284 "Will ignore next crossing of breakpoint \[0-9\]*. Continuing..*" \
285 "continue with ignore count"
286
287gdb_test "next" ".*$bp_location11\[ \t\]*marker1.*" \
c1ea7c01 288 "step after continue with ignore count"
9c7bb332
AC
289
290set test "continue with ignore count, not stopped at bpt"
291gdb_test_multiple "continue 2" "$test" {
292 -re "Not stopped at any breakpoint; argument ignored.*$gdb_prompt $" {
293 pass "$test"
294 }
295 -re "No breakpoint number -1.*$gdb_prompt $" {
296 kfail gdb/1689 "$test"
297 }
c906108c
SS
298}
299
9eaabc75
MW
300# Verify that GDB correctly handles the "enable/disable" command
301# with arguments, that include multiple locations.
302#
303if ![runto_main] then { fail "enable/disable break tests suppressed" }
304
305set b1 0
306set b2 0
307set b3 0
308set b4 0
309set b1 [break_at main ""]
310set b2 [break_at main ""]
311set b3 [break_at main ""]
312set b4 [break_at main ""]
313
314# Perform tests for disable/enable commands on multiple
315# locations and breakpoints.
316#
317# WHAT - the command to test (disable/enable).
318#
319proc test_ena_dis_br { what } {
320 global b1
321 global b2
322 global b3
323 global b4
324 global gdb_prompt
325
326 # OPPOS - the command opposite to WHAT.
327 # WHAT_RES - whether breakpoints are expected to end
328 # up enabled or disabled.
329 # OPPOS_RES- same as WHAT_RES but opposite.
330 # P1/P2 - proc to call (pass/fail). Must be
331 # opposites.
332 # Set variable values for disable command.
333 set oppos "enable"
334 set oppos_res "y"
335 set what_res "n"
336 set p1 "pass"
337 set p2 "fail"
338
339 if { "$what" == "enable" } {
340 # Set varibale values for enable command.
341 set oppos "disable"
342 set oppos_res "n"
343 set what_res "y"
344 set p1 "fail"
345 set p2 "pass"
346 }
347
348 # Now enable(disable) $b.1 $b2.1.
349 gdb_test_no_output "$what $b1.1 $b2.1" "$what \$b1.1 \$b2.1"
350 set test1 "${what}d \$b1.1 and \$b2.1"
351
352 # Now $b1.1 and $b2.1 should be enabled(disabled).
353 gdb_test_multiple "info break" "$test1" {
354 -re "(${b1}.1)(\[^\n\r\]*)( n.*)(${b2}.1)(\[^\n\r\]*)( n.*)$gdb_prompt $" {
355 $p1 "$test1"
356 }
357 -re ".*$gdb_prompt $" {
358 $p2 "$test1"
359 }
360 }
361
362 # Now enable(disable) $b1 fooo.1, it should give error on fooo.
363 gdb_test "$what $b1 fooo.1" \
364 "Bad breakpoint number 'fooo'" \
365 "$what \$b1 fooo.1"
366
367 # $b1 should be enabled(disabled).
368 gdb_test "info break" \
369 "(${b1})(\[^\n\r]*)( $what_res.*)" \
370 "${what}d \$b1"
371
372 gdb_test_no_output "$oppos $b3" "$oppos \$b3"
373 gdb_test_no_output "$what $b4 $b3.1" "$what \$b4 \$b3.1"
374 set test1 "${what}d \$b4 and \$b3.1,remain ${oppos}d \$b3"
375
376 # Now $b4 $b3.1 should be enabled(disabled) and
377 # $b3 should remain disabled(enabled).
378 gdb_test_multiple "info break" "$test1" {
379 -re "(${b3})(\[^\n\r]*)( $oppos_res.*)(${b3}.1)(\[^\n\r\]*)( n.*)(${b4})(\[^\n\r\]*)( $what_res.*)$gdb_prompt $" {
380 $p1 "$test1"
381 }
382 -re "(${b3})(\[^\n\r]*)( $oppos_res.*)(${b4})(\[^\n\r\]*)( $what_res.*)$gdb_prompt $" {
383 $p2 "$test1"
384 }
385 }
386
387 # Now enable(disable) $b4.1 fooobaar and
388 # it should give warning on fooobaar.
389 gdb_test "$what $b4.1 fooobaar" \
390 "warning: bad breakpoint number at or near 'fooobaar'" \
391 "$what \$b4.1 fooobar"
392 set test1 "${what}d \$b4.1"
393
394 # $b4.1 should be enabled(disabled).
395 gdb_test_multiple "info break" "$test1" {
396 -re "(${b4}.1)(\[^\n\r\]*)( n.*)$gdb_prompt $" {
397 $p1 "$test1"
398 }
399 -re ".*$gdb_prompt $" {
400 $p2 "$test1"
401 }
402 }
403}
404
405test_ena_dis_br "disable"
406test_ena_dis_br "enable"
407
c906108c
SS
408gdb_exit
409return 0