1 # Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
2 # 2000, 2002, 2003, 2004
3 # Free Software Foundation, Inc.
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.
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.
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.
19 # Please email any bugs, comments, and/or additions to this file to:
20 # bug-gdb@prep.ai.mit.edu
22 # Based on break.exp, written by Rob Savoye. (rob@cygnus.com)
23 # Modified to test gdb's handling of separate debug info files.
25 # This file has two parts. The first is testing that gdb behaves
26 # normally after reading in an executable and its corresponding
27 # separate debug file. The second moves the .debug file to a different
28 # location and tests the "set debug-file-directory" command.
36 # test running programs
41 set testfile "sepdebug"
42 set srcfile ${testfile}.c
43 set binfile ${objdir}/${subdir}/${testfile}
45 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
46 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
49 # FIXME: this is nasty. We need to check for the stabs debug format.
50 # To do this we must run gdb on the unstripped executable, list 'main'
51 # (as to have a default source file), use get_debug_format (which does
52 # 'info source') and then see if the debug info is stabs. If so, we
53 # bail out. We cannot do this any other way because get_debug_format
54 # finds out the debug format using gdb itself, and in case of stabs we
55 # get an error loading the program if it is already stripped. An
56 # alternative would be to find out the debug info from the flags
57 # passed to dejagnu when the test is run.
61 gdb_reinitialize_dir $srcdir/$subdir
63 gdb_test "list main" "" ""
65 if { [test_debug_format "stabs"] } then {
66 # the separate debug info feature doesn't work well in binutils with stabs.
67 # It produces a corrupted debug info only file, and gdb chokes on it.
68 # It is almost impossible to capture the failing message out of gdb,
69 # because it happens inside gdb_load. At that point any error message
70 # is intercepted by dejagnu itself, and, because of the error threshold,
71 # any faulty test result is changed into an UNRESOLVED.
72 # (see dejagnu/lib/framework.exp)
73 unsupported "no separate debug info handling with stabs"
78 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
79 # ${binfile}, which is just like the executable ($binfile) but without
80 # the debuginfo. Instead $binfile has a .gnudebuglink section which contains
81 # the name of a idebuginfo only file. This file will be stored in the
82 # gdb.base/.debug subdirectory.
84 if [gdb_gnu_strip_debug $binfile] {
85 unsupported "no separate debug info handling"
91 gdb_reinitialize_dir $srcdir/$subdir
94 if [target_info exists gdb_stub] {
98 # test simple breakpoint setting commands
101 # Test deleting all breakpoints when there are none installed,
102 # GDB should not prompt for confirmation.
103 # Note that gdb-init.exp provides a "delete_breakpoints" proc
104 # for general use elsewhere.
106 send_gdb "delete breakpoints\n"
108 -re "Delete all breakpoints.*$" {
111 -re "$gdb_prompt $" {
112 fail "Delete all breakpoints when none (unexpected prompt)"
114 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
117 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
118 timeout { fail "Delete all breakpoints when none (timeout)" }
122 # test break at function
124 gdb_test "break main" \
125 "Breakpoint.*at.* file .*$srcfile, line.*" \
126 "breakpoint function"
129 # test break at quoted function
131 gdb_test "break \"marker2\"" \
132 "Breakpoint.*at.* file .*$srcfile, line.*" \
133 "breakpoint quoted function"
136 # test break at function in file
138 gdb_test "break $srcfile:factorial" \
139 "Breakpoint.*at.* file .*$srcfile, line.*" \
140 "breakpoint function in file"
142 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
145 # test break at line number
147 # Note that the default source file is the last one whose source text
148 # was printed. For native debugging, before we've executed the
149 # program, this is the file containing main, but for remote debugging,
150 # it's wherever the processor was stopped when we connected to the
151 # board. So, to be sure, we do a list command.
153 gdb_test "list main" \
154 ".*main \\(argc, argv, envp\\).*" \
155 "use `list' to establish default source file"
156 gdb_test "break $bp_location1" \
157 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
158 "breakpoint line number"
161 # test duplicate breakpoint
163 gdb_test "break $bp_location1" \
164 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
165 "breakpoint duplicate"
167 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
170 # test break at line number in file
172 gdb_test "break $srcfile:$bp_location2" \
173 "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
174 "breakpoint line number in file"
176 set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
177 set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
180 # Test putting a break at the start of a multi-line if conditional.
181 # Verify the breakpoint was put at the start of the conditional.
183 gdb_test "break multi_line_if_conditional" \
184 "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
185 "breakpoint at start of multi line if conditional"
187 gdb_test "break multi_line_while_conditional" \
188 "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
189 "breakpoint at start of multi line while conditional"
191 set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
192 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
195 # check to see what breakpoints are set
197 if [target_info exists gdb_stub] {
198 set main_line $bp_location5
200 set main_line $bp_location6
203 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
204 set bp_location8 [gdb_get_line_number "set breakpoint 8 here"]
205 set bp_location9 [gdb_get_line_number "set breakpoint 9 here"]
207 gdb_test "info break" \
208 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
209 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
210 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile:($bp_location8|$bp_location9).*
211 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:$bp_location7.*
212 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
213 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
214 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location2.*
215 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
216 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
219 # FIXME: The rest of this test doesn't work with anything that can't
221 # Huh? There doesn't *appear* to be anything that passes arguments
223 if [istarget "mips-idt-*"] then {
228 # run until the breakpoint at main is hit. For non-stubs-using targets.
230 if ![target_info exists use_gdb_stub] {
231 if [istarget "*-*-vxworks*"] then {
232 send_gdb "run vxmain \"2\"\n"
234 verbose "Timeout is now $timeout seconds" 2
239 -re "The program .* has been started already.*y or n. $" {
243 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
244 { pass "run until function breakpoint" }
245 -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
246 timeout { fail "run until function breakpoint (timeout)" }
249 if ![target_info exists gdb_stub] {
250 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue"
255 # run until the breakpoint at a line number
257 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
258 "run until breakpoint set at a line number"
261 # Run until the breakpoint set in a function in a file
263 for {set i 6} {$i >= 1} {incr i -1} {
264 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
265 "run until file:function($i) breakpoint"
269 # Run until the breakpoint set at a quoted function
271 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile:($bp_location8|$bp_location9).*" \
272 "run until quoted breakpoint"
274 # run until the file:function breakpoint at a line number in a file
276 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
277 "run until file:linenum breakpoint"
279 # Test break at offset +1
280 set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
282 gdb_test "break +1" \
283 "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
284 "breakpoint offset +1"
286 # Check to see if breakpoint is hit when stepped onto
289 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
290 "step onto breakpoint"
293 # delete all breakpoints so we can start over, course this can be a test too
298 # test temporary breakpoint at function
301 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
304 # test break at function in file
307 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
308 "Temporary breakpoint function in file"
311 # test break at line number
313 send_gdb "tbreak $bp_location1\n"
315 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
316 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
317 timeout { fail "breakpoint line number #1 (timeout)" }
320 gdb_test "tbreak $bp_location6" "Breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
323 # test break at line number in file
325 send_gdb "tbreak $srcfile:$bp_location2\n"
327 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
328 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
329 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
332 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
333 gdb_test "tbreak $srcfile:$bp_location11" "Breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
336 # check to see what breakpoints are set (temporary this time)
338 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
339 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
340 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:$bp_location7.*\[\r\n\]
341 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
342 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
343 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
344 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
345 "Temporary breakpoint info"
350 # Verify that catchpoints for fork, vfork and exec don't trigger
351 # inappropriately. (There are no calls to those system functions
352 # in this test program.)
354 if ![runto_main] then { fail "break tests suppressed" }
358 -re "Catch requires an event name.*$gdb_prompt $"\
359 {pass "catch requires an event name"}
361 {fail "catch requires an event name"}
362 timeout {fail "(timeout) catch requires an event name"}
366 set name "set catch fork, never expected to trigger"
367 send_gdb "catch fork\n"
369 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
371 -re "Catch of fork not yet implemented.*$gdb_prompt $"
375 timeout {fail "(timeout) $name"}
379 set name "set catch vfork, never expected to trigger"
380 send_gdb "catch vfork\n"
382 # If we are on HP-UX 10.20, we expect an error message to be
383 # printed if we type "catch vfork" at the gdb gdb_prompt. This is
384 # because on HP-UX 10.20, we cannot catch vfork events.
386 if [istarget "hppa*-hp-hpux10.20"] then {
388 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
392 timeout {fail "(timeout) $name"}
396 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
398 -re "Catch of vfork not yet implemented.*$gdb_prompt $"
402 timeout {fail "(timeout) $name"}
406 set name "set catch exec, never expected to trigger"
407 send_gdb "catch exec\n"
409 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
411 -re "Catch of exec not yet implemented.*$gdb_prompt $"
413 -re "$gdb_prompt $" {fail $name}
414 timeout {fail "(timeout) $name"}
417 # Verify that GDB responds gracefully when asked to set a breakpoint
418 # on a nonexistent source line.
420 send_gdb "break 999\n"
422 -re "No line 999 in file .*$gdb_prompt $"\
423 {pass "break on non-existent source line"}
425 {fail "break on non-existent source line"}
426 timeout {fail "(timeout) break on non-existent source line"}
429 # Run to the desired default location. If not positioned here, the
430 # tests below don't work.
432 gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
435 # Verify that GDB allows one to just say "break", which is treated
436 # as the "default" breakpoint. Note that GDB gets cute when printing
437 # the informational message about other breakpoints at the same
438 # location. We'll hit that bird with this stone too.
442 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
443 {pass "break on default location, 1st time"}
445 {fail "break on default location, 1st time"}
446 timeout {fail "(timeout) break on default location, 1st time"}
451 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
452 {pass "break on default location, 2nd time"}
454 {fail "break on default location, 2nd time"}
455 timeout {fail "(timeout) break on default location, 2nd time"}
460 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
461 {pass "break on default location, 3rd time"}
463 {fail "break on default location, 3rd time"}
464 timeout {fail "(timeout) break on default location, 3rd time"}
469 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
470 {pass "break on default location, 4th time"}
472 {fail "break on default location, 4th time"}
473 timeout {fail "(timeout) break on default location, 4th time"}
476 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
477 # "silent" about its triggering.
479 if ![runto_main] then { fail "break tests suppressed" }
481 send_gdb "break $bp_location1\n"
483 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
484 {pass "set to-be-silent break bp_location1"}
486 {fail "set to-be-silent break bp_location1"}
487 timeout {fail "(timeout) set to-be-silent break bp_location1"}
490 send_gdb "commands $expect_out(1,string)\n"
494 -re ".*$gdb_prompt $"\
495 {pass "set silent break bp_location1"}
496 timeout {fail "(timeout) set silent break bp_location1"}
499 send_gdb "info break $expect_out(1,string)\n"
501 -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
502 {pass "info silent break bp_location1"}
504 {fail "info silent break bp_location1"}
505 timeout {fail "(timeout) info silent break bp_location1"}
507 send_gdb "continue\n"
509 -re "Continuing.\r\n$gdb_prompt $"\
510 {pass "hit silent break bp_location1"}
512 {fail "hit silent break bp_location1"}
513 timeout {fail "(timeout) hit silent break bp_location1"}
517 -re "#0 main .* at .*:$bp_location1.*$gdb_prompt $"\
518 {pass "stopped for silent break bp_location1"}
520 {fail "stopped for silent break bp_location1"}
521 timeout {fail "(timeout) stopped for silent break bp_location1"}
524 # Verify that GDB can at least parse a breakpoint with the
525 # "thread" keyword. (We won't attempt to test here that a
526 # thread-specific breakpoint really triggers appropriately.
527 # The gdb.threads subdirectory contains tests for that.)
529 set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
530 send_gdb "break $bp_location12 thread 999\n"
532 -re "Unknown thread 999.*$gdb_prompt $"\
533 {pass "thread-specific breakpoint on non-existent thread disallowed"}
535 {fail "thread-specific breakpoint on non-existent thread disallowed"}
536 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
538 send_gdb "break $bp_location12 thread foo\n"
540 -re "Junk after thread keyword..*$gdb_prompt $"\
541 {pass "thread-specific breakpoint on bogus thread ID disallowed"}
543 {fail "thread-specific breakpoint on bogus thread ID disallowed"}
544 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
547 # Verify that GDB responds gracefully to a breakpoint command with
550 send_gdb "break $bp_location12 foo\n"
552 -re "Junk at end of arguments..*$gdb_prompt $"\
553 {pass "breakpoint with trailing garbage disallowed"}
555 {fail "breakpoint with trailing garbage disallowed"}
556 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
559 # Verify that GDB responds gracefully to a "clear" command that has
560 # no matching breakpoint. (First, get us off the current source line,
561 # which we know has a breakpoint.)
565 -re ".*$gdb_prompt $"\
566 {pass "step over breakpoint"}
567 timeout {fail "(timeout) step over breakpoint"}
569 send_gdb "clear 81\n"
571 -re "No breakpoint at 81..*$gdb_prompt $"\
572 {pass "clear line has no breakpoint disallowed"}
574 {fail "clear line has no breakpoint disallowed"}
575 timeout {fail "(timeout) clear line has no breakpoint disallowed"}
579 -re "No breakpoint at this line..*$gdb_prompt $"\
580 {pass "clear current line has no breakpoint disallowed"}
582 {fail "clear current line has no breakpoint disallowed"}
583 timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
586 # Verify that we can set and clear multiple breakpoints.
588 # We don't test that it deletes the correct breakpoints. We do at
589 # least test that it deletes more than one breakpoint.
591 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
592 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
593 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
595 # Verify that a breakpoint can be set via a convenience variable.
597 send_gdb "set \$foo=$bp_location11\n"
600 {pass "set convenience variable \$foo to bp_location11"}
601 timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
603 send_gdb "break \$foo\n"
605 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
606 {pass "set breakpoint via convenience variable"}
608 {fail "set breakpoint via convenience variable"}
609 timeout {fail "(timeout) set breakpoint via convenience variable"}
612 # Verify that GDB responds gracefully to an attempt to set a
613 # breakpoint via a convenience variable whose type is not integer.
615 send_gdb "set \$foo=81.5\n"
618 {pass "set convenience variable \$foo to 81.5"}
619 timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
621 send_gdb "break \$foo\n"
623 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
624 {pass "set breakpoint via non-integer convenience variable disallowed"}
626 {fail "set breakpoint via non-integer convenience variable disallowed"}
627 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
630 # Verify that we can set and trigger a breakpoint in a user-called function.
632 send_gdb "break marker2\n"
634 -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
635 {pass "set breakpoint on to-be-called function"}
637 {fail "set breakpoint on to-be-called function"}
638 timeout {fail "(timeout) set breakpoint on to-be-called function"}
640 send_gdb "print marker2(99)\n"
642 -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 $"\
643 {pass "hit breakpoint on called function"}
645 {fail "hit breakpoint on called function"}
646 timeout {fail "(timeout) hit breakpoint on called function"}
649 # As long as we're stopped (breakpointed) in a called function,
650 # verify that we can successfully backtrace & such from here.
652 # In this and the following test, the _sr4export check apparently is needed
657 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
658 {pass "backtrace while in called function"}
659 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
660 {pass "backtrace while in called function"}
662 {fail "backtrace while in called function"}
663 timeout {fail "(timeout) backtrace while in called function"}
666 # Return from the called function. For remote targets, it's important to do
667 # this before runto_main, which otherwise may silently stop on the dummy
668 # breakpoint inserted by GDB at the program's entry point.
672 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
673 {pass "finish from called function"}
674 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
675 {pass "finish from called function"}
676 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
677 {pass "finish from called function"}
679 {fail "finish from called function"}
680 timeout {fail "(timeout) finish from called function"}
683 # Verify that GDB responds gracefully to a "finish" command with
686 if ![runto_main] then { fail "break tests suppressed" }
688 send_gdb "finish 123\n"
690 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
691 {pass "finish with arguments disallowed"}
693 {fail "finish with arguments disallowed"}
694 timeout {fail "(timeout) finish with arguments disallowed"}
697 # Verify that GDB responds gracefully to a request to "finish" from
698 # the outermost frame. On a stub that never exits, this will just
699 # run to the stubs routine, so we don't get this error... Thus the
705 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
706 {pass "finish from outermost frame disallowed"}
707 -re "Run till exit from.*\r\n$gdb_prompt $" {
708 pass "finish from outermost frame disallowed"
711 {fail "finish from outermost frame disallowed"}
712 timeout {fail "(timeout) finish from outermost frame disallowed"}
715 # Verify that we can explicitly ask GDB to stop on all shared library
716 # events, and that it does so.
718 if [istarget "hppa*-*-hpux*"] then {
719 if ![runto_main] then { fail "break tests suppressed" }
721 send_gdb "set stop-on-solib-events 1\n"
724 {pass "set stop-on-solib-events"}
725 timeout {fail "(timeout) set stop-on-solib-events"}
730 -re ".*Start it from the beginning.*y or n. $"\
733 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
734 {pass "triggered stop-on-solib-events"}
736 {fail "triggered stop-on-solib-events"}
737 timeout {fail "(timeout) triggered stop-on-solib-events"}
741 {fail "rerun for stop-on-solib-events"}
742 timeout {fail "(timeout) rerun for stop-on-solib-events"}
745 send_gdb "set stop-on-solib-events 0\n"
748 {pass "reset stop-on-solib-events"}
749 timeout {fail "(timeout) reset stop-on-solib-events"}
753 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
754 # gracefully responds to requests to create them.
756 if [istarget "hppa*-*-hpux*"] then {
757 if ![runto_main] then { fail "break tests suppressed" }
761 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
762 {pass "hw breaks disallowed"}
764 {fail "hw breaks disallowed"}
765 timeout {fail "(timeout) hw breaks disallowed"}
770 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
771 {pass "temporary hw breaks disallowed"}
773 {fail "temporary hw breaks disallowed"}
774 timeout {fail "(timeout) temporary hw breaks disallowed"}
782 # Test "next" over recursive function call.
785 proc test_next_with_recursion {} {
790 if [target_info exists use_gdb_stub] {
791 # Reload the program.
795 # FIXME: should be using runto
796 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
801 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
803 # Run until we call factorial with 6
805 if [istarget "*-*-vxworks*"] then {
806 send_gdb "run vxmain \"6\"\n"
811 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
812 -re ".*$gdb_prompt $" {
813 fail "run to factorial(6)";
816 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
819 # Continue until we call factorial recursively with 5.
821 if [gdb_test "continue" \
822 "Continuing.*Break.* factorial .value=5. .*" \
823 "continue to factorial(5)"] then { gdb_suppress_tests }
825 # Do a backtrace just to confirm how many levels deep we are.
827 if [gdb_test "backtrace" \
828 "#0\[ \t\]+ factorial .value=5..*" \
829 "backtrace from factorial(5)"] then { gdb_suppress_tests }
831 # Now a "next" should position us at the recursive call, which
832 # we will be performing with 4.
834 if [gdb_test "next" \
835 ".* factorial .value - 1.;.*" \
836 "next to recursive call"] then { gdb_suppress_tests }
838 # Disable the breakpoint at the entry to factorial by deleting them all.
839 # The "next" should run until we return to the next line from this
840 # recursive call to factorial with 4.
841 # Buggy versions of gdb will stop instead at the innermost frame on
842 # the line where we are trying to "next" to.
846 if [istarget "mips*tx39-*"] {
849 # We used to set timeout here for all other targets as well. This
850 # is almost certainly wrong. The proper timeout depends on the
851 # target system in use, and how we communicate with it, so there
852 # is no single value appropriate for all targets. The timeout
853 # should be established by the Dejagnu config file(s) for the
854 # board, and respected by the test suite.
856 # For example, if I'm running GDB over an SSH tunnel talking to a
857 # portmaster in California talking to an ancient 68k board running
858 # a crummy ROM monitor (a situation I can only wish were
859 # hypothetical), then I need a large timeout. But that's not the
860 # kind of knowledge that belongs in this file.
862 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
863 "next over recursive call"
865 # OK, we should be back in the same stack frame we started from.
866 # Do a backtrace just to confirm.
868 set result [gdb_test "backtrace" \
869 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
870 "backtrace from factorial(5.1)"]
871 if { $result != 0 } { gdb_suppress_tests }
873 if [target_info exists gdb,noresults] { gdb_suppress_tests }
874 gdb_continue_to_end "recursive next test"
875 gdb_stop_suppressing_tests;
878 test_next_with_recursion
883 # now move the .debug file to a different location so that we can test
884 # the "set debug-file-directory" command.
886 remote_exec build "mv ${objdir}/${subdir}/.debug/${testfile}.debug ${objdir}/${subdir}"
889 gdb_reinitialize_dir $srcdir/$subdir
890 gdb_test "set debug-file-directory ${objdir}/${subdir}" ".*" "set separate debug location"
893 if [target_info exists gdb_stub] {
898 # test break at function
900 gdb_test "break main" \
901 "Breakpoint.*at.* file .*$srcfile, line.*" \
902 "breakpoint function, optimized file"
905 # test break at function
907 gdb_test "break marker4" \
908 "Breakpoint.*at.* file .*$srcfile, line.*" \
909 "breakpoint small function, optimized file"
912 # run until the breakpoint at main is hit. For non-stubs-using targets.
914 if ![target_info exists use_gdb_stub] {
915 if [istarget "*-*-vxworks*"] then {
916 send_gdb "run vxmain \"2\"\n"
918 verbose "Timeout is now $timeout seconds" 2
923 -re "The program .* has been started already.*y or n. $" {
927 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
928 { pass "run until function breakpoint, optimized file" }
929 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $"\
930 { pass "run until function breakpoint, optimized file (code motion)" }
931 -re ".*$gdb_prompt $" { fail "run until function breakpoint, optimized file" }
932 timeout { fail "run until function breakpoint, optimized file (timeout)" }
935 if ![target_info exists gdb_stub] {
936 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue, optimized file"
941 # run until the breakpoint at a small function
945 # Add a second pass pattern. The behavior differs here between stabs
946 # and dwarf for one-line functions. Stabs preserves two line symbols
947 # (one before the prologue and one after) with the same line number,
948 # but dwarf regards these as duplicates and discards one of them.
949 # Therefore the address after the prologue (where the breakpoint is)
950 # has no exactly matching line symbol, and GDB reports the breakpoint
951 # as if it were in the middle of a line rather than at the beginning.
953 set bp_location13 [gdb_get_line_number "set breakpoint 13 here"]
954 set bp_location14 [gdb_get_line_number "set breakpoint 14 here"]
955 send_gdb "continue\n"
957 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
958 pass "run until breakpoint set at small function, optimized file"
960 -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
961 pass "run until breakpoint set at small function, optimized file"
963 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
964 # marker4() is defined at line 46 when compiled with -DPROTOTYPES
965 pass "run until breakpoint set at small function, optimized file (line bp_location14)"
967 -re ".*$gdb_prompt " {
968 fail "run until breakpoint set at small function, optimized file"
971 fail "run until breakpoint set at small function, optimized file (timeout)"
976 # Reset the default arguments for VxWorks
977 if [istarget "*-*-vxworks*"] {
979 verbose "Timeout is now $timeout seconds" 2
980 send_gdb "set args main\n"
981 gdb_expect -re ".*$gdb_prompt $" {}