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