1# This testcase is part of GDB, the GNU debugger. 2 3# Copyright 1997-2016 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 ${testfile}.exp ${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 "$test" 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" 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" 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" 104 105# Verify that we don't stop at a disabled breakpoint. 106gdb_continue_to_end "no stop" 107rerun_to_main 108gdb_continue_to_end "no stop at auto-disabled break marker2" 109 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" 114} 115 116set bp [break_at "marker3" " line $bp_location17"] 117 118gdb_test_no_output "enable del $bp" "enable del break marker3" 119 120gdb_test "info break $bp" \ 121 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*" \ 122 "info auto-deleted break marker2" 123 124gdb_test "continue" \ 125 ".*marker3 .*:$bp_location17.*" \ 126 "continue to auto-deleted break marker3" 127 128gdb_test "info break $bp" \ 129 ".*No breakpoint or watchpoint matching.*" \ 130 "info auto-deleted break marker3" 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). 134 135set bp [break_at "marker4" " line $bp_location14.*"] 136 137gdb_test_no_output "disable $bp" "disable break marker4" 138 139gdb_test "info break $bp" \ 140 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*" \ 141 "info break marker4" 142 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 152set bp2 [break_at marker1 " line $bp_location15"] 153 154gdb_test "enable count" \ 155 "Argument required \\(hit count\\)\\." \ 156 "enable count missing arguments" 157 158gdb_test "enable count 2" \ 159 "Argument required \\(one or more breakpoint numbers\\)\\." \ 160 "enable count missing breakpoint number" 161 162gdb_test_no_output "enable count 2 $bp" "disable break with count" 163 164gdb_test "continue" \ 165 ".*factorial .*:$bp_location7.*" \ 166 "continue from enable count, first time" 167 168gdb_test "continue" \ 169 ".*factorial .*:$bp_location7.*" \ 170 "continue from enable count, second time" 171 172gdb_test "continue" \ 173 ".*marker1 .*:$bp_location15.*" \ 174 "continue through enable count, now disabled" 175 176# Verify that we can set a breakpoint with an ignore count N, which 177# should cause the next N triggers of the bp to be ignored. (This is 178# a flavor of enablement/disablement, after all.) 179 180if ![runto_main] then { 181 fail "enable/disable break tests suppressed" 182} 183 184set bp [break_at "marker1" " line $bp_location15.*"] 185 186# Verify that an ignore of a non-existent breakpoint is gracefully 187# handled. 188 189gdb_test "ignore 999 2" \ 190 "No breakpoint number 999..*" \ 191 "ignore non-existent break" 192 193# Verify that a missing ignore count is gracefully handled. 194 195gdb_test "ignore $bp" \ 196 "Second argument .specified ignore-count. is missing..*" \ 197 "ignore break with missing ignore count" 198 199# Verify that a negative or zero ignore count is handled gracefully 200# (they both are treated the same). 201 202gdb_test "ignore $bp -1" \ 203 "Will stop next time breakpoint \[0-9\]* is reached..*" \ 204 "ignore break marker1 -1" 205 206gdb_test "ignore $bp 0" \ 207 "Will stop next time breakpoint \[0-9\]* is reached..*" \ 208 "ignore break marker1 0" 209 210gdb_test "ignore $bp 1" \ 211 "Will ignore next crossing of breakpoint \[0-9\]*.*" \ 212 "ignore break marker1" 213 214gdb_test "info break $bp" \ 215 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*ignore next 1 hits.*" \ 216 "info ignored break marker1" 217 218gdb_continue_to_end "no stop at ignored break marker1" 219rerun_to_main 220 221# See the comments in condbreak.exp for "run until breakpoint at marker1" 222# for an explanation of the xfail below. 223set test "continue to break marker1, 2nd time" 224gdb_test_multiple "continue" "$test" { 225 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" { 226 pass "continue to break marker1, 2nd time" 227 } 228 -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" { 229 xfail "continue to break marker1, 2nd time" 230 } 231} 232 233# Verify that we can specify both an ignore count and an auto-delete. 234 235if ![runto_main] then { 236 fail "enable/disable break tests suppressed" 237} 238 239set bp [break_at marker1 " line $bp_location15.*"] 240 241gdb_test "ignore $bp 1" \ 242 "Will ignore next crossing of breakpoint \[0-9\]*.*" \ 243 "ignore break marker1" 244 245gdb_test_no_output "enable del $bp" "enable del break marker1" 246 247gdb_test "info break $bp" \ 248 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*ignore next 1 hits.*" \ 249 "info break marker1" 250 251gdb_continue_to_end "no stop at ignored & auto-deleted break marker1" 252rerun_to_main 253 254gdb_test "continue" \ 255 ".*marker1 .*:$bp_location15.*" \ 256 "continue to ignored & auto-deleted break marker1" 257 258# Verify that a disabled breakpoint's ignore count isn't updated when 259# the bp is encountered. 260 261if ![runto_main] then { 262 fail "enable/disable break tests suppressed" 263} 264 265set bp [break_at marker1 " line $bp_location15"] 266 267gdb_test "ignore $bp 10" \ 268 "Will ignore next 10 crossings of breakpoint \[0-9\]*.*" \ 269 "ignore break marker1" 270 271gdb_test_no_output "disable $bp" "disable break marker1" 272 273gdb_continue_to_end "no stop at ignored & disabled break marker1" 274rerun_to_main 275 276gdb_test "info break $bp" \ 277 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*ignore next 10 hits.*" \ 278 "info ignored & disabled break marker1" 279 280# Verify that GDB correctly handles the "continue" command with an argument, 281# which is an ignore count to set on the currently stopped-at breakpoint. 282# (Also verify that GDB gracefully handles the case where the inferior 283# isn't stopped at a breakpoint.) 284# 285if ![runto_main] then { fail "enable/disable break tests suppressed" } 286 287gdb_test "break $bp_location1" \ 288 "Breakpoint \[0-9\]*.*, line $bp_location1.*" \ 289 "prepare to continue with ignore count" 290 291gdb_test "continue 2" \ 292 "Will ignore next crossing of breakpoint \[0-9\]*. Continuing..*" \ 293 "continue with ignore count" 294 295gdb_test "next" ".*$bp_location11\[ \t\]*marker1.*" \ 296 "step after continue with ignore count" 297 298set test "continue with ignore count, not stopped at bpt" 299gdb_test_multiple "continue 2" "$test" { 300 -re "Not stopped at any breakpoint; argument ignored.*$gdb_prompt $" { 301 pass "$test" 302 } 303 -re "No breakpoint number -1.*$gdb_prompt $" { 304 kfail gdb/1689 "$test" 305 } 306} 307 308# Verify that GDB correctly handles the "enable/disable" command 309# with arguments, that include multiple locations. 310# 311if ![runto_main] then { fail "enable/disable break tests suppressed" } 312 313set b1 0 314set b2 0 315set b3 0 316set b4 0 317set b1 [break_at main ""] 318set b2 [break_at main ""] 319set b3 [break_at main ""] 320set b4 [break_at main ""] 321 322# Perform tests for disable/enable commands on multiple 323# locations and breakpoints. 324# 325# WHAT - the command to test (disable/enable). 326# 327proc test_ena_dis_br { what } { 328 global b1 329 global b2 330 global b3 331 global b4 332 global gdb_prompt 333 334 # OPPOS - the command opposite to WHAT. 335 # WHAT_RES - whether breakpoints are expected to end 336 # up enabled or disabled. 337 # OPPOS_RES- same as WHAT_RES but opposite. 338 # P1/P2 - proc to call (pass/fail). Must be 339 # opposites. 340 # Set variable values for disable command. 341 set oppos "enable" 342 set oppos_res "y" 343 set what_res "n" 344 set p1 "pass" 345 set p2 "fail" 346 347 if { "$what" == "enable" } { 348 # Set varibale values for enable command. 349 set oppos "disable" 350 set oppos_res "n" 351 set what_res "y" 352 set p1 "fail" 353 set p2 "pass" 354 } 355 356 # Now enable(disable) $b.1 $b2.1. 357 gdb_test_no_output "$what $b1.1 $b2.1" "$what \$b1.1 \$b2.1" 358 set test1 "${what}d \$b1.1 and \$b2.1" 359 360 # Now $b1.1 and $b2.1 should be enabled(disabled). 361 gdb_test_multiple "info break" "$test1" { 362 -re "(${b1}.1)(\[^\n\r\]*)( n.*)(${b2}.1)(\[^\n\r\]*)( n.*)$gdb_prompt $" { 363 $p1 "$test1" 364 } 365 -re ".*$gdb_prompt $" { 366 $p2 "$test1" 367 } 368 } 369 370 # Now enable(disable) $b1 fooo.1, it should give error on fooo. 371 gdb_test "$what $b1 fooo.1" \ 372 "Bad breakpoint number 'fooo'" \ 373 "$what \$b1 fooo.1" 374 375 # $b1 should be enabled(disabled). 376 gdb_test "info break" \ 377 "(${b1})(\[^\n\r]*)( $what_res.*)" \ 378 "${what}d \$b1" 379 380 gdb_test_no_output "$oppos $b3" "$oppos \$b3" 381 gdb_test_no_output "$what $b4 $b3.1" "$what \$b4 \$b3.1" 382 set test1 "${what}d \$b4 and \$b3.1,remain ${oppos}d \$b3" 383 384 # Now $b4 $b3.1 should be enabled(disabled) and 385 # $b3 should remain disabled(enabled). 386 gdb_test_multiple "info break" "$test1" { 387 -re "(${b3})(\[^\n\r]*)( $oppos_res.*)(${b3}.1)(\[^\n\r\]*)( n.*)(${b4})(\[^\n\r\]*)( $what_res.*)$gdb_prompt $" { 388 $p1 "$test1" 389 } 390 -re "(${b3})(\[^\n\r]*)( $oppos_res.*)(${b4})(\[^\n\r\]*)( $what_res.*)$gdb_prompt $" { 391 $p2 "$test1" 392 } 393 } 394 395 # Now enable(disable) $b4.1 fooobaar and 396 # it should give warning on fooobaar. 397 gdb_test "$what $b4.1 fooobaar" \ 398 "warning: bad breakpoint number at or near 'fooobaar'" \ 399 "$what \$b4.1 fooobar" 400 set test1 "${what}d \$b4.1" 401 402 # $b4.1 should be enabled(disabled). 403 gdb_test_multiple "info break" "$test1" { 404 -re "(${b4}.1)(\[^\n\r\]*)( n.*)$gdb_prompt $" { 405 $p1 "$test1" 406 } 407 -re ".*$gdb_prompt $" { 408 $p2 "$test1" 409 } 410 } 411} 412 413test_ena_dis_br "disable" 414test_ena_dis_br "enable" 415 416gdb_exit 417return 0 418