1 # Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
2 # 2000, 2002, 2003, 2007 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # This file was written by Rob Savoye. (rob@cygnus.com)
29 # test running programs
35 set srcfile ${testfile}.c
36 set srcfile1 ${testfile}1.c
37 set binfile ${objdir}/${subdir}/${testfile}
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
49 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
54 if [get_compiler_info ${binfile}] {
60 gdb_reinitialize_dir $srcdir/$subdir
63 if [target_info exists gdb_stub] {
67 # test simple breakpoint setting commands
70 # Test deleting all breakpoints when there are none installed,
71 # GDB should not prompt for confirmation.
72 # Note that lib/gdb.exp provides a "delete_breakpoints" proc
73 # for general use elsewhere.
75 send_gdb "delete breakpoints\n"
77 -re "Delete all breakpoints.*$" {
81 fail "Delete all breakpoints when none (unexpected prompt)"
83 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
86 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
87 timeout { fail "Delete all breakpoints when none (timeout)" }
91 # test break at function
93 gdb_test "break main" \
94 "Breakpoint.*at.* file .*$srcfile, line.*" \
98 # test break at quoted function
100 gdb_test "break \"marker2\"" \
101 "Breakpoint.*at.* file .*$srcfile1, line.*" \
102 "breakpoint quoted function"
105 # test break at function in file
107 gdb_test "break $srcfile:factorial" \
108 "Breakpoint.*at.* file .*$srcfile, line.*" \
109 "breakpoint function in file"
111 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
114 # test break at line number
116 # Note that the default source file is the last one whose source text
117 # was printed. For native debugging, before we've executed the
118 # program, this is the file containing main, but for remote debugging,
119 # it's wherever the processor was stopped when we connected to the
120 # board. So, to be sure, we do a list command.
122 gdb_test "list main" \
123 ".*main \\(argc, argv, envp\\).*" \
124 "use `list' to establish default source file"
125 gdb_test "break $bp_location1" \
126 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
127 "breakpoint line number"
130 # test duplicate breakpoint
132 gdb_test "break $bp_location1" \
133 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
134 "breakpoint duplicate"
136 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
139 # test break at line number in file
141 gdb_test "break $srcfile:$bp_location2" \
142 "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
143 "breakpoint line number in file"
145 set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
146 set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
149 # Test putting a break at the start of a multi-line if conditional.
150 # Verify the breakpoint was put at the start of the conditional.
152 gdb_test "break multi_line_if_conditional" \
153 "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
154 "breakpoint at start of multi line if conditional"
156 gdb_test "break multi_line_while_conditional" \
157 "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
158 "breakpoint at start of multi line while conditional"
160 set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
161 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
164 # check to see what breakpoints are set
166 if [target_info exists gdb_stub] {
167 set main_line $bp_location5
169 set main_line $bp_location6
172 if {$hp_aCC_compiler} {
173 set proto "\\(int\\)"
178 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
179 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
180 set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
182 gdb_test "info break" \
183 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
184 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
185 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile1:($bp_location8|$bp_location9).*
186 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial$proto at .*$srcfile:$bp_location7.*
187 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
188 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
189 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location2.*
190 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
191 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
194 # FIXME: The rest of this test doesn't work with anything that can't
196 # Huh? There doesn't *appear* to be anything that passes arguments
198 if [istarget "mips-idt-*"] then {
203 # run until the breakpoint at main is hit. For non-stubs-using targets.
205 if ![target_info exists use_gdb_stub] {
206 if [istarget "*-*-vxworks*"] then {
207 send_gdb "run vxmain \"2\"\n"
209 verbose "Timeout is now $timeout seconds" 2
214 -re "The program .* has been started already.*y or n. $" {
218 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
219 { pass "run until function breakpoint" }
220 -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
221 timeout { fail "run until function breakpoint (timeout)" }
224 if ![target_info exists gdb_stub] {
225 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue"
230 # run until the breakpoint at a line number
232 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
233 "run until breakpoint set at a line number"
236 # Run until the breakpoint set in a function in a file
238 for {set i 6} {$i >= 1} {incr i -1} {
239 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
240 "run until file:function($i) breakpoint"
244 # Run until the breakpoint set at a quoted function
246 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*" \
247 "run until quoted breakpoint"
249 # run until the file:function breakpoint at a line number in a file
251 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
252 "run until file:linenum breakpoint"
254 # Test break at offset +1
255 set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
257 gdb_test "break +1" \
258 "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
259 "breakpoint offset +1"
261 # Check to see if breakpoint is hit when stepped onto
264 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
265 "step onto breakpoint"
267 # Check to see if breakpoint can be set on ending brace of function
268 set bp_location10a [gdb_get_line_number "set breakpoint 10a here"]
270 gdb_test "break $bp_location10a" \
271 "Breakpoint.*at.* file .*$srcfile, line $bp_location10a\\." \
272 "setting breakpoint at }"
274 gdb_test "continue" \
275 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10a.*$bp_location10a\[\t \]+}.*breakpoint 10a here.*" \
276 "continue to breakpoint at }"
279 # delete all breakpoints so we can start over, course this can be a test too
284 # test temporary breakpoint at function
287 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
290 # test break at function in file
293 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
294 "Temporary breakpoint function in file"
297 # test break at line number
299 send_gdb "tbreak $bp_location1\n"
301 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
302 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
303 timeout { fail "breakpoint line number #1 (timeout)" }
306 gdb_test "tbreak $bp_location6" "Breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
309 # test break at line number in file
311 send_gdb "tbreak $srcfile:$bp_location2\n"
313 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
314 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
315 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
318 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
319 gdb_test "tbreak $srcfile:$bp_location11" "Breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
322 # check to see what breakpoints are set (temporary this time)
324 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
325 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
326 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial$proto at .*$srcfile:$bp_location7.*\[\r\n\]
327 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
328 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
329 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
330 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
331 "Temporary breakpoint info"
336 # Verify that catchpoints for fork, vfork and exec don't trigger
337 # inappropriately. (There are no calls to those system functions
338 # in this test program.)
340 if ![runto_main] then { fail "break tests suppressed" }
344 -re "Catch requires an event name.*$gdb_prompt $"\
345 {pass "catch requires an event name"}
347 {fail "catch requires an event name"}
348 timeout {fail "(timeout) catch requires an event name"}
352 set name "set catch fork, never expected to trigger"
353 send_gdb "catch fork\n"
355 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
357 -re "Catch of fork not yet implemented.*$gdb_prompt $"
361 timeout {fail "(timeout) $name"}
365 set name "set catch vfork, never expected to trigger"
366 send_gdb "catch vfork\n"
368 # If we are on HP-UX 10.20, we expect an error message to be
369 # printed if we type "catch vfork" at the gdb gdb_prompt. This is
370 # because on HP-UX 10.20, we cannot catch vfork events.
372 if [istarget "hppa*-hp-hpux10.20"] then {
374 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
378 timeout {fail "(timeout) $name"}
382 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
384 -re "Catch of vfork not yet implemented.*$gdb_prompt $"
388 timeout {fail "(timeout) $name"}
392 set name "set catch exec, never expected to trigger"
393 send_gdb "catch exec\n"
395 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
397 -re "Catch of exec not yet implemented.*$gdb_prompt $"
399 -re "$gdb_prompt $" {fail $name}
400 timeout {fail "(timeout) $name"}
403 # Verify that GDB responds gracefully when asked to set a breakpoint
404 # on a nonexistent source line.
406 send_gdb "break 999\n"
408 -re "No line 999 in file .*$gdb_prompt $"\
409 {pass "break on non-existent source line"}
411 {fail "break on non-existent source line"}
412 timeout {fail "(timeout) break on non-existent source line"}
415 # Run to the desired default location. If not positioned here, the
416 # tests below don't work.
418 gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
421 # Verify that GDB allows one to just say "break", which is treated
422 # as the "default" breakpoint. Note that GDB gets cute when printing
423 # the informational message about other breakpoints at the same
424 # location. We'll hit that bird with this stone too.
428 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
429 {pass "break on default location, 1st time"}
431 {fail "break on default location, 1st time"}
432 timeout {fail "(timeout) break on default location, 1st time"}
437 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
438 {pass "break on default location, 2nd time"}
440 {fail "break on default location, 2nd time"}
441 timeout {fail "(timeout) break on default location, 2nd time"}
446 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
447 {pass "break on default location, 3rd time"}
449 {fail "break on default location, 3rd time"}
450 timeout {fail "(timeout) break on default location, 3rd time"}
455 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
456 {pass "break on default location, 4th time"}
458 {fail "break on default location, 4th time"}
459 timeout {fail "(timeout) break on default location, 4th time"}
462 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
463 # "silent" about its triggering.
465 if ![runto_main] then { fail "break tests suppressed" }
467 send_gdb "break $bp_location1\n"
469 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
470 {pass "set to-be-silent break bp_location1"}
472 {fail "set to-be-silent break bp_location1"}
473 timeout {fail "(timeout) set to-be-silent break bp_location1"}
476 send_gdb "commands $expect_out(1,string)\n"
480 -re ".*$gdb_prompt $"\
481 {pass "set silent break bp_location1"}
482 timeout {fail "(timeout) set silent break bp_location1"}
485 send_gdb "info break $expect_out(1,string)\n"
487 -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
488 {pass "info silent break bp_location1"}
490 {fail "info silent break bp_location1"}
491 timeout {fail "(timeout) info silent break bp_location1"}
493 send_gdb "continue\n"
495 -re "Continuing.\r\n$gdb_prompt $"\
496 {pass "hit silent break bp_location1"}
498 {fail "hit silent break bp_location1"}
499 timeout {fail "(timeout) hit silent break bp_location1"}
503 -re "#0 main .* at .*:$bp_location1.*$gdb_prompt $"\
504 {pass "stopped for silent break bp_location1"}
506 {fail "stopped for silent break bp_location1"}
507 timeout {fail "(timeout) stopped for silent break bp_location1"}
510 # Verify that GDB can at least parse a breakpoint with the
511 # "thread" keyword. (We won't attempt to test here that a
512 # thread-specific breakpoint really triggers appropriately.
513 # The gdb.threads subdirectory contains tests for that.)
515 set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
516 send_gdb "break $bp_location12 thread 999\n"
518 -re "Unknown thread 999.*$gdb_prompt $"\
519 {pass "thread-specific breakpoint on non-existent thread disallowed"}
521 {fail "thread-specific breakpoint on non-existent thread disallowed"}
522 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
524 send_gdb "break $bp_location12 thread foo\n"
526 -re "Junk after thread keyword..*$gdb_prompt $"\
527 {pass "thread-specific breakpoint on bogus thread ID disallowed"}
529 {fail "thread-specific breakpoint on bogus thread ID disallowed"}
530 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
533 # Verify that GDB responds gracefully to a breakpoint command with
536 send_gdb "break $bp_location12 foo\n"
538 -re "Junk at end of arguments..*$gdb_prompt $"\
539 {pass "breakpoint with trailing garbage disallowed"}
541 {fail "breakpoint with trailing garbage disallowed"}
542 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
545 # Verify that GDB responds gracefully to a "clear" command that has
546 # no matching breakpoint. (First, get us off the current source line,
547 # which we know has a breakpoint.)
551 -re ".*$gdb_prompt $"\
552 {pass "step over breakpoint"}
553 timeout {fail "(timeout) step over breakpoint"}
555 send_gdb "clear 81\n"
557 -re "No breakpoint at 81..*$gdb_prompt $"\
558 {pass "clear line has no breakpoint disallowed"}
560 {fail "clear line has no breakpoint disallowed"}
561 timeout {fail "(timeout) clear line has no breakpoint disallowed"}
565 -re "No breakpoint at this line..*$gdb_prompt $"\
566 {pass "clear current line has no breakpoint disallowed"}
568 {fail "clear current line has no breakpoint disallowed"}
569 timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
572 # Verify that we can set and clear multiple breakpoints.
574 # We don't test that it deletes the correct breakpoints. We do at
575 # least test that it deletes more than one breakpoint.
577 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
578 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
579 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
581 # Verify that a breakpoint can be set via a convenience variable.
583 send_gdb "set \$foo=$bp_location11\n"
586 {pass "set convenience variable \$foo to bp_location11"}
587 timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
589 send_gdb "break \$foo\n"
591 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
592 {pass "set breakpoint via convenience variable"}
594 {fail "set breakpoint via convenience variable"}
595 timeout {fail "(timeout) set breakpoint via convenience variable"}
598 # Verify that GDB responds gracefully to an attempt to set a
599 # breakpoint via a convenience variable whose type is not integer.
601 send_gdb "set \$foo=81.5\n"
604 {pass "set convenience variable \$foo to 81.5"}
605 timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
607 send_gdb "break \$foo\n"
609 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
610 {pass "set breakpoint via non-integer convenience variable disallowed"}
612 {fail "set breakpoint via non-integer convenience variable disallowed"}
613 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
616 # Verify that we can set and trigger a breakpoint in a user-called function.
618 send_gdb "break marker2\n"
620 -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
621 {pass "set breakpoint on to-be-called function"}
623 {fail "set breakpoint on to-be-called function"}
624 timeout {fail "(timeout) set breakpoint on to-be-called function"}
626 send_gdb "print marker2(99)\n"
628 -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 $"\
629 {pass "hit breakpoint on called function"}
631 {fail "hit breakpoint on called function"}
632 timeout {fail "(timeout) hit breakpoint on called function"}
635 # As long as we're stopped (breakpointed) in a called function,
636 # verify that we can successfully backtrace & such from here.
638 # In this and the following test, the _sr4export check apparently is needed
643 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
644 {pass "backtrace while in called function"}
645 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
646 {pass "backtrace while in called function"}
648 {fail "backtrace while in called function"}
649 timeout {fail "(timeout) backtrace while in called function"}
652 # Return from the called function. For remote targets, it's important to do
653 # this before runto_main, which otherwise may silently stop on the dummy
654 # breakpoint inserted by GDB at the program's entry point.
658 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
659 {pass "finish from called function"}
660 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
661 {pass "finish from called function"}
662 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
663 {pass "finish from called function"}
665 {fail "finish from called function"}
666 timeout {fail "(timeout) finish from called function"}
669 # Verify that GDB responds gracefully to a "finish" command with
672 if ![runto_main] then { fail "break tests suppressed" }
674 send_gdb "finish 123\n"
676 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
677 {pass "finish with arguments disallowed"}
679 {fail "finish with arguments disallowed"}
680 timeout {fail "(timeout) finish with arguments disallowed"}
683 # Verify that GDB responds gracefully to a request to "finish" from
684 # the outermost frame. On a stub that never exits, this will just
685 # run to the stubs routine, so we don't get this error... Thus the
691 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
692 {pass "finish from outermost frame disallowed"}
693 -re "Run till exit from.*\r\n$gdb_prompt $" {
694 pass "finish from outermost frame disallowed"
697 {fail "finish from outermost frame disallowed"}
698 timeout {fail "(timeout) finish from outermost frame disallowed"}
701 # Verify that we can explicitly ask GDB to stop on all shared library
702 # events, and that it does so.
704 if [istarget "hppa*-*-hpux*"] then {
705 if ![runto_main] then { fail "break tests suppressed" }
707 send_gdb "set stop-on-solib-events 1\n"
710 {pass "set stop-on-solib-events"}
711 timeout {fail "(timeout) set stop-on-solib-events"}
716 -re ".*Start it from the beginning.*y or n. $"\
719 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
720 {pass "triggered stop-on-solib-events"}
722 {fail "triggered stop-on-solib-events"}
723 timeout {fail "(timeout) triggered stop-on-solib-events"}
727 {fail "rerun for stop-on-solib-events"}
728 timeout {fail "(timeout) rerun for stop-on-solib-events"}
731 send_gdb "set stop-on-solib-events 0\n"
734 {pass "reset stop-on-solib-events"}
735 timeout {fail "(timeout) reset stop-on-solib-events"}
739 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
740 # gracefully responds to requests to create them.
742 if [istarget "hppa*-*-hpux*"] then {
743 if ![runto_main] then { fail "break tests suppressed" }
747 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
748 {pass "hw breaks disallowed"}
750 {fail "hw breaks disallowed"}
751 timeout {fail "(timeout) hw breaks disallowed"}
756 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
757 {pass "temporary hw breaks disallowed"}
759 {fail "temporary hw breaks disallowed"}
760 timeout {fail "(timeout) temporary hw breaks disallowed"}
768 # Test "next" over recursive function call.
771 proc test_next_with_recursion {} {
776 if [target_info exists use_gdb_stub] {
777 # Reload the program.
781 # FIXME: should be using runto
782 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
787 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
789 # Run until we call factorial with 6
791 if [istarget "*-*-vxworks*"] then {
792 send_gdb "run vxmain \"6\"\n"
797 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
798 -re ".*$gdb_prompt $" {
799 fail "run to factorial(6)";
802 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
805 # Continue until we call factorial recursively with 5.
807 if [gdb_test "continue" \
808 "Continuing.*Break.* factorial .value=5. .*" \
809 "continue to factorial(5)"] then { gdb_suppress_tests }
811 # Do a backtrace just to confirm how many levels deep we are.
813 if [gdb_test "backtrace" \
814 "#0\[ \t\]+ factorial .value=5..*" \
815 "backtrace from factorial(5)"] then { gdb_suppress_tests }
817 # Now a "next" should position us at the recursive call, which
818 # we will be performing with 4.
820 if [gdb_test "next" \
821 ".* factorial .value - 1.;.*" \
822 "next to recursive call"] then { gdb_suppress_tests }
824 # Disable the breakpoint at the entry to factorial by deleting them all.
825 # The "next" should run until we return to the next line from this
826 # recursive call to factorial with 4.
827 # Buggy versions of gdb will stop instead at the innermost frame on
828 # the line where we are trying to "next" to.
832 if [istarget "mips*tx39-*"] {
835 # We used to set timeout here for all other targets as well. This
836 # is almost certainly wrong. The proper timeout depends on the
837 # target system in use, and how we communicate with it, so there
838 # is no single value appropriate for all targets. The timeout
839 # should be established by the Dejagnu config file(s) for the
840 # board, and respected by the test suite.
842 # For example, if I'm running GDB over an SSH tunnel talking to a
843 # portmaster in California talking to an ancient 68k board running
844 # a crummy ROM monitor (a situation I can only wish were
845 # hypothetical), then I need a large timeout. But that's not the
846 # kind of knowledge that belongs in this file.
848 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
849 "next over recursive call"
851 # OK, we should be back in the same stack frame we started from.
852 # Do a backtrace just to confirm.
854 set result [gdb_test "backtrace" \
855 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
856 "backtrace from factorial(5.1)"]
857 if { $result != 0 } { gdb_suppress_tests }
859 if [target_info exists gdb,noresults] { gdb_suppress_tests }
860 gdb_continue_to_end "recursive next test"
861 gdb_stop_suppressing_tests;
864 test_next_with_recursion
869 # build a new file with optimization enabled so that we can try breakpoints
870 # on targets with optimized prologues
872 set binfileo2 ${objdir}/${subdir}/${testfile}o2
874 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}O0.o" object {debug nowarnings optimize=-O2}] != "" } {
879 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}O1.o" object {debug nowarnings optimize=-O2}] != "" } {
884 if { [gdb_compile "${binfile}O0.o ${binfile}O1.o" "${binfileo2}" executable {debug nowarnings}] != "" } {
889 if [get_compiler_info ${binfileo2}] {
895 gdb_reinitialize_dir $srcdir/$subdir
896 gdb_load ${binfileo2}
898 if [target_info exists gdb_stub] {
903 # test break at function
905 gdb_test "break main" \
906 "Breakpoint.*at.* file .*, line.*" \
907 "breakpoint function, optimized file"
910 # test break at function
912 gdb_test "break marker4" \
913 "Breakpoint.*at.* file .*$srcfile1, line.*" \
914 "breakpoint small function, optimized file"
917 # run until the breakpoint at main is hit. For non-stubs-using targets.
919 if ![target_info exists use_gdb_stub] {
920 if [istarget "*-*-vxworks*"] then {
921 send_gdb "run vxmain \"2\"\n"
923 verbose "Timeout is now $timeout seconds" 2
928 -re "The program .* has been started already.*y or n. $" {
932 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
933 { pass "run until function breakpoint, optimized file" }
934 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $"\
935 { pass "run until function breakpoint, optimized file (code motion)" }
936 -re ".*$gdb_prompt $" { fail "run until function breakpoint, optimized file" }
937 timeout { fail "run until function breakpoint, optimized file (timeout)" }
940 if ![target_info exists gdb_stub] {
941 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue, optimized file"
946 # run until the breakpoint at a small function
950 # Add a second pass pattern. The behavior differs here between stabs
951 # and dwarf for one-line functions. Stabs preserves two line symbols
952 # (one before the prologue and one after) with the same line number,
953 # but dwarf regards these as duplicates and discards one of them.
954 # Therefore the address after the prologue (where the breakpoint is)
955 # has no exactly matching line symbol, and GDB reports the breakpoint
956 # as if it were in the middle of a line rather than at the beginning.
958 set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
959 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
960 send_gdb "continue\n"
962 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
963 pass "run until breakpoint set at small function, optimized file"
965 -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
966 pass "run until breakpoint set at small function, optimized file"
968 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
969 # marker4() is defined at line 46 when compiled with -DPROTOTYPES
970 pass "run until breakpoint set at small function, optimized file (line bp_location14)"
972 -re ".*$gdb_prompt " {
973 fail "run until breakpoint set at small function, optimized file"
976 fail "run until breakpoint set at small function, optimized file (timeout)"
981 # Reset the default arguments for VxWorks
982 if [istarget "*-*-vxworks*"] {
984 verbose "Timeout is now $timeout seconds" 2
985 send_gdb "set args main\n"
986 gdb_expect -re ".*$gdb_prompt $" {}