1 # Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
2 # 2000, 2002, 2003, 2007, 2008 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 3 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, see <http://www.gnu.org/licenses/>.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Rob Savoye. (rob@cygnus.com)
28 # test running programs
34 set srcfile ${testfile}.c
35 set srcfile1 ${testfile}1.c
36 set binfile ${objdir}/${subdir}/${testfile}
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
43 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
48 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
53 if [get_compiler_info ${binfile}] {
59 gdb_reinitialize_dir $srcdir/$subdir
62 if [target_info exists gdb_stub] {
66 # test simple breakpoint setting commands
69 # Test deleting all breakpoints when there are none installed,
70 # GDB should not prompt for confirmation.
71 # Note that lib/gdb.exp provides a "delete_breakpoints" proc
72 # for general use elsewhere.
74 send_gdb "delete breakpoints\n"
76 -re "Delete all breakpoints.*$" {
80 fail "Delete all breakpoints when none (unexpected prompt)"
82 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
85 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
86 timeout { fail "Delete all breakpoints when none (timeout)" }
90 # test break at function
92 gdb_test "break main" \
93 "Breakpoint.*at.* file .*$srcfile, line.*" \
97 # test break at quoted function
99 gdb_test "break \"marker2\"" \
100 "Breakpoint.*at.* file .*$srcfile1, line.*" \
101 "breakpoint quoted function"
104 # test break at function in file
106 gdb_test "break $srcfile:factorial" \
107 "Breakpoint.*at.* file .*$srcfile, line.*" \
108 "breakpoint function in file"
110 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
113 # test break at line number
115 # Note that the default source file is the last one whose source text
116 # was printed. For native debugging, before we've executed the
117 # program, this is the file containing main, but for remote debugging,
118 # it's wherever the processor was stopped when we connected to the
119 # board. So, to be sure, we do a list command.
121 gdb_test "list main" \
122 ".*main \\(argc, argv, envp\\).*" \
123 "use `list' to establish default source file"
124 gdb_test "break $bp_location1" \
125 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
126 "breakpoint line number"
129 # test duplicate breakpoint
131 gdb_test "break $bp_location1" \
132 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
133 "breakpoint duplicate"
135 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
138 # test break at line number in file
140 gdb_test "break $srcfile:$bp_location2" \
141 "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
142 "breakpoint line number in file"
144 set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
145 set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
148 # Test putting a break at the start of a multi-line if conditional.
149 # Verify the breakpoint was put at the start of the conditional.
151 gdb_test "break multi_line_if_conditional" \
152 "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
153 "breakpoint at start of multi line if conditional"
155 gdb_test "break multi_line_while_conditional" \
156 "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
157 "breakpoint at start of multi line while conditional"
159 set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
160 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
163 # check to see what breakpoints are set
165 if [target_info exists gdb_stub] {
166 set main_line $bp_location5
168 set main_line $bp_location6
171 if {$hp_aCC_compiler} {
172 set proto "\\(int\\)"
177 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
178 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
179 set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
181 gdb_test "info break" \
182 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
183 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
184 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile1:($bp_location8|$bp_location9).*
185 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial$proto at .*$srcfile:$bp_location7.*
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_location1.*
188 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location2.*
189 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
190 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
193 # FIXME: The rest of this test doesn't work with anything that can't
195 # Huh? There doesn't *appear* to be anything that passes arguments
197 if [istarget "mips-idt-*"] then {
202 # run until the breakpoint at main is hit. For non-stubs-using targets.
206 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
207 pass "run until function breakpoint"
209 -re "$gdb_prompt $" {
210 fail "run until function breakpoint"
213 fail "run until function breakpoint (timeout)"
218 # run until the breakpoint at a line number
220 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
221 "run until breakpoint set at a line number"
224 # Run until the breakpoint set in a function in a file
226 for {set i 6} {$i >= 1} {incr i -1} {
227 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
228 "run until file:function($i) breakpoint"
232 # Run until the breakpoint set at a quoted function
234 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*" \
235 "run until quoted breakpoint"
237 # run until the file:function breakpoint at a line number in a file
239 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
240 "run until file:linenum breakpoint"
242 # Test break at offset +1
243 set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
245 gdb_test "break +1" \
246 "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
247 "breakpoint offset +1"
249 # Check to see if breakpoint is hit when stepped onto
252 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
253 "step onto breakpoint"
255 # Check to see if breakpoint can be set on ending brace of function
256 set bp_location10a [gdb_get_line_number "set breakpoint 10a here"]
258 gdb_test "break $bp_location10a" \
259 "Breakpoint.*at.* file .*$srcfile, line $bp_location10a\\." \
260 "setting breakpoint at }"
262 gdb_test "continue" \
263 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10a.*$bp_location10a\[\t \]+}.*breakpoint 10a here.*" \
264 "continue to breakpoint at }"
267 # delete all breakpoints so we can start over, course this can be a test too
272 # test temporary breakpoint at function
275 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
278 # test break at function in file
281 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
282 "Temporary breakpoint function in file"
285 # test break at line number
287 send_gdb "tbreak $bp_location1\n"
289 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
290 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
291 timeout { fail "breakpoint line number #1 (timeout)" }
294 gdb_test "tbreak $bp_location6" "Breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
297 # test break at line number in file
299 send_gdb "tbreak $srcfile:$bp_location2\n"
301 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
302 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
303 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
306 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
307 gdb_test "tbreak $srcfile:$bp_location11" "Breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
310 # check to see what breakpoints are set (temporary this time)
312 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
313 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
314 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial$proto at .*$srcfile:$bp_location7.*\[\r\n\]
315 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
316 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
317 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
318 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
319 "Temporary breakpoint info"
324 # Verify that catchpoints for fork, vfork and exec don't trigger
325 # inappropriately. (There are no calls to those system functions
326 # in this test program.)
328 if ![runto_main] then { fail "break tests suppressed" }
332 -re "Catch requires an event name.*$gdb_prompt $"\
333 {pass "catch requires an event name"}
335 {fail "catch requires an event name"}
336 timeout {fail "(timeout) catch requires an event name"}
340 set name "set catch fork, never expected to trigger"
341 send_gdb "catch fork\n"
343 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
345 -re "Catch of fork not yet implemented.*$gdb_prompt $"
349 timeout {fail "(timeout) $name"}
353 set name "set catch vfork, never expected to trigger"
354 send_gdb "catch vfork\n"
356 # If we are on HP-UX 10.20, we expect an error message to be
357 # printed if we type "catch vfork" at the gdb gdb_prompt. This is
358 # because on HP-UX 10.20, we cannot catch vfork events.
360 if [istarget "hppa*-hp-hpux10.20"] then {
362 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
366 timeout {fail "(timeout) $name"}
370 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
372 -re "Catch of vfork not yet implemented.*$gdb_prompt $"
376 timeout {fail "(timeout) $name"}
380 set name "set catch exec, never expected to trigger"
381 send_gdb "catch exec\n"
383 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
385 -re "Catch of exec not yet implemented.*$gdb_prompt $"
387 -re "$gdb_prompt $" {fail $name}
388 timeout {fail "(timeout) $name"}
391 # Verify that GDB responds gracefully when asked to set a breakpoint
392 # on a nonexistent source line.
394 send_gdb "break 999\n"
396 -re "No line 999 in file .*$gdb_prompt $"\
397 {pass "break on non-existent source line"}
399 {fail "break on non-existent source line"}
400 timeout {fail "(timeout) break on non-existent source line"}
403 # Run to the desired default location. If not positioned here, the
404 # tests below don't work.
406 gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
409 # Verify that GDB allows one to just say "break", which is treated
410 # as the "default" breakpoint. Note that GDB gets cute when printing
411 # the informational message about other breakpoints at the same
412 # location. We'll hit that bird with this stone too.
416 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
417 {pass "break on default location, 1st time"}
419 {fail "break on default location, 1st time"}
420 timeout {fail "(timeout) break on default location, 1st time"}
425 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
426 {pass "break on default location, 2nd time"}
428 {fail "break on default location, 2nd time"}
429 timeout {fail "(timeout) break on default location, 2nd time"}
434 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
435 {pass "break on default location, 3rd time"}
437 {fail "break on default location, 3rd time"}
438 timeout {fail "(timeout) break on default location, 3rd time"}
443 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
444 {pass "break on default location, 4th time"}
446 {fail "break on default location, 4th time"}
447 timeout {fail "(timeout) break on default location, 4th time"}
450 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
451 # "silent" about its triggering.
453 if ![runto_main] then { fail "break tests suppressed" }
455 send_gdb "break $bp_location1\n"
457 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
458 {pass "set to-be-silent break bp_location1"}
460 {fail "set to-be-silent break bp_location1"}
461 timeout {fail "(timeout) set to-be-silent break bp_location1"}
464 send_gdb "commands $expect_out(1,string)\n"
468 -re ".*$gdb_prompt $"\
469 {pass "set silent break bp_location1"}
470 timeout {fail "(timeout) set silent break bp_location1"}
473 send_gdb "info break $expect_out(1,string)\n"
475 -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
476 {pass "info silent break bp_location1"}
478 {fail "info silent break bp_location1"}
479 timeout {fail "(timeout) info silent break bp_location1"}
481 send_gdb "continue\n"
483 -re "Continuing.\r\n$gdb_prompt $"\
484 {pass "hit silent break bp_location1"}
486 {fail "hit silent break bp_location1"}
487 timeout {fail "(timeout) hit silent break bp_location1"}
491 -re "#0 main .* at .*:$bp_location1.*$gdb_prompt $"\
492 {pass "stopped for silent break bp_location1"}
494 {fail "stopped for silent break bp_location1"}
495 timeout {fail "(timeout) stopped for silent break bp_location1"}
498 # Verify that GDB can at least parse a breakpoint with the
499 # "thread" keyword. (We won't attempt to test here that a
500 # thread-specific breakpoint really triggers appropriately.
501 # The gdb.threads subdirectory contains tests for that.)
503 set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
504 send_gdb "break $bp_location12 thread 999\n"
506 -re "Unknown thread 999.*$gdb_prompt $"\
507 {pass "thread-specific breakpoint on non-existent thread disallowed"}
509 {fail "thread-specific breakpoint on non-existent thread disallowed"}
510 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
512 send_gdb "break $bp_location12 thread foo\n"
514 -re "Junk after thread keyword..*$gdb_prompt $"\
515 {pass "thread-specific breakpoint on bogus thread ID disallowed"}
517 {fail "thread-specific breakpoint on bogus thread ID disallowed"}
518 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
521 # Verify that GDB responds gracefully to a breakpoint command with
524 send_gdb "break $bp_location12 foo\n"
526 -re "Junk at end of arguments..*$gdb_prompt $"\
527 {pass "breakpoint with trailing garbage disallowed"}
529 {fail "breakpoint with trailing garbage disallowed"}
530 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
533 # Verify that GDB responds gracefully to a "clear" command that has
534 # no matching breakpoint. (First, get us off the current source line,
535 # which we know has a breakpoint.)
539 -re ".*$gdb_prompt $"\
540 {pass "step over breakpoint"}
541 timeout {fail "(timeout) step over breakpoint"}
543 send_gdb "clear 81\n"
545 -re "No breakpoint at 81..*$gdb_prompt $"\
546 {pass "clear line has no breakpoint disallowed"}
548 {fail "clear line has no breakpoint disallowed"}
549 timeout {fail "(timeout) clear line has no breakpoint disallowed"}
553 -re "No breakpoint at this line..*$gdb_prompt $"\
554 {pass "clear current line has no breakpoint disallowed"}
556 {fail "clear current line has no breakpoint disallowed"}
557 timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
560 # Verify that we can set and clear multiple breakpoints.
562 # We don't test that it deletes the correct breakpoints. We do at
563 # least test that it deletes more than one breakpoint.
565 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
566 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
567 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
569 # Verify that a breakpoint can be set via a convenience variable.
571 send_gdb "set \$foo=$bp_location11\n"
574 {pass "set convenience variable \$foo to bp_location11"}
575 timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
577 send_gdb "break \$foo\n"
579 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
580 {pass "set breakpoint via convenience variable"}
582 {fail "set breakpoint via convenience variable"}
583 timeout {fail "(timeout) set breakpoint via convenience variable"}
586 # Verify that GDB responds gracefully to an attempt to set a
587 # breakpoint via a convenience variable whose type is not integer.
589 send_gdb "set \$foo=81.5\n"
592 {pass "set convenience variable \$foo to 81.5"}
593 timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
595 send_gdb "break \$foo\n"
597 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
598 {pass "set breakpoint via non-integer convenience variable disallowed"}
600 {fail "set breakpoint via non-integer convenience variable disallowed"}
601 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
604 # Verify that we can set and trigger a breakpoint in a user-called function.
606 send_gdb "break marker2\n"
608 -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
609 {pass "set breakpoint on to-be-called function"}
611 {fail "set breakpoint on to-be-called function"}
612 timeout {fail "(timeout) set breakpoint on to-be-called function"}
614 send_gdb "print marker2(99)\n"
616 -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 $"\
617 {pass "hit breakpoint on called function"}
619 {fail "hit breakpoint on called function"}
620 timeout {fail "(timeout) hit breakpoint on called function"}
623 # As long as we're stopped (breakpointed) in a called function,
624 # verify that we can successfully backtrace & such from here.
626 # In this and the following test, the _sr4export check apparently is needed
631 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
632 {pass "backtrace while in called function"}
633 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
634 {pass "backtrace while in called function"}
636 {fail "backtrace while in called function"}
637 timeout {fail "(timeout) backtrace while in called function"}
640 # Return from the called function. For remote targets, it's important to do
641 # this before runto_main, which otherwise may silently stop on the dummy
642 # breakpoint inserted by GDB at the program's entry point.
646 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
647 {pass "finish from called function"}
648 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
649 {pass "finish from called function"}
650 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
651 {pass "finish from called function"}
653 {fail "finish from called function"}
654 timeout {fail "(timeout) finish from called function"}
657 # Verify that GDB responds gracefully to a "finish" command with
660 if ![runto_main] then { fail "break tests suppressed" }
662 send_gdb "finish 123\n"
664 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
665 {pass "finish with arguments disallowed"}
667 {fail "finish with arguments disallowed"}
668 timeout {fail "(timeout) finish with arguments disallowed"}
671 # Verify that GDB responds gracefully to a request to "finish" from
672 # the outermost frame. On a stub that never exits, this will just
673 # run to the stubs routine, so we don't get this error... Thus the
679 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
680 {pass "finish from outermost frame disallowed"}
681 -re "Run till exit from.*\r\n$gdb_prompt $" {
682 pass "finish from outermost frame disallowed"
685 {fail "finish from outermost frame disallowed"}
686 timeout {fail "(timeout) finish from outermost frame disallowed"}
689 # Verify that we can explicitly ask GDB to stop on all shared library
690 # events, and that it does so.
692 if [istarget "hppa*-*-hpux*"] then {
693 if ![runto_main] then { fail "break tests suppressed" }
695 send_gdb "set stop-on-solib-events 1\n"
698 {pass "set stop-on-solib-events"}
699 timeout {fail "(timeout) set stop-on-solib-events"}
704 -re ".*Start it from the beginning.*y or n. $"\
707 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
708 {pass "triggered stop-on-solib-events"}
710 {fail "triggered stop-on-solib-events"}
711 timeout {fail "(timeout) triggered stop-on-solib-events"}
715 {fail "rerun for stop-on-solib-events"}
716 timeout {fail "(timeout) rerun for stop-on-solib-events"}
719 send_gdb "set stop-on-solib-events 0\n"
722 {pass "reset stop-on-solib-events"}
723 timeout {fail "(timeout) reset stop-on-solib-events"}
727 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
728 # gracefully responds to requests to create them.
730 if [istarget "hppa*-*-hpux*"] then {
731 if ![runto_main] then { fail "break tests suppressed" }
735 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
736 {pass "hw breaks disallowed"}
738 {fail "hw breaks disallowed"}
739 timeout {fail "(timeout) hw breaks disallowed"}
744 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
745 {pass "temporary hw breaks disallowed"}
747 {fail "temporary hw breaks disallowed"}
748 timeout {fail "(timeout) temporary hw breaks disallowed"}
756 # Test "next" over recursive function call.
759 proc test_next_with_recursion {} {
764 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
767 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
769 # Run until we call factorial with 6
773 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
774 -re ".*$gdb_prompt $" {
775 fail "run to factorial(6)";
778 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
781 # Continue until we call factorial recursively with 5.
783 if [gdb_test "continue" \
784 "Continuing.*Break.* factorial .value=5. .*" \
785 "continue to factorial(5)"] then { gdb_suppress_tests }
787 # Do a backtrace just to confirm how many levels deep we are.
789 if [gdb_test "backtrace" \
790 "#0\[ \t\]+ factorial .value=5..*" \
791 "backtrace from factorial(5)"] then { gdb_suppress_tests }
793 # Now a "next" should position us at the recursive call, which
794 # we will be performing with 4.
796 if [gdb_test "next" \
797 ".* factorial .value - 1.;.*" \
798 "next to recursive call"] then { gdb_suppress_tests }
800 # Disable the breakpoint at the entry to factorial by deleting them all.
801 # The "next" should run until we return to the next line from this
802 # recursive call to factorial with 4.
803 # Buggy versions of gdb will stop instead at the innermost frame on
804 # the line where we are trying to "next" to.
808 if [istarget "mips*tx39-*"] {
811 # We used to set timeout here for all other targets as well. This
812 # is almost certainly wrong. The proper timeout depends on the
813 # target system in use, and how we communicate with it, so there
814 # is no single value appropriate for all targets. The timeout
815 # should be established by the Dejagnu config file(s) for the
816 # board, and respected by the test suite.
818 # For example, if I'm running GDB over an SSH tunnel talking to a
819 # portmaster in California talking to an ancient 68k board running
820 # a crummy ROM monitor (a situation I can only wish were
821 # hypothetical), then I need a large timeout. But that's not the
822 # kind of knowledge that belongs in this file.
824 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
825 "next over recursive call"
827 # OK, we should be back in the same stack frame we started from.
828 # Do a backtrace just to confirm.
830 set result [gdb_test "backtrace" \
831 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
832 "backtrace from factorial(5.1)"]
833 if { $result != 0 } { gdb_suppress_tests }
835 if [target_info exists gdb,noresults] { gdb_suppress_tests }
836 gdb_continue_to_end "recursive next test"
837 gdb_stop_suppressing_tests;
840 test_next_with_recursion
845 # build a new file with optimization enabled so that we can try breakpoints
846 # on targets with optimized prologues
848 set binfileo2 ${objdir}/${subdir}/${testfile}o2
850 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}O0.o" object {debug nowarnings optimize=-O2}] != "" } {
855 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}O1.o" object {debug nowarnings optimize=-O2}] != "" } {
860 if { [gdb_compile "${binfile}O0.o ${binfile}O1.o" "${binfileo2}" executable {debug nowarnings}] != "" } {
865 if [get_compiler_info ${binfileo2}] {
871 gdb_reinitialize_dir $srcdir/$subdir
872 gdb_load ${binfileo2}
874 if [target_info exists gdb_stub] {
879 # test break at function
881 gdb_test "break main" \
882 "Breakpoint.*at.* file .*, line.*" \
883 "breakpoint function, optimized file"
886 # test break at function
888 gdb_test "break marker4" \
889 "Breakpoint.*at.* file .*$srcfile1, line.*" \
890 "breakpoint small function, optimized file"
893 # run until the breakpoint at main is hit. For non-stubs-using targets.
897 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
898 pass "run until function breakpoint, optimized file"
900 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $" {
901 pass "run until function breakpoint, optimized file (code motion)"
903 -re "$gdb_prompt $" {
904 fail "run until function breakpoint, optimized file"
907 fail "run until function breakpoint, optimized file (timeout)"
912 # run until the breakpoint at a small function
916 # Add a second pass pattern. The behavior differs here between stabs
917 # and dwarf for one-line functions. Stabs preserves two line symbols
918 # (one before the prologue and one after) with the same line number,
919 # but dwarf regards these as duplicates and discards one of them.
920 # Therefore the address after the prologue (where the breakpoint is)
921 # has no exactly matching line symbol, and GDB reports the breakpoint
922 # as if it were in the middle of a line rather than at the beginning.
924 set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
925 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
926 send_gdb "continue\n"
928 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
929 pass "run until breakpoint set at small function, optimized file"
931 -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
932 pass "run until breakpoint set at small function, optimized file"
934 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
935 # marker4() is defined at line 46 when compiled with -DPROTOTYPES
936 pass "run until breakpoint set at small function, optimized file (line bp_location14)"
938 -re ".*$gdb_prompt " {
939 fail "run until breakpoint set at small function, optimized file"
942 fail "run until breakpoint set at small function, optimized file (timeout)"
947 # Reset the default arguments for VxWorks
948 if [istarget "*-*-vxworks*"] {
950 verbose "Timeout is now $timeout seconds" 2
951 send_gdb "set args main\n"
952 gdb_expect -re ".*$gdb_prompt $" {}