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