1# Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2# 2000, 2002, 2003, 2007 Free Software Foundation, Inc. 3 4# This program is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; either version 3 of the License, or 7# (at your option) any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17# Please email any bugs, comments, and/or additions to this file to: 18# bug-gdb@prep.ai.mit.edu 19 20# This file was written by Rob Savoye. (rob@cygnus.com) 21 22if $tracelevel then { 23 strace $tracelevel 24} 25 26 27# 28# test running programs 29# 30set prms_id 0 31set bug_id 0 32 33set testfile "break" 34set srcfile ${testfile}.c 35set srcfile1 ${testfile}1.c 36set binfile ${objdir}/${subdir}/${testfile} 37 38if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } { 39 untested break.exp 40 return -1 41} 42 43if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } { 44 untested break.exp 45 return -1 46} 47 48if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } { 49 untested break.exp 50 return -1 51} 52 53if [get_compiler_info ${binfile}] { 54 return -1 55} 56 57gdb_exit 58gdb_start 59gdb_reinitialize_dir $srcdir/$subdir 60gdb_load ${binfile} 61 62if [target_info exists gdb_stub] { 63 gdb_step_for_stub; 64} 65# 66# test simple breakpoint setting commands 67# 68 69# Test deleting all breakpoints when there are none installed, 70# GDB should not prompt for confirmation. 71# Note that lib/gdb.exp provides a "delete_breakpoints" proc 72# for general use elsewhere. 73 74send_gdb "delete breakpoints\n" 75gdb_expect { 76 -re "Delete all breakpoints.*$" { 77 send_gdb "y\n" 78 gdb_expect { 79 -re "$gdb_prompt $" { 80 fail "Delete all breakpoints when none (unexpected prompt)" 81 } 82 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" } 83 } 84 } 85 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" } 86 timeout { fail "Delete all breakpoints when none (timeout)" } 87} 88 89# 90# test break at function 91# 92gdb_test "break main" \ 93 "Breakpoint.*at.* file .*$srcfile, line.*" \ 94 "breakpoint function" 95 96# 97# test break at quoted function 98# 99gdb_test "break \"marker2\"" \ 100 "Breakpoint.*at.* file .*$srcfile1, line.*" \ 101 "breakpoint quoted function" 102 103# 104# test break at function in file 105# 106gdb_test "break $srcfile:factorial" \ 107 "Breakpoint.*at.* file .*$srcfile, line.*" \ 108 "breakpoint function in file" 109 110set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] 111 112# 113# test break at line number 114# 115# Note that the default source file is the last one whose source text 116# was printed. For native debugging, before we've executed the 117# program, this is the file containing main, but for remote debugging, 118# it's wherever the processor was stopped when we connected to the 119# board. So, to be sure, we do a list command. 120# 121gdb_test "list main" \ 122 ".*main \\(argc, argv, envp\\).*" \ 123 "use `list' to establish default source file" 124gdb_test "break $bp_location1" \ 125 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \ 126 "breakpoint line number" 127 128# 129# test duplicate breakpoint 130# 131gdb_test "break $bp_location1" \ 132 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \ 133 "breakpoint duplicate" 134 135set bp_location2 [gdb_get_line_number "set breakpoint 2 here"] 136 137# 138# test break at line number in file 139# 140gdb_test "break $srcfile:$bp_location2" \ 141 "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \ 142 "breakpoint line number in file" 143 144set bp_location3 [gdb_get_line_number "set breakpoint 3 here"] 145set bp_location4 [gdb_get_line_number "set breakpoint 4 here"] 146 147# 148# Test putting a break at the start of a multi-line if conditional. 149# Verify the breakpoint was put at the start of the conditional. 150# 151gdb_test "break multi_line_if_conditional" \ 152 "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \ 153 "breakpoint at start of multi line if conditional" 154 155gdb_test "break multi_line_while_conditional" \ 156 "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \ 157 "breakpoint at start of multi line while conditional" 158 159set bp_location5 [gdb_get_line_number "set breakpoint 5 here"] 160set bp_location6 [gdb_get_line_number "set breakpoint 6 here"] 161 162# 163# check to see what breakpoints are set 164# 165if [target_info exists gdb_stub] { 166 set main_line $bp_location5 167} else { 168 set main_line $bp_location6 169} 170 171if {$hp_aCC_compiler} { 172 set proto "\\(int\\)" 173} else { 174 set proto "" 175} 176 177set bp_location7 [gdb_get_line_number "set breakpoint 7 here"] 178set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1] 179set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1] 180 181gdb_test "info break" \ 182 "Num Type\[ \]+Disp Enb Address\[ \]+What.* 183\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.* 184\[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile1:($bp_location8|$bp_location9).* 185\[0-9\]+\[\t \]+breakpoint keep y.* in factorial$proto at .*$srcfile:$bp_location7.* 186\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.* 187\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.* 188\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location2.* 189\[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.* 190\[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \ 191 "breakpoint info" 192 193# FIXME: The rest of this test doesn't work with anything that can't 194# handle arguments. 195# Huh? There doesn't *appear* to be anything that passes arguments 196# below. 197if [istarget "mips-idt-*"] then { 198 return 199} 200 201# 202# run until the breakpoint at main is hit. For non-stubs-using targets. 203# 204gdb_run_cmd 205gdb_expect { 206 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" { 207 pass "run until function breakpoint" 208 } 209 -re "$gdb_prompt $" { 210 fail "run until function breakpoint" 211 } 212 timeout { 213 fail "run until function breakpoint (timeout)" 214 } 215} 216 217# 218# run until the breakpoint at a line number 219# 220gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \ 221 "run until breakpoint set at a line number" 222 223# 224# Run until the breakpoint set in a function in a file 225# 226for {set i 6} {$i >= 1} {incr i -1} { 227 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \ 228 "run until file:function($i) breakpoint" 229} 230 231# 232# Run until the breakpoint set at a quoted function 233# 234gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*" \ 235 "run until quoted breakpoint" 236# 237# run until the file:function breakpoint at a line number in a file 238# 239gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \ 240 "run until file:linenum breakpoint" 241 242# Test break at offset +1 243set bp_location10 [gdb_get_line_number "set breakpoint 10 here"] 244 245gdb_test "break +1" \ 246 "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \ 247 "breakpoint offset +1" 248 249# Check to see if breakpoint is hit when stepped onto 250 251gdb_test "step" \ 252 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \ 253 "step onto breakpoint" 254 255# Check to see if breakpoint can be set on ending brace of function 256set bp_location10a [gdb_get_line_number "set breakpoint 10a here"] 257 258gdb_test "break $bp_location10a" \ 259 "Breakpoint.*at.* file .*$srcfile, line $bp_location10a\\." \ 260 "setting breakpoint at }" 261 262gdb_test "continue" \ 263 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10a.*$bp_location10a\[\t \]+}.*breakpoint 10a here.*" \ 264 "continue to breakpoint at }" 265 266# 267# delete all breakpoints so we can start over, course this can be a test too 268# 269delete_breakpoints 270 271# 272# test temporary breakpoint at function 273# 274 275gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function" 276 277# 278# test break at function in file 279# 280 281gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \ 282 "Temporary breakpoint function in file" 283 284# 285# test break at line number 286# 287send_gdb "tbreak $bp_location1\n" 288gdb_expect { 289 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" } 290 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" } 291 timeout { fail "breakpoint line number #1 (timeout)" } 292} 293 294gdb_test "tbreak $bp_location6" "Breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2" 295 296# 297# test break at line number in file 298# 299send_gdb "tbreak $srcfile:$bp_location2\n" 300gdb_expect { 301 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" } 302 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" } 303 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" } 304} 305 306set bp_location11 [gdb_get_line_number "set breakpoint 11 here"] 307gdb_test "tbreak $srcfile:$bp_location11" "Breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2" 308 309# 310# check to see what breakpoints are set (temporary this time) 311# 312gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\] 313\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\] 314\[0-9\]+\[\t \]+breakpoint del.*y.*in factorial$proto at .*$srcfile:$bp_location7.*\[\r\n\] 315\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\] 316\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\] 317\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\] 318\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \ 319 "Temporary breakpoint info" 320 321 322#*********** 323 324# Verify that catchpoints for fork, vfork and exec don't trigger 325# inappropriately. (There are no calls to those system functions 326# in this test program.) 327# 328if ![runto_main] then { fail "break tests suppressed" } 329 330send_gdb "catch\n" 331gdb_expect { 332 -re "Catch requires an event name.*$gdb_prompt $"\ 333 {pass "catch requires an event name"} 334 -re "$gdb_prompt $"\ 335 {fail "catch requires an event name"} 336 timeout {fail "(timeout) catch requires an event name"} 337} 338 339 340set name "set catch fork, never expected to trigger" 341send_gdb "catch fork\n" 342gdb_expect { 343 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $" 344 {pass $name} 345 -re "Catch of fork not yet implemented.*$gdb_prompt $" 346 {pass $name} 347 -re "$gdb_prompt $" 348 {fail $name} 349 timeout {fail "(timeout) $name"} 350} 351 352 353set name "set catch vfork, never expected to trigger" 354send_gdb "catch vfork\n" 355 356# If we are on HP-UX 10.20, we expect an error message to be 357# printed if we type "catch vfork" at the gdb gdb_prompt. This is 358# because on HP-UX 10.20, we cannot catch vfork events. 359 360if [istarget "hppa*-hp-hpux10.20"] then { 361 gdb_expect { 362 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $" 363 {pass $name} 364 -re "$gdb_prompt $" 365 {fail $name} 366 timeout {fail "(timeout) $name"} 367 } 368} else { 369 gdb_expect { 370 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $" 371 {pass $name} 372 -re "Catch of vfork not yet implemented.*$gdb_prompt $" 373 {pass $name} 374 -re "$gdb_prompt $" 375 {fail $name} 376 timeout {fail "(timeout) $name"} 377 } 378} 379 380set name "set catch exec, never expected to trigger" 381send_gdb "catch exec\n" 382gdb_expect { 383 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $" 384 {pass $name} 385 -re "Catch of exec not yet implemented.*$gdb_prompt $" 386 {pass $name} 387 -re "$gdb_prompt $" {fail $name} 388 timeout {fail "(timeout) $name"} 389} 390 391# Verify that GDB responds gracefully when asked to set a breakpoint 392# on a nonexistent source line. 393# 394send_gdb "break 999\n" 395gdb_expect { 396 -re "No line 999 in file .*$gdb_prompt $"\ 397 {pass "break on non-existent source line"} 398 -re "$gdb_prompt $"\ 399 {fail "break on non-existent source line"} 400 timeout {fail "(timeout) break on non-existent source line"} 401} 402 403# Run to the desired default location. If not positioned here, the 404# tests below don't work. 405# 406gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1" 407 408 409# Verify that GDB allows one to just say "break", which is treated 410# as the "default" breakpoint. Note that GDB gets cute when printing 411# the informational message about other breakpoints at the same 412# location. We'll hit that bird with this stone too. 413# 414send_gdb "break\n" 415gdb_expect { 416 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\ 417 {pass "break on default location, 1st time"} 418 -re "$gdb_prompt $"\ 419 {fail "break on default location, 1st time"} 420 timeout {fail "(timeout) break on default location, 1st time"} 421} 422 423send_gdb "break\n" 424gdb_expect { 425 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\ 426 {pass "break on default location, 2nd time"} 427 -re "$gdb_prompt $"\ 428 {fail "break on default location, 2nd time"} 429 timeout {fail "(timeout) break on default location, 2nd time"} 430} 431 432send_gdb "break\n" 433gdb_expect { 434 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\ 435 {pass "break on default location, 3rd time"} 436 -re "$gdb_prompt $"\ 437 {fail "break on default location, 3rd time"} 438 timeout {fail "(timeout) break on default location, 3rd time"} 439} 440 441send_gdb "break\n" 442gdb_expect { 443 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\ 444 {pass "break on default location, 4th time"} 445 -re "$gdb_prompt $"\ 446 {fail "break on default location, 4th time"} 447 timeout {fail "(timeout) break on default location, 4th time"} 448} 449 450# Verify that a "silent" breakpoint can be set, and that GDB is indeed 451# "silent" about its triggering. 452# 453if ![runto_main] then { fail "break tests suppressed" } 454 455send_gdb "break $bp_location1\n" 456gdb_expect { 457 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\ 458 {pass "set to-be-silent break bp_location1"} 459 -re "$gdb_prompt $"\ 460 {fail "set to-be-silent break bp_location1"} 461 timeout {fail "(timeout) set to-be-silent break bp_location1"} 462} 463 464send_gdb "commands $expect_out(1,string)\n" 465send_gdb "silent\n" 466send_gdb "end\n" 467gdb_expect { 468 -re ".*$gdb_prompt $"\ 469 {pass "set silent break bp_location1"} 470 timeout {fail "(timeout) set silent break bp_location1"} 471} 472 473send_gdb "info break $expect_out(1,string)\n" 474gdb_expect { 475 -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\ 476 {pass "info silent break bp_location1"} 477 -re "$gdb_prompt $"\ 478 {fail "info silent break bp_location1"} 479 timeout {fail "(timeout) info silent break bp_location1"} 480} 481send_gdb "continue\n" 482gdb_expect { 483 -re "Continuing.\r\n$gdb_prompt $"\ 484 {pass "hit silent break bp_location1"} 485 -re "$gdb_prompt $"\ 486 {fail "hit silent break bp_location1"} 487 timeout {fail "(timeout) hit silent break bp_location1"} 488} 489send_gdb "bt\n" 490gdb_expect { 491 -re "#0 main .* at .*:$bp_location1.*$gdb_prompt $"\ 492 {pass "stopped for silent break bp_location1"} 493 -re "$gdb_prompt $"\ 494 {fail "stopped for silent break bp_location1"} 495 timeout {fail "(timeout) stopped for silent break bp_location1"} 496} 497 498# Verify that GDB can at least parse a breakpoint with the 499# "thread" keyword. (We won't attempt to test here that a 500# thread-specific breakpoint really triggers appropriately. 501# The gdb.threads subdirectory contains tests for that.) 502# 503set bp_location12 [gdb_get_line_number "set breakpoint 12 here"] 504send_gdb "break $bp_location12 thread 999\n" 505gdb_expect { 506 -re "Unknown thread 999.*$gdb_prompt $"\ 507 {pass "thread-specific breakpoint on non-existent thread disallowed"} 508 -re "$gdb_prompt $"\ 509 {fail "thread-specific breakpoint on non-existent thread disallowed"} 510 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"} 511} 512send_gdb "break $bp_location12 thread foo\n" 513gdb_expect { 514 -re "Junk after thread keyword..*$gdb_prompt $"\ 515 {pass "thread-specific breakpoint on bogus thread ID disallowed"} 516 -re "$gdb_prompt $"\ 517 {fail "thread-specific breakpoint on bogus thread ID disallowed"} 518 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"} 519} 520 521# Verify that GDB responds gracefully to a breakpoint command with 522# trailing garbage. 523# 524send_gdb "break $bp_location12 foo\n" 525gdb_expect { 526 -re "Junk at end of arguments..*$gdb_prompt $"\ 527 {pass "breakpoint with trailing garbage disallowed"} 528 -re "$gdb_prompt $"\ 529 {fail "breakpoint with trailing garbage disallowed"} 530 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"} 531} 532 533# Verify that GDB responds gracefully to a "clear" command that has 534# no matching breakpoint. (First, get us off the current source line, 535# which we know has a breakpoint.) 536# 537send_gdb "next\n" 538gdb_expect { 539 -re ".*$gdb_prompt $"\ 540 {pass "step over breakpoint"} 541 timeout {fail "(timeout) step over breakpoint"} 542} 543send_gdb "clear 81\n" 544gdb_expect { 545 -re "No breakpoint at 81..*$gdb_prompt $"\ 546 {pass "clear line has no breakpoint disallowed"} 547 -re "$gdb_prompt $"\ 548 {fail "clear line has no breakpoint disallowed"} 549 timeout {fail "(timeout) clear line has no breakpoint disallowed"} 550} 551send_gdb "clear\n" 552gdb_expect { 553 -re "No breakpoint at this line..*$gdb_prompt $"\ 554 {pass "clear current line has no breakpoint disallowed"} 555 -re "$gdb_prompt $"\ 556 {fail "clear current line has no breakpoint disallowed"} 557 timeout {fail "(timeout) clear current line has no breakpoint disallowed"} 558} 559 560# Verify that we can set and clear multiple breakpoints. 561# 562# We don't test that it deletes the correct breakpoints. We do at 563# least test that it deletes more than one breakpoint. 564# 565gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1" 566gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2" 567gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*} 568 569# Verify that a breakpoint can be set via a convenience variable. 570# 571send_gdb "set \$foo=$bp_location11\n" 572gdb_expect { 573 -re "$gdb_prompt $"\ 574 {pass "set convenience variable \$foo to bp_location11"} 575 timeout {fail "(timeout) set convenience variable \$foo to bp_location11"} 576} 577send_gdb "break \$foo\n" 578gdb_expect { 579 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\ 580 {pass "set breakpoint via convenience variable"} 581 -re "$gdb_prompt $"\ 582 {fail "set breakpoint via convenience variable"} 583 timeout {fail "(timeout) set breakpoint via convenience variable"} 584} 585 586# Verify that GDB responds gracefully to an attempt to set a 587# breakpoint via a convenience variable whose type is not integer. 588# 589send_gdb "set \$foo=81.5\n" 590gdb_expect { 591 -re "$gdb_prompt $"\ 592 {pass "set convenience variable \$foo to 81.5"} 593 timeout {fail "(timeout) set convenience variable \$foo to 81.5"} 594} 595send_gdb "break \$foo\n" 596gdb_expect { 597 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\ 598 {pass "set breakpoint via non-integer convenience variable disallowed"} 599 -re "$gdb_prompt $"\ 600 {fail "set breakpoint via non-integer convenience variable disallowed"} 601 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"} 602} 603 604# Verify that we can set and trigger a breakpoint in a user-called function. 605# 606send_gdb "break marker2\n" 607gdb_expect { 608 -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\ 609 {pass "set breakpoint on to-be-called function"} 610 -re "$gdb_prompt $"\ 611 {fail "set breakpoint on to-be-called function"} 612 timeout {fail "(timeout) set breakpoint on to-be-called function"} 613} 614send_gdb "print marker2(99)\n" 615gdb_expect { 616 -re "The program being debugged stopped while in a function called from GDB.\r\nWhen the function .marker2$proto. is done executing, GDB will silently\r\nstop .instead of continuing to evaluate the expression containing\r\nthe function call...*$gdb_prompt $"\ 617 {pass "hit breakpoint on called function"} 618 -re "$gdb_prompt $"\ 619 {fail "hit breakpoint on called function"} 620 timeout {fail "(timeout) hit breakpoint on called function"} 621} 622 623# As long as we're stopped (breakpointed) in a called function, 624# verify that we can successfully backtrace & such from here. 625# 626# In this and the following test, the _sr4export check apparently is needed 627# for hppa*-*-hpux. 628# 629send_gdb "bt\n" 630gdb_expect { 631 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\ 632 {pass "backtrace while in called function"} 633 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\ 634 {pass "backtrace while in called function"} 635 -re "$gdb_prompt $"\ 636 {fail "backtrace while in called function"} 637 timeout {fail "(timeout) backtrace while in called function"} 638} 639 640# Return from the called function. For remote targets, it's important to do 641# this before runto_main, which otherwise may silently stop on the dummy 642# breakpoint inserted by GDB at the program's entry point. 643# 644send_gdb "finish\n" 645gdb_expect { 646 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\ 647 {pass "finish from called function"} 648 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\ 649 {pass "finish from called function"} 650 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\ 651 {pass "finish from called function"} 652 -re "$gdb_prompt $"\ 653 {fail "finish from called function"} 654 timeout {fail "(timeout) finish from called function"} 655} 656 657# Verify that GDB responds gracefully to a "finish" command with 658# arguments. 659# 660if ![runto_main] then { fail "break tests suppressed" } 661 662send_gdb "finish 123\n" 663gdb_expect { 664 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\ 665 {pass "finish with arguments disallowed"} 666 -re "$gdb_prompt $"\ 667 {fail "finish with arguments disallowed"} 668 timeout {fail "(timeout) finish with arguments disallowed"} 669} 670 671# Verify that GDB responds gracefully to a request to "finish" from 672# the outermost frame. On a stub that never exits, this will just 673# run to the stubs routine, so we don't get this error... Thus the 674# second condition. 675# 676 677send_gdb "finish\n" 678gdb_expect { 679 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\ 680 {pass "finish from outermost frame disallowed"} 681 -re "Run till exit from.*\r\n$gdb_prompt $" { 682 pass "finish from outermost frame disallowed" 683 } 684 -re "$gdb_prompt $"\ 685 {fail "finish from outermost frame disallowed"} 686 timeout {fail "(timeout) finish from outermost frame disallowed"} 687} 688 689# Verify that we can explicitly ask GDB to stop on all shared library 690# events, and that it does so. 691# 692if [istarget "hppa*-*-hpux*"] then { 693 if ![runto_main] then { fail "break tests suppressed" } 694 695 send_gdb "set stop-on-solib-events 1\n" 696 gdb_expect { 697 -re "$gdb_prompt $"\ 698 {pass "set stop-on-solib-events"} 699 timeout {fail "(timeout) set stop-on-solib-events"} 700 } 701 702 send_gdb "run\n" 703 gdb_expect { 704 -re ".*Start it from the beginning.*y or n. $"\ 705 {send_gdb "y\n" 706 gdb_expect { 707 -re ".*Stopped due to shared library event.*$gdb_prompt $"\ 708 {pass "triggered stop-on-solib-events"} 709 -re "$gdb_prompt $"\ 710 {fail "triggered stop-on-solib-events"} 711 timeout {fail "(timeout) triggered stop-on-solib-events"} 712 } 713 } 714 -re "$gdb_prompt $"\ 715 {fail "rerun for stop-on-solib-events"} 716 timeout {fail "(timeout) rerun for stop-on-solib-events"} 717 } 718 719 send_gdb "set stop-on-solib-events 0\n" 720 gdb_expect { 721 -re "$gdb_prompt $"\ 722 {pass "reset stop-on-solib-events"} 723 timeout {fail "(timeout) reset stop-on-solib-events"} 724 } 725} 726 727# Hardware breakpoints are unsupported on HP-UX. Verify that GDB 728# gracefully responds to requests to create them. 729# 730if [istarget "hppa*-*-hpux*"] then { 731 if ![runto_main] then { fail "break tests suppressed" } 732 733 send_gdb "hbreak\n" 734 gdb_expect { 735 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\ 736 {pass "hw breaks disallowed"} 737 -re "$gdb_prompt $"\ 738 {fail "hw breaks disallowed"} 739 timeout {fail "(timeout) hw breaks disallowed"} 740 } 741 742 send_gdb "thbreak\n" 743 gdb_expect { 744 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\ 745 {pass "temporary hw breaks disallowed"} 746 -re "$gdb_prompt $"\ 747 {fail "temporary hw breaks disallowed"} 748 timeout {fail "(timeout) temporary hw breaks disallowed"} 749 } 750} 751 752#******** 753 754 755# 756# Test "next" over recursive function call. 757# 758 759proc test_next_with_recursion {} { 760 global gdb_prompt 761 global decimal 762 global binfile 763 764 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y" 765 delete_breakpoints 766 767 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial" 768 769 # Run until we call factorial with 6 770 771 gdb_run_cmd 772 gdb_expect { 773 -re "Break.* factorial .value=6. .*$gdb_prompt $" {} 774 -re ".*$gdb_prompt $" { 775 fail "run to factorial(6)"; 776 gdb_suppress_tests; 777 } 778 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests } 779 } 780 781 # Continue until we call factorial recursively with 5. 782 783 if [gdb_test "continue" \ 784 "Continuing.*Break.* factorial .value=5. .*" \ 785 "continue to factorial(5)"] then { gdb_suppress_tests } 786 787 # Do a backtrace just to confirm how many levels deep we are. 788 789 if [gdb_test "backtrace" \ 790 "#0\[ \t\]+ factorial .value=5..*" \ 791 "backtrace from factorial(5)"] then { gdb_suppress_tests } 792 793 # Now a "next" should position us at the recursive call, which 794 # we will be performing with 4. 795 796 if [gdb_test "next" \ 797 ".* factorial .value - 1.;.*" \ 798 "next to recursive call"] then { gdb_suppress_tests } 799 800 # Disable the breakpoint at the entry to factorial by deleting them all. 801 # The "next" should run until we return to the next line from this 802 # recursive call to factorial with 4. 803 # Buggy versions of gdb will stop instead at the innermost frame on 804 # the line where we are trying to "next" to. 805 806 delete_breakpoints 807 808 if [istarget "mips*tx39-*"] { 809 set timeout 60 810 } 811 # We used to set timeout here for all other targets as well. This 812 # is almost certainly wrong. The proper timeout depends on the 813 # target system in use, and how we communicate with it, so there 814 # is no single value appropriate for all targets. The timeout 815 # should be established by the Dejagnu config file(s) for the 816 # board, and respected by the test suite. 817 # 818 # For example, if I'm running GDB over an SSH tunnel talking to a 819 # portmaster in California talking to an ancient 68k board running 820 # a crummy ROM monitor (a situation I can only wish were 821 # hypothetical), then I need a large timeout. But that's not the 822 # kind of knowledge that belongs in this file. 823 824 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \ 825 "next over recursive call" 826 827 # OK, we should be back in the same stack frame we started from. 828 # Do a backtrace just to confirm. 829 830 set result [gdb_test "backtrace" \ 831 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \ 832 "backtrace from factorial(5.1)"] 833 if { $result != 0 } { gdb_suppress_tests } 834 835 if [target_info exists gdb,noresults] { gdb_suppress_tests } 836 gdb_continue_to_end "recursive next test" 837 gdb_stop_suppressing_tests; 838} 839 840test_next_with_recursion 841 842 843#******** 844 845# build a new file with optimization enabled so that we can try breakpoints 846# on targets with optimized prologues 847 848set binfileo2 ${objdir}/${subdir}/${testfile}o2 849 850if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}O0.o" object {debug nowarnings optimize=-O2}] != "" } { 851 untested break.exp 852 return -1 853} 854 855if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}O1.o" object {debug nowarnings optimize=-O2}] != "" } { 856 untested break.exp 857 return -1 858} 859 860if { [gdb_compile "${binfile}O0.o ${binfile}O1.o" "${binfileo2}" executable {debug nowarnings}] != "" } { 861 untested break.exp 862 return -1 863} 864 865if [get_compiler_info ${binfileo2}] { 866 return -1 867} 868 869gdb_exit 870gdb_start 871gdb_reinitialize_dir $srcdir/$subdir 872gdb_load ${binfileo2} 873 874if [target_info exists gdb_stub] { 875 gdb_step_for_stub; 876} 877 878# 879# test break at function 880# 881gdb_test "break main" \ 882 "Breakpoint.*at.* file .*, line.*" \ 883 "breakpoint function, optimized file" 884 885# 886# test break at function 887# 888gdb_test "break marker4" \ 889 "Breakpoint.*at.* file .*$srcfile1, line.*" \ 890 "breakpoint small function, optimized file" 891 892# 893# run until the breakpoint at main is hit. For non-stubs-using targets. 894# 895gdb_run_cmd 896gdb_expect { 897 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" { 898 pass "run until function breakpoint, optimized file" 899 } 900 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $" { 901 pass "run until function breakpoint, optimized file (code motion)" 902 } 903 -re "$gdb_prompt $" { 904 fail "run until function breakpoint, optimized file" 905 } 906 timeout { 907 fail "run until function breakpoint, optimized file (timeout)" 908 } 909} 910 911# 912# run until the breakpoint at a small function 913# 914 915# 916# Add a second pass pattern. The behavior differs here between stabs 917# and dwarf for one-line functions. Stabs preserves two line symbols 918# (one before the prologue and one after) with the same line number, 919# but dwarf regards these as duplicates and discards one of them. 920# Therefore the address after the prologue (where the breakpoint is) 921# has no exactly matching line symbol, and GDB reports the breakpoint 922# as if it were in the middle of a line rather than at the beginning. 923 924set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1] 925set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1] 926send_gdb "continue\n" 927gdb_expect { 928 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" { 929 pass "run until breakpoint set at small function, optimized file" 930 } 931 -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" { 932 pass "run until breakpoint set at small function, optimized file" 933 } 934 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" { 935 # marker4() is defined at line 46 when compiled with -DPROTOTYPES 936 pass "run until breakpoint set at small function, optimized file (line bp_location14)" 937 } 938 -re ".*$gdb_prompt " { 939 fail "run until breakpoint set at small function, optimized file" 940 } 941 timeout { 942 fail "run until breakpoint set at small function, optimized file (timeout)" 943 } 944} 945 946 947# Reset the default arguments for VxWorks 948if [istarget "*-*-vxworks*"] { 949 set timeout 10 950 verbose "Timeout is now $timeout seconds" 2 951 send_gdb "set args main\n" 952 gdb_expect -re ".*$gdb_prompt $" {} 953} 954