1 # Copyright (C) 1988, 1990, 1991, 1992, 1994, 1997, 1998
2 # 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 # This file was written by Rob Savoye. (rob@cygnus.com)
29 # test running programs
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
39 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
44 gdb_reinitialize_dir $srcdir/$subdir
47 if [target_info exists gdb_stub] {
51 # test simple breakpoint setting commands
54 # Test deleting all breakpoints when there are none installed,
55 # GDB should not prompt for confirmation.
56 # Note that gdb-init.exp provides a "delete_breakpoints" proc
57 # for general use elsewhere.
59 send_gdb "delete breakpoints\n"
61 -re "Delete all breakpoints.*$" {
65 fail "Delete all breakpoints when none (unexpected prompt)"
67 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
70 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
71 timeout { fail "Delete all breakpoints when none (timeout)" }
75 # test break at function
77 gdb_test "break main" \
78 "Breakpoint.*at.* file .*$srcfile, line.*" \
82 # test break at function in file
84 gdb_test "break $srcfile:factorial" \
85 "Breakpoint.*at.* file .*$srcfile, line.*" \
86 "breakpoint function in file"
89 # test break at line number
92 "Breakpoint.*at.* file .*$srcfile, line 64\\." \
93 "breakpoint line number"
96 # test duplicate breakpoint
99 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 64\\." \
100 "breakpoint duplicate"
103 # test break at line number in file
105 gdb_test "break $srcfile:70" \
106 "Breakpoint.*at.* file .*$srcfile, line 70\\." \
107 "breakpoint line number in file"
111 # check to see what breakpoints are set
113 if [target_info exists gdb_stub] {
119 gdb_test "info break" \
120 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
121 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
122 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:76.*
123 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:64.*
124 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:64.*
125 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:70" \
129 # FIXME: The rest of this test doesn't work with anything that can't
131 # Huh? There doesn't *appear* to be anything that passes arguments
133 if [istarget "mips-idt-*"] then {
138 # run until the breakpoint at main is hit. For non-stubs-using targets.
140 if ![target_info exists use_gdb_stub] {
141 if [istarget "*-*-vxworks*"] then {
142 send_gdb "run vxmain \"2\"\n"
144 verbose "Timeout is now $timeout seconds" 2
149 -re "The program .* has been started already.*y or n. $" {
153 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:60.*60\[\t \]+if .argc.* \{.*$gdb_prompt $"\
154 { pass "run until function breakpoint" }
155 -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
156 timeout { fail "run until function breakpoint (timeout)" }
159 if ![target_info exists gdb_stub] {
160 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:60.*60\[\t \]+if .argc.*\{" "stub continue"
165 # run until the breakpoint at a line number
167 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:64.*64\[\t \]+printf.*factorial.*" \
168 "run until breakpoint set at a line number"
171 # Run until the breakpoint set in a function in a file
173 for {set i 6} {$i >= 1} {incr i -1} {
174 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:76.*76\[\t \]+if .value > 1. \{" \
175 "run until file:function($i) breakpoint"
179 # run until the file:function breakpoint at a line number in a file
181 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:70.*70\[\t \]+return 0;" \
182 "run until file:linenum breakpoint"
185 # delete all breakpoints so we can start over, course this can be a test too
190 # test temporary breakpoint at function
193 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
196 # test break at function in file
199 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
200 "Temporary breakpoint function in file"
203 # test break at line number
205 send_gdb "tbreak 64\n"
207 -re "Breakpoint.*at.* file .*$srcfile, line 64.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
208 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
209 timeout { fail "breakpoint line number #1 (timeout)" }
212 gdb_test "tbreak 60" "Breakpoint.*at.* file .*$srcfile, line 60.*" "Temporary breakpoint line number #2"
215 # test break at line number in file
217 send_gdb "tbreak $srcfile:70\n"
219 -re "Breakpoint.*at.* file .*$srcfile, line 70.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
220 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
221 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
224 gdb_test "tbreak $srcfile:66" "Breakpoint.*at.* file .*$srcfile, line 66.*" "Temporary breakpoint line number in file #2"
227 # check to see what breakpoints are set (temporary this time)
229 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]\[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:76.*\[\r\n\]\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:64.*\[\r\n\]\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:70.*" "Temporary breakpoint info"
234 # Verify that catchpoints for fork, vfork and exec don't trigger
235 # inappropriately. (There are no calls to those system functions
236 # in this test program.)
238 if ![runto_main] then { fail "break tests suppressed" }
242 -re "Catch requires an event name.*$gdb_prompt $"\
243 {pass "catch requires an event name"}
245 {fail "catch requires an event name"}
246 timeout {fail "(timeout) catch requires an event name"}
250 set name "set catch fork, never expected to trigger"
251 send_gdb "catch fork\n"
253 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
255 -re "Catch of fork not yet implemented.*$gdb_prompt $"
259 timeout {fail "(timeout) $name"}
263 set name "set catch vfork, never expected to trigger"
264 send_gdb "catch vfork\n"
266 # If we are on HP-UX 10.20, we expect an error message to be
267 # printed if we type "catch vfork" at the gdb gdb_prompt. This is
268 # because on HP-UX 10.20, we cannot catch vfork events.
270 if [istarget "hppa*-hp-hpux10.20"] then {
272 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
276 timeout {fail "(timeout) $name"}
280 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
282 -re "Catch of vfork not yet implemented.*$gdb_prompt $"
286 timeout {fail "(timeout) $name"}
290 set name "set catch exec, never expected to trigger"
291 send_gdb "catch exec\n"
293 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
295 -re "Catch of exec not yet implemented.*$gdb_prompt $"
297 -re "$gdb_prompt $" {fail $name}
298 timeout {fail "(timeout) $name"}
301 # Verify that "until <location>" works. (This is really just syntactic
302 # sugar for "tbreak <location>; continue".)
304 send_gdb "until 64\n"
306 -re "main .* at .*:64.*$gdb_prompt $"\
310 timeout {fail "(timeout) until 64"}
313 # Verify that a malformed "until" is gracefully caught.
315 send_gdb "until 65 then stop\n"
317 -re "Junk at end of arguments..*$gdb_prompt $"\
318 {pass "malformed until"}
320 {fail "malformed until"}
321 timeout {fail "(timeout) malformed until"}
324 # Verify that GDB responds gracefully when asked to set a breakpoint
325 # on a nonexistent source line.
327 send_gdb "break 999\n"
329 -re "No line 999 in file .*$gdb_prompt $"\
330 {pass "break on non-existent source line"}
332 {fail "break on non-existent source line"}
333 timeout {fail "(timeout) break on non-existent source line"}
336 # Verify that GDB allows one to just say "break", which is treated
337 # as the "default" breakpoint. Note that GDB gets cute when printing
338 # the informational message about other breakpoints at the same
339 # location. We'll hit that bird with this stone too.
343 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
344 {pass "break on default location, 1st time"}
346 {fail "break on default location, 1st time"}
347 timeout {fail "(timeout) break on default location, 1st time"}
352 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
353 {pass "break on default location, 2nd time"}
355 {fail "break on default location, 2nd time"}
356 timeout {fail "(timeout) break on default location, 2nd time"}
361 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
362 {pass "break on default location, 3rd time"}
364 {fail "break on default location, 3rd time"}
365 timeout {fail "(timeout) break on default location, 3rd time"}
370 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
371 {pass "break on default location, 4th time"}
373 {fail "break on default location, 4th time"}
374 timeout {fail "(timeout) break on default location, 4th time"}
377 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
378 # "silent" about its triggering.
380 if ![runto_main] then { fail "break tests suppressed" }
382 send_gdb "break 64\n"
384 -re "Breakpoint (\[0-9\]*) at .*, line 64.*$gdb_prompt $"\
385 {pass "set to-be-silent break 64"}
387 {fail "set to-be-silent break 64"}
388 timeout {fail "(timeout) set to-be-silent break 64"}
391 send_gdb "commands $expect_out(1,string)\n"
395 -re ".*$gdb_prompt $"\
396 {pass "set silent break 64"}
397 timeout {fail "(timeout) set silent break 64"}
400 send_gdb "info break $expect_out(1,string)\n"
402 -re "\[0-9\]*\[ \t\]*breakpoint.*:64\r\n\[ \t\]*silent.*$gdb_prompt $"\
403 {pass "info silent break 64"}
405 {fail "info silent break 64"}
406 timeout {fail "(timeout) info silent break 64"}
408 send_gdb "continue\n"
410 -re "Continuing.\r\n$gdb_prompt $"\
411 {pass "hit silent break 64"}
413 {fail "hit silent break 64"}
414 timeout {fail "(timeout) hit silent break 64"}
418 -re "#0 main .* at .*:64.*$gdb_prompt $"\
419 {pass "stopped for silent break 64"}
421 {fail "stopped for silent break 64"}
422 timeout {fail "(timeout) stopped for silent break 64"}
425 # Verify that GDB can at least parse a breakpoint with the
426 # "thread" keyword. (We won't attempt to test here that a
427 # thread-specific breakpoint really triggers appropriately.
428 # The gdb.threads subdirectory contains tests for that.)
430 send_gdb "break 65 thread 999\n"
432 -re "Unknown thread 999.*$gdb_prompt $"\
433 {pass "thread-specific breakpoint on non-existent thread disallowed"}
435 {fail "thread-specific breakpoint on non-existent thread disallowed"}
436 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
438 send_gdb "break 65 thread foo\n"
440 -re "Junk after thread keyword..*$gdb_prompt $"\
441 {pass "thread-specific breakpoint on bogus thread ID disallowed"}
443 {fail "thread-specific breakpoint on bogus thread ID disallowed"}
444 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
447 # Verify that GDB responds gracefully to a breakpoint command with
450 send_gdb "break 65 foo\n"
452 -re "Junk at end of arguments..*$gdb_prompt $"\
453 {pass "breakpoint with trailing garbage disallowed"}
455 {fail "breakpoint with trailing garbage disallowed"}
456 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
459 # Verify that GDB responds gracefully to a "clear" command that has
460 # no matching breakpoint. (First, get us off the current source line,
461 # which we know has a breakpoint.)
465 -re ".*$gdb_prompt $"\
466 {pass "step over breakpoint"}
467 timeout {fail "(timeout) step over breakpoint"}
469 send_gdb "clear 66\n"
471 -re "No breakpoint at 66..*$gdb_prompt $"\
472 {pass "clear line has no breakpoint disallowed"}
474 {fail "clear line has no breakpoint disallowed"}
475 timeout {fail "(timeout) clear line has no breakpoint disallowed"}
479 -re "No breakpoint at this line..*$gdb_prompt $"\
480 {pass "clear current line has no breakpoint disallowed"}
482 {fail "clear current line has no breakpoint disallowed"}
483 timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
486 # Verify that a breakpoint can be set via a convenience variable.
488 send_gdb "set \$foo=66\n"
491 {pass "set convenience variable \$foo to 66"}
492 timeout {fail "(timeout) set convenience variable \$foo to 66"}
494 send_gdb "break \$foo\n"
496 -re "Breakpoint (\[0-9\]*) at .*, line 66.*$gdb_prompt $"\
497 {pass "set breakpoint via convenience variable"}
499 {fail "set breakpoint via convenience variable"}
500 timeout {fail "(timeout) set breakpoint via convenience variable"}
503 # Verify that GDB responds gracefully to an attempt to set a
504 # breakpoint via a convenience variable whose type is not integer.
506 send_gdb "set \$foo=66.5\n"
509 {pass "set convenience variable \$foo to 66.5"}
510 timeout {fail "(timeout) set convenience variable \$foo to 66.5"}
512 send_gdb "break \$foo\n"
514 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
515 {pass "set breakpoint via non-integer convenience variable disallowed"}
517 {fail "set breakpoint via non-integer convenience variable disallowed"}
518 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
521 # Verify that we can set and trigger a breakpoint in a user-called function.
523 send_gdb "break marker2\n"
525 -re "Breakpoint (\[0-9\]*) at .*, line 42.*$gdb_prompt $"\
526 {pass "set breakpoint on to-be-called function"}
528 {fail "set breakpoint on to-be-called function"}
529 timeout {fail "(timeout) set breakpoint on to-be-called function"}
531 send_gdb "print marker2(99)\n"
533 -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 $"\
534 {pass "hit breakpoint on called function"}
536 {fail "hit breakpoint on called function"}
537 timeout {fail "(timeout) hit breakpoint on called function"}
540 # As long as we're stopped (breakpointed) in a called function,
541 # verify that we can successfully backtrace & such from here.
543 if [istarget "hppa*-*-hpux*"] then {
546 -re "#0\[ \t\]*marker2.*:42\r\n#1.*_sr4export.*$gdb_prompt $"\
547 {pass "backtrace while in called function"}
549 {fail "backtrace while in called function"}
550 timeout {fail "(timeout) backtrace while in called function"}
554 -re "Run till exit from .*marker2.* at .*42\r\n.* in _sr4export.*$gdb_prompt $"\
555 {pass "finish from called function"}
557 {fail "finish from called function"}
558 timeout {fail "(timeout) finish from called function"}
562 # Verify that GDB responds gracefully to a "finish" command with
565 if ![runto_main] then { fail "break tests suppressed" }
567 send_gdb "finish 123\n"
569 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
570 {pass "finish with arguments disallowed"}
572 {fail "finish with arguments disallowed"}
573 timeout {fail "(timeout) finish with arguments disallowed"}
576 # Verify that GDB responds gracefully to a request to "finish" from
577 # the outermost frame.
581 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
582 {pass "finish from outermost frame disallowed"}
584 {fail "finish from outermost frame disallowed"}
585 timeout {fail "(timeout) finish from outermost frame disallowed"}
588 # Verify that we can explicitly ask GDB to stop on all shared library
589 # events, and that it does so.
591 if [istarget "hppa*-*-hpux*"] then {
592 if ![runto_main] then { fail "break tests suppressed" }
594 send_gdb "set stop-on-solib-events 1\n"
597 {pass "set stop-on-solib-events"}
598 timeout {fail "(timeout) set stop-on-solib-events"}
603 -re ".*Start it from the beginning.*y or n. $"\
606 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
607 {pass "triggered stop-on-solib-events"}
609 {fail "triggered stop-on-solib-events"}
610 timeout {fail "(timeout) triggered stop-on-solib-events"}
614 {fail "rerun for stop-on-solib-events"}
615 timeout {fail "(timeout) rerun for stop-on-solib-events"}
618 send_gdb "set stop-on-solib-events 0\n"
621 {pass "reset stop-on-solib-events"}
622 timeout {fail "(timeout) reset stop-on-solib-events"}
626 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
627 # gracefully responds to requests to create them.
629 if [istarget "hppa*-*-hpux*"] then {
630 if ![runto_main] then { fail "break tests suppressed" }
634 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
635 {pass "hw breaks disallowed"}
637 {fail "hw breaks disallowed"}
638 timeout {fail "(timeout) hw breaks disallowed"}
643 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
644 {pass "temporary hw breaks disallowed"}
646 {fail "temporary hw breaks disallowed"}
647 timeout {fail "(timeout) temporary hw breaks disallowed"}
654 proc test_clear_command {} {
655 gdb_test "break main" "Breakpoint.*at.*" "break main #1"
656 gdb_test "break main" "Breakpoint.*at.*" "break main #2"
658 # We don't test that it deletes the correct breakpoints. We do at
659 # least test that it deletes more than one breakpoint.
660 gdb_test "clear main" {Deleted breakpoints [0-9]+ [0-9]+.*}
664 # Test "next" over recursive function call.
667 proc test_next_with_recursion {} {
672 if [target_info exists use_gdb_stub] {
673 # Reload the program.
677 # FIXME: should be using runto
678 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
683 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
685 # Run until we call factorial with 6
687 if [istarget "*-*-vxworks*"] then {
688 send_gdb "run vxmain \"6\"\n"
693 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
694 -re ".*$gdb_prompt $" {
695 fail "run to factorial(6)";
698 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
701 # Continue until we call factorial recursively with 5.
703 if [gdb_test "continue" \
704 "Continuing.*Break.* factorial .value=5. .*" \
705 "continue to factorial(5)"] then { gdb_suppress_tests }
707 # Do a backtrace just to confirm how many levels deep we are.
709 if [gdb_test "backtrace" \
710 "#0\[ \t\]+ factorial .value=5..*" \
711 "backtrace from factorial(5)"] then { gdb_suppress_tests }
713 # Now a "next" should position us at the recursive call, which
714 # we will be performing with 4.
716 if [gdb_test "next" \
717 ".* factorial .value - 1.;.*" \
718 "next to recursive call"] then { gdb_suppress_tests }
720 # Disable the breakpoint at the entry to factorial by deleting them all.
721 # The "next" should run until we return to the next line from this
722 # recursive call to factorial with 4.
723 # Buggy versions of gdb will stop instead at the innermost frame on
724 # the line where we are trying to "next" to.
728 if [istarget "mips*tx39-*"] {
734 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
735 "next over recursive call"
737 # OK, we should be back in the same stack frame we started from.
738 # Do a backtrace just to confirm.
740 set result [gdb_test "backtrace" \
741 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
742 "backtrace from factorial(5.1)"]
743 if { $result != 0 } { gdb_suppress_tests }
745 if [target_info exists gdb,noresults] { gdb_suppress_tests }
746 if [target_info exists use_gdb_stub] {
747 gdb_breakpoint "exit"
748 gdb_test "continue" "Continuing..*Breakpoint .*exit \[(\].*=0\[)\].*" "continue until exit in recursive next test"
750 # Continue until we exit. Should not stop again.
751 # Don't bother to check the output of the program, that may be
752 # extremely tough for some remote systems.
754 "Continuing.\[\r\n0-9\]+Program exited normally\\..*"\
755 "continue until exit in recursive next test"
757 gdb_stop_suppressing_tests;
761 test_next_with_recursion
763 # Reset the default arguments for VxWorks
764 if [istarget "*-*-vxworks*"] {
766 verbose "Timeout is now $timeout seconds" 2
767 send_gdb "set args main\n"
768 gdb_expect -re ".*$gdb_prompt $" {}