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