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