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