1 # Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
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 # This file was written by Rob Savoye. (rob@cygnus.com)
30 # test running programs
36 set srcfile ${testfile}.c
37 set binfile ${objdir}/${subdir}/${testfile}
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
40 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
43 if [get_compiler_info ${binfile}] {
49 gdb_reinitialize_dir $srcdir/$subdir
52 if [target_info exists gdb_stub] {
56 # test simple breakpoint setting commands
59 # Test deleting all breakpoints when there are none installed,
60 # GDB should not prompt for confirmation.
61 # Note that gdb-init.exp provides a "delete_breakpoints" proc
62 # for general use elsewhere.
64 send_gdb "delete breakpoints\n"
66 -re "Delete all breakpoints.*$" {
70 fail "Delete all breakpoints when none (unexpected prompt)"
72 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
75 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
76 timeout { fail "Delete all breakpoints when none (timeout)" }
80 # test break at function
82 gdb_test "break main" \
83 "Breakpoint.*at.* file .*$srcfile, line.*" \
87 # test break at quoted function
89 gdb_test "break \"marker2\"" \
90 "Breakpoint.*at.* file .*$srcfile, line.*" \
91 "breakpoint quoted function"
94 # test break at function in file
96 gdb_test "break $srcfile:factorial" \
97 "Breakpoint.*at.* file .*$srcfile, line.*" \
98 "breakpoint function in file"
101 # test break at line number
103 # Note that the default source file is the last one whose source text
104 # was printed. For native debugging, before we've executed the
105 # program, this is the file containing main, but for remote debugging,
106 # it's wherever the processor was stopped when we connected to the
107 # board. So, to be sure, we do a list command.
109 gdb_test "list main" \
110 ".*main \\(argc, argv, envp\\).*" \
111 "use `list' to establish default source file"
112 gdb_test "break 79" \
113 "Breakpoint.*at.* file .*$srcfile, line 79\\." \
114 "breakpoint line number"
117 # test duplicate breakpoint
119 gdb_test "break 79" \
120 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 79\\." \
121 "breakpoint duplicate"
124 # test break at line number in file
126 gdb_test "break $srcfile:85" \
127 "Breakpoint.*at.* file .*$srcfile, line 85\\." \
128 "breakpoint line number in file"
132 # Test putting a break at the start of a multi-line if conditional.
133 # Verify the breakpoint was put at the start of the conditional.
135 gdb_test "break multi_line_if_conditional" \
136 "Breakpoint.*at.* file .*$srcfile, line 109\\." \
137 "breakpoint at start of multi line if conditional"
139 gdb_test "break multi_line_while_conditional" \
140 "Breakpoint.*at.* file .*$srcfile, line 124\\." \
141 "breakpoint at start of multi line while conditional"
144 # check to see what breakpoints are set
146 if [target_info exists gdb_stub] {
152 if {$hp_aCC_compiler} {
153 set proto "\\(int\\)"
157 gdb_test "info break" \
158 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
159 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
160 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile:4\[49\].*
161 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial$proto at .*$srcfile:96.*
162 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:79.*
163 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:79.*
164 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:85.*
165 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:109.*
166 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:124" \
170 # FIXME: The rest of this test doesn't work with anything that can't
172 # Huh? There doesn't *appear* to be anything that passes arguments
174 if [istarget "mips-idt-*"] then {
179 # run until the breakpoint at main is hit. For non-stubs-using targets.
181 if ![target_info exists use_gdb_stub] {
182 if [istarget "*-*-vxworks*"] then {
183 send_gdb "run vxmain \"2\"\n"
185 verbose "Timeout is now $timeout seconds" 2
190 -re "The program .* has been started already.*y or n. $" {
194 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:75.*75\[\t \]+if .argc.* \{.*$gdb_prompt $"\
195 { pass "run until function breakpoint" }
196 -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
197 timeout { fail "run until function breakpoint (timeout)" }
200 if ![target_info exists gdb_stub] {
201 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:75.*75\[\t \]+if .argc.*\{.*" "stub continue"
206 # run until the breakpoint at a line number
208 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:79.*79\[\t \]+printf.*factorial.*" \
209 "run until breakpoint set at a line number"
212 # Run until the breakpoint set in a function in a file
214 for {set i 6} {$i >= 1} {incr i -1} {
215 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:96.*96\[\t \]+.*if .value > 1. \{.*" \
216 "run until file:function($i) breakpoint"
220 # Run until the breakpoint set at a quoted function
222 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile:4\[49\].*" \
223 "run until quoted breakpoint"
225 # run until the file:function breakpoint at a line number in a file
227 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:85.*85\[\t \]+argc = \\(argc == 12345\\);.*" \
228 "run until file:linenum breakpoint"
230 # Test break at offset +1
232 gdb_test "break +1" \
233 "Breakpoint.*at.* file .*$srcfile, line 86\\." \
234 "breakpoint offset +1"
236 # Check to see if breakpoint is hit when stepped onto
239 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:86.*86\[\t \]+return argc;" \
240 "step onto breakpoint"
243 # delete all breakpoints so we can start over, course this can be a test too
248 # test temporary breakpoint at function
251 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
254 # test break at function in file
257 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
258 "Temporary breakpoint function in file"
261 # test break at line number
263 send_gdb "tbreak 79\n"
265 -re "Breakpoint.*at.* file .*$srcfile, line 79.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
266 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
267 timeout { fail "breakpoint line number #1 (timeout)" }
270 gdb_test "tbreak 75" "Breakpoint.*at.* file .*$srcfile, line 75.*" "Temporary breakpoint line number #2"
273 # test break at line number in file
275 send_gdb "tbreak $srcfile:85\n"
277 -re "Breakpoint.*at.* file .*$srcfile, line 85.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
278 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
279 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
282 gdb_test "tbreak $srcfile:81" "Breakpoint.*at.* file .*$srcfile, line 81.*" "Temporary breakpoint line number in file #2"
285 # check to see what breakpoints are set (temporary this time)
287 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
288 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
289 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial$proto at .*$srcfile:96.*\[\r\n\]
290 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:79.*\[\r\n\]
291 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:75.*\[\r\n\]
292 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:85.*\[\r\n\]
293 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:81.*" \
294 "Temporary breakpoint info"
299 # Verify that catchpoints for fork, vfork and exec don't trigger
300 # inappropriately. (There are no calls to those system functions
301 # in this test program.)
303 if ![runto_main] then { fail "break tests suppressed" }
307 -re "Catch requires an event name.*$gdb_prompt $"\
308 {pass "catch requires an event name"}
310 {fail "catch requires an event name"}
311 timeout {fail "(timeout) catch requires an event name"}
315 set name "set catch fork, never expected to trigger"
316 send_gdb "catch fork\n"
318 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
320 -re "Catch of fork not yet implemented.*$gdb_prompt $"
324 timeout {fail "(timeout) $name"}
328 set name "set catch vfork, never expected to trigger"
329 send_gdb "catch vfork\n"
331 # If we are on HP-UX 10.20, we expect an error message to be
332 # printed if we type "catch vfork" at the gdb gdb_prompt. This is
333 # because on HP-UX 10.20, we cannot catch vfork events.
335 if [istarget "hppa*-hp-hpux10.20"] then {
337 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
341 timeout {fail "(timeout) $name"}
345 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
347 -re "Catch of vfork not yet implemented.*$gdb_prompt $"
351 timeout {fail "(timeout) $name"}
355 set name "set catch exec, never expected to trigger"
356 send_gdb "catch exec\n"
358 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
360 -re "Catch of exec not yet implemented.*$gdb_prompt $"
362 -re "$gdb_prompt $" {fail $name}
363 timeout {fail "(timeout) $name"}
366 # Verify that "until <location>" works. (This is really just syntactic
367 # sugar for "tbreak <location>; continue".)
369 send_gdb "until 79\n"
371 -re "main .* at .*:79.*$gdb_prompt $"\
375 timeout {fail "(timeout) until 79"}
378 # Verify that a malformed "until" is gracefully caught.
380 send_gdb "until 80 then stop\n"
382 -re "Junk at end of arguments..*$gdb_prompt $"\
383 {pass "malformed until"}
385 {fail "malformed until"}
386 timeout {fail "(timeout) malformed until"}
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 # Verify that GDB allows one to just say "break", which is treated
402 # as the "default" breakpoint. Note that GDB gets cute when printing
403 # the informational message about other breakpoints at the same
404 # location. We'll hit that bird with this stone too.
408 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
409 {pass "break on default location, 1st time"}
411 {fail "break on default location, 1st time"}
412 timeout {fail "(timeout) break on default location, 1st time"}
417 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
418 {pass "break on default location, 2nd time"}
420 {fail "break on default location, 2nd time"}
421 timeout {fail "(timeout) break on default location, 2nd time"}
426 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
427 {pass "break on default location, 3rd time"}
429 {fail "break on default location, 3rd time"}
430 timeout {fail "(timeout) break on default location, 3rd time"}
435 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
436 {pass "break on default location, 4th time"}
438 {fail "break on default location, 4th time"}
439 timeout {fail "(timeout) break on default location, 4th time"}
442 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
443 # "silent" about its triggering.
445 if ![runto_main] then { fail "break tests suppressed" }
447 send_gdb "break 79\n"
449 -re "Breakpoint (\[0-9\]*) at .*, line 79.*$gdb_prompt $"\
450 {pass "set to-be-silent break 79"}
452 {fail "set to-be-silent break 79"}
453 timeout {fail "(timeout) set to-be-silent break 79"}
456 send_gdb "commands $expect_out(1,string)\n"
460 -re ".*$gdb_prompt $"\
461 {pass "set silent break 79"}
462 timeout {fail "(timeout) set silent break 79"}
465 send_gdb "info break $expect_out(1,string)\n"
467 -re "\[0-9\]*\[ \t\]*breakpoint.*:79\r\n\[ \t\]*silent.*$gdb_prompt $"\
468 {pass "info silent break 79"}
470 {fail "info silent break 79"}
471 timeout {fail "(timeout) info silent break 79"}
473 send_gdb "continue\n"
475 -re "Continuing.\r\n$gdb_prompt $"\
476 {pass "hit silent break 79"}
478 {fail "hit silent break 79"}
479 timeout {fail "(timeout) hit silent break 79"}
483 -re "#0 main .* at .*:79.*$gdb_prompt $"\
484 {pass "stopped for silent break 79"}
486 {fail "stopped for silent break 79"}
487 timeout {fail "(timeout) stopped for silent break 79"}
490 # Verify that GDB can at least parse a breakpoint with the
491 # "thread" keyword. (We won't attempt to test here that a
492 # thread-specific breakpoint really triggers appropriately.
493 # The gdb.threads subdirectory contains tests for that.)
495 send_gdb "break 80 thread 999\n"
497 -re "Unknown thread 999.*$gdb_prompt $"\
498 {pass "thread-specific breakpoint on non-existent thread disallowed"}
500 {fail "thread-specific breakpoint on non-existent thread disallowed"}
501 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
503 send_gdb "break 80 thread foo\n"
505 -re "Junk after thread keyword..*$gdb_prompt $"\
506 {pass "thread-specific breakpoint on bogus thread ID disallowed"}
508 {fail "thread-specific breakpoint on bogus thread ID disallowed"}
509 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
512 # Verify that GDB responds gracefully to a breakpoint command with
515 send_gdb "break 80 foo\n"
517 -re "Junk at end of arguments..*$gdb_prompt $"\
518 {pass "breakpoint with trailing garbage disallowed"}
520 {fail "breakpoint with trailing garbage disallowed"}
521 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
524 # Verify that GDB responds gracefully to a "clear" command that has
525 # no matching breakpoint. (First, get us off the current source line,
526 # which we know has a breakpoint.)
530 -re ".*$gdb_prompt $"\
531 {pass "step over breakpoint"}
532 timeout {fail "(timeout) step over breakpoint"}
534 send_gdb "clear 81\n"
536 -re "No breakpoint at 81..*$gdb_prompt $"\
537 {pass "clear line has no breakpoint disallowed"}
539 {fail "clear line has no breakpoint disallowed"}
540 timeout {fail "(timeout) clear line has no breakpoint disallowed"}
544 -re "No breakpoint at this line..*$gdb_prompt $"\
545 {pass "clear current line has no breakpoint disallowed"}
547 {fail "clear current line has no breakpoint disallowed"}
548 timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
551 # Verify that we can set and clear multiple breakpoints.
553 # We don't test that it deletes the correct breakpoints. We do at
554 # least test that it deletes more than one breakpoint.
556 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
557 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
558 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
560 # Verify that a breakpoint can be set via a convenience variable.
562 send_gdb "set \$foo=81\n"
565 {pass "set convenience variable \$foo to 81"}
566 timeout {fail "(timeout) set convenience variable \$foo to 81"}
568 send_gdb "break \$foo\n"
570 -re "Breakpoint (\[0-9\]*) at .*, line 81.*$gdb_prompt $"\
571 {pass "set breakpoint via convenience variable"}
573 {fail "set breakpoint via convenience variable"}
574 timeout {fail "(timeout) set breakpoint via convenience variable"}
577 # Verify that GDB responds gracefully to an attempt to set a
578 # breakpoint via a convenience variable whose type is not integer.
580 send_gdb "set \$foo=81.5\n"
583 {pass "set convenience variable \$foo to 81.5"}
584 timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
586 send_gdb "break \$foo\n"
588 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
589 {pass "set breakpoint via non-integer convenience variable disallowed"}
591 {fail "set breakpoint via non-integer convenience variable disallowed"}
592 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
595 # Verify that we can set and trigger a breakpoint in a user-called function.
597 send_gdb "break marker2\n"
599 -re "Breakpoint (\[0-9\]*) at .*, line 4\[49\].*$gdb_prompt $"\
600 {pass "set breakpoint on to-be-called function"}
602 {fail "set breakpoint on to-be-called function"}
603 timeout {fail "(timeout) set breakpoint on to-be-called function"}
605 send_gdb "print marker2(99)\n"
607 -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 $"\
608 {pass "hit breakpoint on called function"}
610 {fail "hit breakpoint on called function"}
611 timeout {fail "(timeout) hit breakpoint on called function"}
614 # As long as we're stopped (breakpointed) in a called function,
615 # verify that we can successfully backtrace & such from here.
617 # In this and the following test, the _sr4export check apparently is needed
622 -re "#0\[ \t\]*($hex in )?marker2.*:4\[49\]\r\n#1.*_sr4export.*$gdb_prompt $"\
623 {pass "backtrace while in called function"}
624 -re "#0\[ \t\]*($hex in )?marker2.*:4\[49\]\r\n#1.*function called from gdb.*$gdb_prompt $"\
625 {pass "backtrace while in called function"}
627 {fail "backtrace while in called function"}
628 timeout {fail "(timeout) backtrace while in called function"}
631 # Return from the called function. For remote targets, it's important to do
632 # this before runto_main, which otherwise may silently stop on the dummy
633 # breakpoint inserted by GDB at the program's entry point.
637 -re "Run till exit from .*marker2.* at .*4\[49\]\r\n.* in _sr4export.*$gdb_prompt $"\
638 {pass "finish from called function"}
639 -re "Run till exit from .*marker2.* at .*4\[49\]\r\n.*function called from gdb.*$gdb_prompt $"\
640 {pass "finish from called function"}
641 -re "Run till exit from .*marker2.* at .*4\[49\]\r\n.*Value returned.*$gdb_prompt $"\
642 {pass "finish from called function"}
644 {fail "finish from called function"}
645 timeout {fail "(timeout) finish from called function"}
648 # Verify that GDB responds gracefully to a "finish" command with
651 if ![runto_main] then { fail "break tests suppressed" }
653 send_gdb "finish 123\n"
655 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
656 {pass "finish with arguments disallowed"}
658 {fail "finish with arguments disallowed"}
659 timeout {fail "(timeout) finish with arguments disallowed"}
662 # Verify that GDB responds gracefully to a request to "finish" from
663 # the outermost frame. On a stub that never exits, this will just
664 # run to the stubs routine, so we don't get this error... Thus the
670 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
671 {pass "finish from outermost frame disallowed"}
672 -re "Run till exit from.*\r\n$gdb_prompt $" {
673 pass "finish from outermost frame disallowed"
676 {fail "finish from outermost frame disallowed"}
677 timeout {fail "(timeout) finish from outermost frame disallowed"}
680 # Verify that we can explicitly ask GDB to stop on all shared library
681 # events, and that it does so.
683 if [istarget "hppa*-*-hpux*"] then {
684 if ![runto_main] then { fail "break tests suppressed" }
686 send_gdb "set stop-on-solib-events 1\n"
689 {pass "set stop-on-solib-events"}
690 timeout {fail "(timeout) set stop-on-solib-events"}
695 -re ".*Start it from the beginning.*y or n. $"\
698 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
699 {pass "triggered stop-on-solib-events"}
701 {fail "triggered stop-on-solib-events"}
702 timeout {fail "(timeout) triggered stop-on-solib-events"}
706 {fail "rerun for stop-on-solib-events"}
707 timeout {fail "(timeout) rerun for stop-on-solib-events"}
710 send_gdb "set stop-on-solib-events 0\n"
713 {pass "reset stop-on-solib-events"}
714 timeout {fail "(timeout) reset stop-on-solib-events"}
718 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
719 # gracefully responds to requests to create them.
721 if [istarget "hppa*-*-hpux*"] then {
722 if ![runto_main] then { fail "break tests suppressed" }
726 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
727 {pass "hw breaks disallowed"}
729 {fail "hw breaks disallowed"}
730 timeout {fail "(timeout) hw breaks disallowed"}
735 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
736 {pass "temporary hw breaks disallowed"}
738 {fail "temporary hw breaks disallowed"}
739 timeout {fail "(timeout) temporary hw breaks disallowed"}
747 # Test "next" over recursive function call.
750 proc test_next_with_recursion {} {
755 if [target_info exists use_gdb_stub] {
756 # Reload the program.
760 # FIXME: should be using runto
761 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
766 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
768 # Run until we call factorial with 6
770 if [istarget "*-*-vxworks*"] then {
771 send_gdb "run vxmain \"6\"\n"
776 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
777 -re ".*$gdb_prompt $" {
778 fail "run to factorial(6)";
781 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
784 # Continue until we call factorial recursively with 5.
786 if [gdb_test "continue" \
787 "Continuing.*Break.* factorial .value=5. .*" \
788 "continue to factorial(5)"] then { gdb_suppress_tests }
790 # Do a backtrace just to confirm how many levels deep we are.
792 if [gdb_test "backtrace" \
793 "#0\[ \t\]+ factorial .value=5..*" \
794 "backtrace from factorial(5)"] then { gdb_suppress_tests }
796 # Now a "next" should position us at the recursive call, which
797 # we will be performing with 4.
799 if [gdb_test "next" \
800 ".* factorial .value - 1.;.*" \
801 "next to recursive call"] then { gdb_suppress_tests }
803 # Disable the breakpoint at the entry to factorial by deleting them all.
804 # The "next" should run until we return to the next line from this
805 # recursive call to factorial with 4.
806 # Buggy versions of gdb will stop instead at the innermost frame on
807 # the line where we are trying to "next" to.
811 if [istarget "mips*tx39-*"] {
814 # We used to set timeout here for all other targets as well. This
815 # is almost certainly wrong. The proper timeout depends on the
816 # target system in use, and how we communicate with it, so there
817 # is no single value appropriate for all targets. The timeout
818 # should be established by the Dejagnu config file(s) for the
819 # board, and respected by the test suite.
821 # For example, if I'm running GDB over an SSH tunnel talking to a
822 # portmaster in California talking to an ancient 68k board running
823 # a crummy ROM monitor (a situation I can only wish were
824 # hypothetical), then I need a large timeout. But that's not the
825 # kind of knowledge that belongs in this file.
827 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
828 "next over recursive call"
830 # OK, we should be back in the same stack frame we started from.
831 # Do a backtrace just to confirm.
833 set result [gdb_test "backtrace" \
834 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
835 "backtrace from factorial(5.1)"]
836 if { $result != 0 } { gdb_suppress_tests }
838 if [target_info exists gdb,noresults] { gdb_suppress_tests }
839 gdb_continue_to_end "recursive next test"
840 gdb_stop_suppressing_tests;
843 test_next_with_recursion
848 # build a new file with optimization enabled so that we can try breakpoints
849 # on targets with optimized prologues
851 set binfileo2 ${objdir}/${subdir}/${testfile}o2
853 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfileo2}" executable {debug additional_flags="-O2" }] != "" } {
854 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
857 if [get_compiler_info ${binfileo2}] {
863 gdb_reinitialize_dir $srcdir/$subdir
864 gdb_load ${binfileo2}
866 if [target_info exists gdb_stub] {
871 # test break at function
873 gdb_test "break main" \
874 "Breakpoint.*at.* file .*$srcfile, line.*" \
875 "breakpoint function, optimized file"
878 # test break at function
880 gdb_test "break marker4" \
881 "Breakpoint.*at.* file .*$srcfile, line.*" \
882 "breakpoint small function, optimized file"
885 # run until the breakpoint at main is hit. For non-stubs-using targets.
887 if ![target_info exists use_gdb_stub] {
888 if [istarget "*-*-vxworks*"] then {
889 send_gdb "run vxmain \"2\"\n"
891 verbose "Timeout is now $timeout seconds" 2
896 -re "The program .* has been started already.*y or n. $" {
900 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:75.*75\[\t \]+if .argc.* \{.*$gdb_prompt $"\
901 { pass "run until function breakpoint, optimized file" }
902 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $"\
903 { pass "run until function breakpoint, optimized file (code motion)" }
904 -re ".*$gdb_prompt $" { fail "run until function breakpoint, optimized file" }
905 timeout { fail "run until function breakpoint, optimized file (timeout)" }
908 if ![target_info exists gdb_stub] {
909 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:75.*75\[\t \]+if .argc.*\{.*" "stub continue, optimized file"
914 # run until the breakpoint at a small function
918 # Add a second pass pattern. The behavior differs here between stabs
919 # and dwarf for one-line functions. Stabs preserves two line symbols
920 # (one before the prologue and one after) with the same line number,
921 # but dwarf regards these as duplicates and discards one of them.
922 # Therefore the address after the prologue (where the breakpoint is)
923 # has no exactly matching line symbol, and GDB reports the breakpoint
924 # as if it were in the middle of a line rather than at the beginning.
926 send_gdb "continue\n"
928 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:51\[\r\n\]+51\[\t \]+void marker4.*" {
929 pass "run until breakpoint set at small function, optimized file"
931 -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile:51\[\r\n\]+51\[\t \]+void marker4.*" {
932 pass "run until breakpoint set at small function, optimized file"
934 -re ".*$gdb_prompt " {
935 fail "run until breakpoint set at small function, optimized file"
938 fail "run until breakpoint set at small function, optimized file (timeout)"
943 # Reset the default arguments for VxWorks
944 if [istarget "*-*-vxworks*"] {
946 verbose "Timeout is now $timeout seconds" 2
947 send_gdb "set args main\n"
948 gdb_expect -re ".*$gdb_prompt $" {}