1 # Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
2 # 2000, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
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 2 of the License, or
7 # (at your option) any later version.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # Based on break.exp, written by Rob Savoye. (rob@cygnus.com)
22 # Modified to test gdb's handling of separate debug info files.
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.
35 # test running programs
40 set testfile "sepdebug"
41 set srcfile ${testfile}.c
42 set binfile ${objdir}/${subdir}/${testfile}
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
49 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
50 # ${binfile}, which is just like the executable ($binfile) but without
51 # the debuginfo. Instead $binfile has a .gnudebuglink section which contains
52 # the name of a debuginfo only file. This file will be stored in the
53 # gdb.base/.debug subdirectory.
55 if [gdb_gnu_strip_debug $binfile] {
56 # check that you have a recent version of strip and objcopy installed
57 unsupported "cannot produce separate debug info files"
63 gdb_reinitialize_dir $srcdir/$subdir
66 if [target_info exists gdb_stub] {
70 # test simple breakpoint setting commands
73 # Test deleting all breakpoints when there are none installed,
74 # GDB should not prompt for confirmation.
75 # Note that gdb-init.exp provides a "delete_breakpoints" proc
76 # for general use elsewhere.
78 send_gdb "delete breakpoints\n"
80 -re "Delete all breakpoints.*$" {
84 fail "Delete all breakpoints when none (unexpected prompt)"
86 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
89 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
90 timeout { fail "Delete all breakpoints when none (timeout)" }
94 # test break at function
96 gdb_test "break main" \
97 "Breakpoint.*at.* file .*$srcfile, line.*" \
101 # test break at quoted function
103 gdb_test "break \"marker2\"" \
104 "Breakpoint.*at.* file .*$srcfile, line.*" \
105 "breakpoint quoted function"
108 # test break at function in file
110 gdb_test "break $srcfile:factorial" \
111 "Breakpoint.*at.* file .*$srcfile, line.*" \
112 "breakpoint function in file"
114 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
117 # test break at line number
119 # Note that the default source file is the last one whose source text
120 # was printed. For native debugging, before we've executed the
121 # program, this is the file containing main, but for remote debugging,
122 # it's wherever the processor was stopped when we connected to the
123 # board. So, to be sure, we do a list command.
125 gdb_test "list main" \
126 ".*main \\(argc, argv, envp\\).*" \
127 "use `list' to establish default source file"
128 gdb_test "break $bp_location1" \
129 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
130 "breakpoint line number"
133 # test duplicate breakpoint
135 gdb_test "break $bp_location1" \
136 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
137 "breakpoint duplicate"
139 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
142 # test break at line number in file
144 gdb_test "break $srcfile:$bp_location2" \
145 "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
146 "breakpoint line number in file"
148 set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
149 set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
152 # Test putting a break at the start of a multi-line if conditional.
153 # Verify the breakpoint was put at the start of the conditional.
155 gdb_test "break multi_line_if_conditional" \
156 "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
157 "breakpoint at start of multi line if conditional"
159 gdb_test "break multi_line_while_conditional" \
160 "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
161 "breakpoint at start of multi line while conditional"
163 set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
164 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
167 # check to see what breakpoints are set
169 if [target_info exists gdb_stub] {
170 set main_line $bp_location5
172 set main_line $bp_location6
175 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
176 set bp_location8 [gdb_get_line_number "set breakpoint 8 here"]
177 set bp_location9 [gdb_get_line_number "set breakpoint 9 here"]
179 gdb_test "info break" \
180 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
181 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
182 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile:($bp_location8|$bp_location9).*
183 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:$bp_location7.*
184 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
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_location2.*
187 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
188 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
191 # FIXME: The rest of this test doesn't work with anything that can't
193 # Huh? There doesn't *appear* to be anything that passes arguments
195 if [istarget "mips-idt-*"] then {
200 # run until the breakpoint at main is hit. For non-stubs-using targets.
202 if ![target_info exists use_gdb_stub] {
203 if [istarget "*-*-vxworks*"] then {
204 send_gdb "run vxmain \"2\"\n"
206 verbose "Timeout is now $timeout seconds" 2
211 -re "The program .* has been started already.*y or n. $" {
215 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
216 { pass "run until function breakpoint" }
217 -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
218 timeout { fail "run until function breakpoint (timeout)" }
221 if ![target_info exists gdb_stub] {
222 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue"
227 # run until the breakpoint at a line number
229 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
230 "run until breakpoint set at a line number"
233 # Run until the breakpoint set in a function in a file
235 for {set i 6} {$i >= 1} {incr i -1} {
236 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
237 "run until file:function($i) breakpoint"
241 # Run until the breakpoint set at a quoted function
243 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile:($bp_location8|$bp_location9).*" \
244 "run until quoted breakpoint"
246 # run until the file:function breakpoint at a line number in a file
248 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
249 "run until file:linenum breakpoint"
251 # Test break at offset +1
252 set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
254 gdb_test "break +1" \
255 "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
256 "breakpoint offset +1"
258 # Check to see if breakpoint is hit when stepped onto
261 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
262 "step onto breakpoint"
265 # delete all breakpoints so we can start over, course this can be a test too
270 # test temporary breakpoint at function
273 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
276 # test break at function in file
279 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
280 "Temporary breakpoint function in file"
283 # test break at line number
285 send_gdb "tbreak $bp_location1\n"
287 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
288 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
289 timeout { fail "breakpoint line number #1 (timeout)" }
292 gdb_test "tbreak $bp_location6" "Breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
295 # test break at line number in file
297 send_gdb "tbreak $srcfile:$bp_location2\n"
299 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
300 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
301 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
304 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
305 gdb_test "tbreak $srcfile:$bp_location11" "Breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
308 # check to see what breakpoints are set (temporary this time)
310 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
311 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
312 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:$bp_location7.*\[\r\n\]
313 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
314 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
315 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
316 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
317 "Temporary breakpoint info"
322 # Verify that catchpoints for fork, vfork and exec don't trigger
323 # inappropriately. (There are no calls to those system functions
324 # in this test program.)
326 if ![runto_main] then { fail "break tests suppressed" }
330 -re "Catch requires an event name.*$gdb_prompt $"\
331 {pass "catch requires an event name"}
333 {fail "catch requires an event name"}
334 timeout {fail "(timeout) catch requires an event name"}
338 set name "set catch fork, never expected to trigger"
339 send_gdb "catch fork\n"
341 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
343 -re "Catch of fork not yet implemented.*$gdb_prompt $"
347 timeout {fail "(timeout) $name"}
351 set name "set catch vfork, never expected to trigger"
352 send_gdb "catch vfork\n"
354 # If we are on HP-UX 10.20, we expect an error message to be
355 # printed if we type "catch vfork" at the gdb gdb_prompt. This is
356 # because on HP-UX 10.20, we cannot catch vfork events.
358 if [istarget "hppa*-hp-hpux10.20"] then {
360 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
364 timeout {fail "(timeout) $name"}
368 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
370 -re "Catch of vfork not yet implemented.*$gdb_prompt $"
374 timeout {fail "(timeout) $name"}
378 set name "set catch exec, never expected to trigger"
379 send_gdb "catch exec\n"
381 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
383 -re "Catch of exec not yet implemented.*$gdb_prompt $"
385 -re "$gdb_prompt $" {fail $name}
386 timeout {fail "(timeout) $name"}
389 # Verify that GDB responds gracefully when asked to set a breakpoint
390 # on a nonexistent source line.
392 send_gdb "break 999\n"
394 -re "No line 999 in file .*$gdb_prompt $"\
395 {pass "break on non-existent source line"}
397 {fail "break on non-existent source line"}
398 timeout {fail "(timeout) break on non-existent source line"}
401 # Run to the desired default location. If not positioned here, the
402 # tests below don't work.
404 gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
407 # Verify that GDB allows one to just say "break", which is treated
408 # as the "default" breakpoint. Note that GDB gets cute when printing
409 # the informational message about other breakpoints at the same
410 # location. We'll hit that bird with this stone too.
414 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
415 {pass "break on default location, 1st time"}
417 {fail "break on default location, 1st time"}
418 timeout {fail "(timeout) break on default location, 1st time"}
423 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
424 {pass "break on default location, 2nd time"}
426 {fail "break on default location, 2nd time"}
427 timeout {fail "(timeout) break on default location, 2nd time"}
432 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
433 {pass "break on default location, 3rd time"}
435 {fail "break on default location, 3rd time"}
436 timeout {fail "(timeout) break on default location, 3rd time"}
441 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
442 {pass "break on default location, 4th time"}
444 {fail "break on default location, 4th time"}
445 timeout {fail "(timeout) break on default location, 4th time"}
448 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
449 # "silent" about its triggering.
451 if ![runto_main] then { fail "break tests suppressed" }
453 send_gdb "break $bp_location1\n"
455 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
456 {pass "set to-be-silent break bp_location1"}
458 {fail "set to-be-silent break bp_location1"}
459 timeout {fail "(timeout) set to-be-silent break bp_location1"}
462 send_gdb "commands $expect_out(1,string)\n"
466 -re ".*$gdb_prompt $"\
467 {pass "set silent break bp_location1"}
468 timeout {fail "(timeout) set silent break bp_location1"}
471 send_gdb "info break $expect_out(1,string)\n"
473 -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
474 {pass "info silent break bp_location1"}
476 {fail "info silent break bp_location1"}
477 timeout {fail "(timeout) info silent break bp_location1"}
479 send_gdb "continue\n"
481 -re "Continuing.\r\n$gdb_prompt $"\
482 {pass "hit silent break bp_location1"}
484 {fail "hit silent break bp_location1"}
485 timeout {fail "(timeout) hit silent break bp_location1"}
489 -re "#0 main .* at .*:$bp_location1.*$gdb_prompt $"\
490 {pass "stopped for silent break bp_location1"}
492 {fail "stopped for silent break bp_location1"}
493 timeout {fail "(timeout) stopped for silent break bp_location1"}
496 # Verify that GDB can at least parse a breakpoint with the
497 # "thread" keyword. (We won't attempt to test here that a
498 # thread-specific breakpoint really triggers appropriately.
499 # The gdb.threads subdirectory contains tests for that.)
501 set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
502 send_gdb "break $bp_location12 thread 999\n"
504 -re "Unknown thread 999.*$gdb_prompt $"\
505 {pass "thread-specific breakpoint on non-existent thread disallowed"}
507 {fail "thread-specific breakpoint on non-existent thread disallowed"}
508 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
510 send_gdb "break $bp_location12 thread foo\n"
512 -re "Junk after thread keyword..*$gdb_prompt $"\
513 {pass "thread-specific breakpoint on bogus thread ID disallowed"}
515 {fail "thread-specific breakpoint on bogus thread ID disallowed"}
516 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
519 # Verify that GDB responds gracefully to a breakpoint command with
522 send_gdb "break $bp_location12 foo\n"
524 -re "Junk at end of arguments..*$gdb_prompt $"\
525 {pass "breakpoint with trailing garbage disallowed"}
527 {fail "breakpoint with trailing garbage disallowed"}
528 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
531 # Verify that GDB responds gracefully to a "clear" command that has
532 # no matching breakpoint. (First, get us off the current source line,
533 # which we know has a breakpoint.)
537 -re ".*$gdb_prompt $"\
538 {pass "step over breakpoint"}
539 timeout {fail "(timeout) step over breakpoint"}
541 send_gdb "clear 81\n"
543 -re "No breakpoint at 81..*$gdb_prompt $"\
544 {pass "clear line has no breakpoint disallowed"}
546 {fail "clear line has no breakpoint disallowed"}
547 timeout {fail "(timeout) clear line has no breakpoint disallowed"}
551 -re "No breakpoint at this line..*$gdb_prompt $"\
552 {pass "clear current line has no breakpoint disallowed"}
554 {fail "clear current line has no breakpoint disallowed"}
555 timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
558 # Verify that we can set and clear multiple breakpoints.
560 # We don't test that it deletes the correct breakpoints. We do at
561 # least test that it deletes more than one breakpoint.
563 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
564 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
565 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
567 # Verify that a breakpoint can be set via a convenience variable.
569 send_gdb "set \$foo=$bp_location11\n"
572 {pass "set convenience variable \$foo to bp_location11"}
573 timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
575 send_gdb "break \$foo\n"
577 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
578 {pass "set breakpoint via convenience variable"}
580 {fail "set breakpoint via convenience variable"}
581 timeout {fail "(timeout) set breakpoint via convenience variable"}
584 # Verify that GDB responds gracefully to an attempt to set a
585 # breakpoint via a convenience variable whose type is not integer.
587 send_gdb "set \$foo=81.5\n"
590 {pass "set convenience variable \$foo to 81.5"}
591 timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
593 send_gdb "break \$foo\n"
595 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
596 {pass "set breakpoint via non-integer convenience variable disallowed"}
598 {fail "set breakpoint via non-integer convenience variable disallowed"}
599 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
602 # Verify that we can set and trigger a breakpoint in a user-called function.
604 send_gdb "break marker2\n"
606 -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
607 {pass "set breakpoint on to-be-called function"}
609 {fail "set breakpoint on to-be-called function"}
610 timeout {fail "(timeout) set breakpoint on to-be-called function"}
612 send_gdb "print marker2(99)\n"
614 -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 $"\
615 {pass "hit breakpoint on called function"}
617 {fail "hit breakpoint on called function"}
618 timeout {fail "(timeout) hit breakpoint on called function"}
621 # As long as we're stopped (breakpointed) in a called function,
622 # verify that we can successfully backtrace & such from here.
624 # In this and the following test, the _sr4export check apparently is needed
629 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
630 {pass "backtrace while in called function"}
631 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
632 {pass "backtrace while in called function"}
634 {fail "backtrace while in called function"}
635 timeout {fail "(timeout) backtrace while in called function"}
638 # Return from the called function. For remote targets, it's important to do
639 # this before runto_main, which otherwise may silently stop on the dummy
640 # breakpoint inserted by GDB at the program's entry point.
644 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
645 {pass "finish from called function"}
646 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
647 {pass "finish from called function"}
648 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
649 {pass "finish from called function"}
651 {fail "finish from called function"}
652 timeout {fail "(timeout) finish from called function"}
655 # Verify that GDB responds gracefully to a "finish" command with
658 if ![runto_main] then { fail "break tests suppressed" }
660 send_gdb "finish 123\n"
662 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
663 {pass "finish with arguments disallowed"}
665 {fail "finish with arguments disallowed"}
666 timeout {fail "(timeout) finish with arguments disallowed"}
669 # Verify that GDB responds gracefully to a request to "finish" from
670 # the outermost frame. On a stub that never exits, this will just
671 # run to the stubs routine, so we don't get this error... Thus the
677 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
678 {pass "finish from outermost frame disallowed"}
679 -re "Run till exit from.*\r\n$gdb_prompt $" {
680 pass "finish from outermost frame disallowed"
683 {fail "finish from outermost frame disallowed"}
684 timeout {fail "(timeout) finish from outermost frame disallowed"}
687 # Verify that we can explicitly ask GDB to stop on all shared library
688 # events, and that it does so.
690 if [istarget "hppa*-*-hpux*"] then {
691 if ![runto_main] then { fail "break tests suppressed" }
693 send_gdb "set stop-on-solib-events 1\n"
696 {pass "set stop-on-solib-events"}
697 timeout {fail "(timeout) set stop-on-solib-events"}
702 -re ".*Start it from the beginning.*y or n. $"\
705 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
706 {pass "triggered stop-on-solib-events"}
708 {fail "triggered stop-on-solib-events"}
709 timeout {fail "(timeout) triggered stop-on-solib-events"}
713 {fail "rerun for stop-on-solib-events"}
714 timeout {fail "(timeout) rerun for stop-on-solib-events"}
717 send_gdb "set stop-on-solib-events 0\n"
720 {pass "reset stop-on-solib-events"}
721 timeout {fail "(timeout) reset stop-on-solib-events"}
725 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
726 # gracefully responds to requests to create them.
728 if [istarget "hppa*-*-hpux*"] then {
729 if ![runto_main] then { fail "break tests suppressed" }
733 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
734 {pass "hw breaks disallowed"}
736 {fail "hw breaks disallowed"}
737 timeout {fail "(timeout) hw breaks disallowed"}
742 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
743 {pass "temporary hw breaks disallowed"}
745 {fail "temporary hw breaks disallowed"}
746 timeout {fail "(timeout) temporary hw breaks disallowed"}
754 # Test "next" over recursive function call.
757 proc test_next_with_recursion {} {
762 if [target_info exists use_gdb_stub] {
763 # Reload the program.
767 # FIXME: should be using runto
768 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
773 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
775 # Run until we call factorial with 6
777 if [istarget "*-*-vxworks*"] then {
778 send_gdb "run vxmain \"6\"\n"
783 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
784 -re ".*$gdb_prompt $" {
785 fail "run to factorial(6)";
788 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
791 # Continue until we call factorial recursively with 5.
793 if [gdb_test "continue" \
794 "Continuing.*Break.* factorial .value=5. .*" \
795 "continue to factorial(5)"] then { gdb_suppress_tests }
797 # Do a backtrace just to confirm how many levels deep we are.
799 if [gdb_test "backtrace" \
800 "#0\[ \t\]+ factorial .value=5..*" \
801 "backtrace from factorial(5)"] then { gdb_suppress_tests }
803 # Now a "next" should position us at the recursive call, which
804 # we will be performing with 4.
806 if [gdb_test "next" \
807 ".* factorial .value - 1.;.*" \
808 "next to recursive call"] then { gdb_suppress_tests }
810 # Disable the breakpoint at the entry to factorial by deleting them all.
811 # The "next" should run until we return to the next line from this
812 # recursive call to factorial with 4.
813 # Buggy versions of gdb will stop instead at the innermost frame on
814 # the line where we are trying to "next" to.
818 if [istarget "mips*tx39-*"] {
821 # We used to set timeout here for all other targets as well. This
822 # is almost certainly wrong. The proper timeout depends on the
823 # target system in use, and how we communicate with it, so there
824 # is no single value appropriate for all targets. The timeout
825 # should be established by the Dejagnu config file(s) for the
826 # board, and respected by the test suite.
828 # For example, if I'm running GDB over an SSH tunnel talking to a
829 # portmaster in California talking to an ancient 68k board running
830 # a crummy ROM monitor (a situation I can only wish were
831 # hypothetical), then I need a large timeout. But that's not the
832 # kind of knowledge that belongs in this file.
834 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
835 "next over recursive call"
837 # OK, we should be back in the same stack frame we started from.
838 # Do a backtrace just to confirm.
840 set result [gdb_test "backtrace" \
841 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
842 "backtrace from factorial(5.1)"]
843 if { $result != 0 } { gdb_suppress_tests }
845 if [target_info exists gdb,noresults] { gdb_suppress_tests }
846 gdb_continue_to_end "recursive next test"
847 gdb_stop_suppressing_tests;
850 test_next_with_recursion
855 # now move the .debug file to a different location so that we can test
856 # the "set debug-file-directory" command.
858 remote_exec build "mv ${objdir}/${subdir}/.debug/${testfile}.debug ${objdir}/${subdir}"
861 gdb_reinitialize_dir $srcdir/$subdir
862 gdb_test "set debug-file-directory ${objdir}/${subdir}" ".*" "set separate debug location"
865 if [target_info exists gdb_stub] {
870 # test break at function
872 gdb_test "break main" \
873 "Breakpoint.*at.* file .*$srcfile, line.*" \
874 "breakpoint function, optimized file"
877 # test break at function
879 gdb_test "break marker4" \
880 "Breakpoint.*at.* file .*$srcfile, line.*" \
881 "breakpoint small function, optimized file"
884 # run until the breakpoint at main is hit. For non-stubs-using targets.
886 if ![target_info exists use_gdb_stub] {
887 if [istarget "*-*-vxworks*"] then {
888 send_gdb "run vxmain \"2\"\n"
890 verbose "Timeout is now $timeout seconds" 2
895 -re "The program .* has been started already.*y or n. $" {
899 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
900 { pass "run until function breakpoint, optimized file" }
901 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $"\
902 { pass "run until function breakpoint, optimized file (code motion)" }
903 -re ".*$gdb_prompt $" { fail "run until function breakpoint, optimized file" }
904 timeout { fail "run until function breakpoint, optimized file (timeout)" }
907 if ![target_info exists gdb_stub] {
908 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue, optimized file"
913 # run until the breakpoint at a small function
917 # Add a second pass pattern. The behavior differs here between stabs
918 # and dwarf for one-line functions. Stabs preserves two line symbols
919 # (one before the prologue and one after) with the same line number,
920 # but dwarf regards these as duplicates and discards one of them.
921 # Therefore the address after the prologue (where the breakpoint is)
922 # has no exactly matching line symbol, and GDB reports the breakpoint
923 # as if it were in the middle of a line rather than at the beginning.
925 set bp_location13 [gdb_get_line_number "set breakpoint 13 here"]
926 set bp_location14 [gdb_get_line_number "set breakpoint 14 here"]
927 send_gdb "continue\n"
929 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
930 pass "run until breakpoint set at small function, optimized file"
932 -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
933 pass "run until breakpoint set at small function, optimized file"
935 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
936 # marker4() is defined at line 46 when compiled with -DPROTOTYPES
937 pass "run until breakpoint set at small function, optimized file (line bp_location14)"
939 -re ".*$gdb_prompt " {
940 fail "run until breakpoint set at small function, optimized file"
943 fail "run until breakpoint set at small function, optimized file (timeout)"
948 # Reset the default arguments for VxWorks
949 if [istarget "*-*-vxworks*"] {
951 verbose "Timeout is now $timeout seconds" 2
952 send_gdb "set args main\n"
953 gdb_expect -re ".*$gdb_prompt $" {}