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 srcfile1 ${testfile}1.c
38 set binfile ${objdir}/${subdir}/${testfile}
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
41 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
45 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
48 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
49 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
52 if [get_compiler_info ${binfile}] {
58 gdb_reinitialize_dir $srcdir/$subdir
61 if [target_info exists gdb_stub] {
65 # test simple breakpoint setting commands
68 # Test deleting all breakpoints when there are none installed,
69 # GDB should not prompt for confirmation.
70 # Note that lib/gdb.exp provides a "delete_breakpoints" proc
71 # for general use elsewhere.
73 send_gdb "delete breakpoints\n"
75 -re "Delete all breakpoints.*$" {
79 fail "Delete all breakpoints when none (unexpected prompt)"
81 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
84 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
85 timeout { fail "Delete all breakpoints when none (timeout)" }
89 # test break at function
91 gdb_test "break main" \
92 "Breakpoint.*at.* file .*$srcfile, line.*" \
96 # test break at quoted function
98 gdb_test "break \"marker2\"" \
99 "Breakpoint.*at.* file .*$srcfile1, line.*" \
100 "breakpoint quoted function"
103 # test break at function in file
105 gdb_test "break $srcfile:factorial" \
106 "Breakpoint.*at.* file .*$srcfile, line.*" \
107 "breakpoint function in file"
109 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
112 # test break at line number
114 # Note that the default source file is the last one whose source text
115 # was printed. For native debugging, before we've executed the
116 # program, this is the file containing main, but for remote debugging,
117 # it's wherever the processor was stopped when we connected to the
118 # board. So, to be sure, we do a list command.
120 gdb_test "list main" \
121 ".*main \\(argc, argv, envp\\).*" \
122 "use `list' to establish default source file"
123 gdb_test "break $bp_location1" \
124 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
125 "breakpoint line number"
128 # test duplicate breakpoint
130 gdb_test "break $bp_location1" \
131 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
132 "breakpoint duplicate"
134 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
137 # test break at line number in file
139 gdb_test "break $srcfile:$bp_location2" \
140 "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
141 "breakpoint line number in file"
143 set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
144 set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
147 # Test putting a break at the start of a multi-line if conditional.
148 # Verify the breakpoint was put at the start of the conditional.
150 gdb_test "break multi_line_if_conditional" \
151 "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
152 "breakpoint at start of multi line if conditional"
154 gdb_test "break multi_line_while_conditional" \
155 "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
156 "breakpoint at start of multi line while conditional"
158 set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
159 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
162 # check to see what breakpoints are set
164 if [target_info exists gdb_stub] {
165 set main_line $bp_location5
167 set main_line $bp_location6
170 if {$hp_aCC_compiler} {
171 set proto "\\(int\\)"
176 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
177 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
178 set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
180 gdb_test "info break" \
181 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
182 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
183 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile1:($bp_location8|$bp_location9).*
184 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial$proto at .*$srcfile:$bp_location7.*
185 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
186 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
187 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location2.*
188 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
189 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
192 # FIXME: The rest of this test doesn't work with anything that can't
194 # Huh? There doesn't *appear* to be anything that passes arguments
196 if [istarget "mips-idt-*"] then {
201 # run until the breakpoint at main is hit. For non-stubs-using targets.
203 if ![target_info exists use_gdb_stub] {
204 if [istarget "*-*-vxworks*"] then {
205 send_gdb "run vxmain \"2\"\n"
207 verbose "Timeout is now $timeout seconds" 2
212 -re "The program .* has been started already.*y or n. $" {
216 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
217 { pass "run until function breakpoint" }
218 -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
219 timeout { fail "run until function breakpoint (timeout)" }
222 if ![target_info exists gdb_stub] {
223 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue"
228 # run until the breakpoint at a line number
230 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
231 "run until breakpoint set at a line number"
234 # Run until the breakpoint set in a function in a file
236 for {set i 6} {$i >= 1} {incr i -1} {
237 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
238 "run until file:function($i) breakpoint"
242 # Run until the breakpoint set at a quoted function
244 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*" \
245 "run until quoted breakpoint"
247 # run until the file:function breakpoint at a line number in a file
249 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
250 "run until file:linenum breakpoint"
252 # Test break at offset +1
253 set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
255 gdb_test "break +1" \
256 "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
257 "breakpoint offset +1"
259 # Check to see if breakpoint is hit when stepped onto
262 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
263 "step onto breakpoint"
265 # Check to see if breakpoint can be set on ending brace of function
266 set bp_location10a [gdb_get_line_number "set breakpoint 10a here"]
268 gdb_test "break $bp_location10a" \
269 "Breakpoint.*at.* file .*$srcfile, line $bp_location10a\\." \
270 "setting breakpoint at }"
272 gdb_test "continue" \
273 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10a.*$bp_location10a\[\t \]+}.*breakpoint 10a here.*" \
274 "continue to breakpoint at }"
277 # delete all breakpoints so we can start over, course this can be a test too
282 # test temporary breakpoint at function
285 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
288 # test break at function in file
291 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
292 "Temporary breakpoint function in file"
295 # test break at line number
297 send_gdb "tbreak $bp_location1\n"
299 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
300 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
301 timeout { fail "breakpoint line number #1 (timeout)" }
304 gdb_test "tbreak $bp_location6" "Breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
307 # test break at line number in file
309 send_gdb "tbreak $srcfile:$bp_location2\n"
311 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
312 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
313 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
316 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
317 gdb_test "tbreak $srcfile:$bp_location11" "Breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
320 # check to see what breakpoints are set (temporary this time)
322 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
323 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
324 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial$proto at .*$srcfile:$bp_location7.*\[\r\n\]
325 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
326 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
327 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
328 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
329 "Temporary breakpoint info"
334 # Verify that catchpoints for fork, vfork and exec don't trigger
335 # inappropriately. (There are no calls to those system functions
336 # in this test program.)
338 if ![runto_main] then { fail "break tests suppressed" }
342 -re "Catch requires an event name.*$gdb_prompt $"\
343 {pass "catch requires an event name"}
345 {fail "catch requires an event name"}
346 timeout {fail "(timeout) catch requires an event name"}
350 set name "set catch fork, never expected to trigger"
351 send_gdb "catch fork\n"
353 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
355 -re "Catch of fork not yet implemented.*$gdb_prompt $"
359 timeout {fail "(timeout) $name"}
363 set name "set catch vfork, never expected to trigger"
364 send_gdb "catch vfork\n"
366 # If we are on HP-UX 10.20, we expect an error message to be
367 # printed if we type "catch vfork" at the gdb gdb_prompt. This is
368 # because on HP-UX 10.20, we cannot catch vfork events.
370 if [istarget "hppa*-hp-hpux10.20"] then {
372 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
376 timeout {fail "(timeout) $name"}
380 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
382 -re "Catch of vfork not yet implemented.*$gdb_prompt $"
386 timeout {fail "(timeout) $name"}
390 set name "set catch exec, never expected to trigger"
391 send_gdb "catch exec\n"
393 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
395 -re "Catch of exec not yet implemented.*$gdb_prompt $"
397 -re "$gdb_prompt $" {fail $name}
398 timeout {fail "(timeout) $name"}
401 # Verify that GDB responds gracefully when asked to set a breakpoint
402 # on a nonexistent source line.
404 send_gdb "break 999\n"
406 -re "No line 999 in file .*$gdb_prompt $"\
407 {pass "break on non-existent source line"}
409 {fail "break on non-existent source line"}
410 timeout {fail "(timeout) break on non-existent source line"}
413 # Run to the desired default location. If not positioned here, the
414 # tests below don't work.
416 gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
419 # Verify that GDB allows one to just say "break", which is treated
420 # as the "default" breakpoint. Note that GDB gets cute when printing
421 # the informational message about other breakpoints at the same
422 # location. We'll hit that bird with this stone too.
426 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
427 {pass "break on default location, 1st time"}
429 {fail "break on default location, 1st time"}
430 timeout {fail "(timeout) break on default location, 1st time"}
435 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
436 {pass "break on default location, 2nd time"}
438 {fail "break on default location, 2nd time"}
439 timeout {fail "(timeout) break on default location, 2nd time"}
444 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
445 {pass "break on default location, 3rd time"}
447 {fail "break on default location, 3rd time"}
448 timeout {fail "(timeout) break on default location, 3rd time"}
453 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
454 {pass "break on default location, 4th time"}
456 {fail "break on default location, 4th time"}
457 timeout {fail "(timeout) break on default location, 4th time"}
460 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
461 # "silent" about its triggering.
463 if ![runto_main] then { fail "break tests suppressed" }
465 send_gdb "break $bp_location1\n"
467 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
468 {pass "set to-be-silent break bp_location1"}
470 {fail "set to-be-silent break bp_location1"}
471 timeout {fail "(timeout) set to-be-silent break bp_location1"}
474 send_gdb "commands $expect_out(1,string)\n"
478 -re ".*$gdb_prompt $"\
479 {pass "set silent break bp_location1"}
480 timeout {fail "(timeout) set silent break bp_location1"}
483 send_gdb "info break $expect_out(1,string)\n"
485 -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
486 {pass "info silent break bp_location1"}
488 {fail "info silent break bp_location1"}
489 timeout {fail "(timeout) info silent break bp_location1"}
491 send_gdb "continue\n"
493 -re "Continuing.\r\n$gdb_prompt $"\
494 {pass "hit silent break bp_location1"}
496 {fail "hit silent break bp_location1"}
497 timeout {fail "(timeout) hit silent break bp_location1"}
501 -re "#0 main .* at .*:$bp_location1.*$gdb_prompt $"\
502 {pass "stopped for silent break bp_location1"}
504 {fail "stopped for silent break bp_location1"}
505 timeout {fail "(timeout) stopped for silent break bp_location1"}
508 # Verify that GDB can at least parse a breakpoint with the
509 # "thread" keyword. (We won't attempt to test here that a
510 # thread-specific breakpoint really triggers appropriately.
511 # The gdb.threads subdirectory contains tests for that.)
513 set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
514 send_gdb "break $bp_location12 thread 999\n"
516 -re "Unknown thread 999.*$gdb_prompt $"\
517 {pass "thread-specific breakpoint on non-existent thread disallowed"}
519 {fail "thread-specific breakpoint on non-existent thread disallowed"}
520 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
522 send_gdb "break $bp_location12 thread foo\n"
524 -re "Junk after thread keyword..*$gdb_prompt $"\
525 {pass "thread-specific breakpoint on bogus thread ID disallowed"}
527 {fail "thread-specific breakpoint on bogus thread ID disallowed"}
528 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
531 # Verify that GDB responds gracefully to a breakpoint command with
534 send_gdb "break $bp_location12 foo\n"
536 -re "Junk at end of arguments..*$gdb_prompt $"\
537 {pass "breakpoint with trailing garbage disallowed"}
539 {fail "breakpoint with trailing garbage disallowed"}
540 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
543 # Verify that GDB responds gracefully to a "clear" command that has
544 # no matching breakpoint. (First, get us off the current source line,
545 # which we know has a breakpoint.)
549 -re ".*$gdb_prompt $"\
550 {pass "step over breakpoint"}
551 timeout {fail "(timeout) step over breakpoint"}
553 send_gdb "clear 81\n"
555 -re "No breakpoint at 81..*$gdb_prompt $"\
556 {pass "clear line has no breakpoint disallowed"}
558 {fail "clear line has no breakpoint disallowed"}
559 timeout {fail "(timeout) clear line has no breakpoint disallowed"}
563 -re "No breakpoint at this line..*$gdb_prompt $"\
564 {pass "clear current line has no breakpoint disallowed"}
566 {fail "clear current line has no breakpoint disallowed"}
567 timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
570 # Verify that we can set and clear multiple breakpoints.
572 # We don't test that it deletes the correct breakpoints. We do at
573 # least test that it deletes more than one breakpoint.
575 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
576 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
577 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
579 # Verify that a breakpoint can be set via a convenience variable.
581 send_gdb "set \$foo=$bp_location11\n"
584 {pass "set convenience variable \$foo to bp_location11"}
585 timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
587 send_gdb "break \$foo\n"
589 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
590 {pass "set breakpoint via convenience variable"}
592 {fail "set breakpoint via convenience variable"}
593 timeout {fail "(timeout) set breakpoint via convenience variable"}
596 # Verify that GDB responds gracefully to an attempt to set a
597 # breakpoint via a convenience variable whose type is not integer.
599 send_gdb "set \$foo=81.5\n"
602 {pass "set convenience variable \$foo to 81.5"}
603 timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
605 send_gdb "break \$foo\n"
607 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
608 {pass "set breakpoint via non-integer convenience variable disallowed"}
610 {fail "set breakpoint via non-integer convenience variable disallowed"}
611 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
614 # Verify that we can set and trigger a breakpoint in a user-called function.
616 send_gdb "break marker2\n"
618 -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
619 {pass "set breakpoint on to-be-called function"}
621 {fail "set breakpoint on to-be-called function"}
622 timeout {fail "(timeout) set breakpoint on to-be-called function"}
624 send_gdb "print marker2(99)\n"
626 -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 $"\
627 {pass "hit breakpoint on called function"}
629 {fail "hit breakpoint on called function"}
630 timeout {fail "(timeout) hit breakpoint on called function"}
633 # As long as we're stopped (breakpointed) in a called function,
634 # verify that we can successfully backtrace & such from here.
636 # In this and the following test, the _sr4export check apparently is needed
641 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
642 {pass "backtrace while in called function"}
643 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
644 {pass "backtrace while in called function"}
646 {fail "backtrace while in called function"}
647 timeout {fail "(timeout) backtrace while in called function"}
650 # Return from the called function. For remote targets, it's important to do
651 # this before runto_main, which otherwise may silently stop on the dummy
652 # breakpoint inserted by GDB at the program's entry point.
656 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
657 {pass "finish from called function"}
658 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
659 {pass "finish from called function"}
660 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
661 {pass "finish from called function"}
663 {fail "finish from called function"}
664 timeout {fail "(timeout) finish from called function"}
667 # Verify that GDB responds gracefully to a "finish" command with
670 if ![runto_main] then { fail "break tests suppressed" }
672 send_gdb "finish 123\n"
674 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
675 {pass "finish with arguments disallowed"}
677 {fail "finish with arguments disallowed"}
678 timeout {fail "(timeout) finish with arguments disallowed"}
681 # Verify that GDB responds gracefully to a request to "finish" from
682 # the outermost frame. On a stub that never exits, this will just
683 # run to the stubs routine, so we don't get this error... Thus the
689 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
690 {pass "finish from outermost frame disallowed"}
691 -re "Run till exit from.*\r\n$gdb_prompt $" {
692 pass "finish from outermost frame disallowed"
695 {fail "finish from outermost frame disallowed"}
696 timeout {fail "(timeout) finish from outermost frame disallowed"}
699 # Verify that we can explicitly ask GDB to stop on all shared library
700 # events, and that it does so.
702 if [istarget "hppa*-*-hpux*"] then {
703 if ![runto_main] then { fail "break tests suppressed" }
705 send_gdb "set stop-on-solib-events 1\n"
708 {pass "set stop-on-solib-events"}
709 timeout {fail "(timeout) set stop-on-solib-events"}
714 -re ".*Start it from the beginning.*y or n. $"\
717 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
718 {pass "triggered stop-on-solib-events"}
720 {fail "triggered stop-on-solib-events"}
721 timeout {fail "(timeout) triggered stop-on-solib-events"}
725 {fail "rerun for stop-on-solib-events"}
726 timeout {fail "(timeout) rerun for stop-on-solib-events"}
729 send_gdb "set stop-on-solib-events 0\n"
732 {pass "reset stop-on-solib-events"}
733 timeout {fail "(timeout) reset stop-on-solib-events"}
737 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
738 # gracefully responds to requests to create them.
740 if [istarget "hppa*-*-hpux*"] then {
741 if ![runto_main] then { fail "break tests suppressed" }
745 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
746 {pass "hw breaks disallowed"}
748 {fail "hw breaks disallowed"}
749 timeout {fail "(timeout) hw breaks disallowed"}
754 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
755 {pass "temporary hw breaks disallowed"}
757 {fail "temporary hw breaks disallowed"}
758 timeout {fail "(timeout) temporary hw breaks disallowed"}
766 # Test "next" over recursive function call.
769 proc test_next_with_recursion {} {
774 if [target_info exists use_gdb_stub] {
775 # Reload the program.
779 # FIXME: should be using runto
780 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
785 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
787 # Run until we call factorial with 6
789 if [istarget "*-*-vxworks*"] then {
790 send_gdb "run vxmain \"6\"\n"
795 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
796 -re ".*$gdb_prompt $" {
797 fail "run to factorial(6)";
800 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
803 # Continue until we call factorial recursively with 5.
805 if [gdb_test "continue" \
806 "Continuing.*Break.* factorial .value=5. .*" \
807 "continue to factorial(5)"] then { gdb_suppress_tests }
809 # Do a backtrace just to confirm how many levels deep we are.
811 if [gdb_test "backtrace" \
812 "#0\[ \t\]+ factorial .value=5..*" \
813 "backtrace from factorial(5)"] then { gdb_suppress_tests }
815 # Now a "next" should position us at the recursive call, which
816 # we will be performing with 4.
818 if [gdb_test "next" \
819 ".* factorial .value - 1.;.*" \
820 "next to recursive call"] then { gdb_suppress_tests }
822 # Disable the breakpoint at the entry to factorial by deleting them all.
823 # The "next" should run until we return to the next line from this
824 # recursive call to factorial with 4.
825 # Buggy versions of gdb will stop instead at the innermost frame on
826 # the line where we are trying to "next" to.
830 if [istarget "mips*tx39-*"] {
833 # We used to set timeout here for all other targets as well. This
834 # is almost certainly wrong. The proper timeout depends on the
835 # target system in use, and how we communicate with it, so there
836 # is no single value appropriate for all targets. The timeout
837 # should be established by the Dejagnu config file(s) for the
838 # board, and respected by the test suite.
840 # For example, if I'm running GDB over an SSH tunnel talking to a
841 # portmaster in California talking to an ancient 68k board running
842 # a crummy ROM monitor (a situation I can only wish were
843 # hypothetical), then I need a large timeout. But that's not the
844 # kind of knowledge that belongs in this file.
846 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
847 "next over recursive call"
849 # OK, we should be back in the same stack frame we started from.
850 # Do a backtrace just to confirm.
852 set result [gdb_test "backtrace" \
853 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
854 "backtrace from factorial(5.1)"]
855 if { $result != 0 } { gdb_suppress_tests }
857 if [target_info exists gdb,noresults] { gdb_suppress_tests }
858 gdb_continue_to_end "recursive next test"
859 gdb_stop_suppressing_tests;
862 test_next_with_recursion
867 # build a new file with optimization enabled so that we can try breakpoints
868 # on targets with optimized prologues
870 set binfileo2 ${objdir}/${subdir}/${testfile}o2
872 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}O0.o" object {debug nowarnings optimize=-O2}] != "" } {
873 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
876 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}O1.o" object {debug nowarnings optimize=-O2}] != "" } {
877 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
880 if { [gdb_compile "${binfile}O0.o ${binfile}O1.o" "${binfileo2}" executable {debug nowarnings}] != "" } {
881 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
884 if [get_compiler_info ${binfileo2}] {
890 gdb_reinitialize_dir $srcdir/$subdir
891 gdb_load ${binfileo2}
893 if [target_info exists gdb_stub] {
898 # test break at function
900 gdb_test "break main" \
901 "Breakpoint.*at.* file .*, line.*" \
902 "breakpoint function, optimized file"
905 # test break at function
907 gdb_test "break marker4" \
908 "Breakpoint.*at.* file .*$srcfile1, 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" $srcfile1]
954 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
955 send_gdb "continue\n"
957 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$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 .*$srcfile1:$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 .*$srcfile1:$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 $" {}