1 # Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
2 # 2000, 2002, 2003, 2004, 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 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 # Based on break.exp, written by Rob Savoye. (rob@cygnus.com)
21 # Modified to test gdb's handling of separate debug info files.
22 # Modified to test gdb's handling of a debug-id retrieval.
24 # This file has two parts. The first is testing that gdb behaves
25 # normally after reading in an executable and its corresponding
26 # separate debug file. The second moves the .debug file to a different
27 # location and tests the "set debug-file-directory" command.
28 # The third is for testing build-id retrievel by finding the separate
29 # ".debug-id/ab/cdef.debug" file.
37 # test running programs
42 set testfile "sepdebug"
43 set srcfile ${testfile}.c
44 set binfile ${objdir}/${subdir}/${testfile}${EXEEXT}
46 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
51 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
52 # ${binfile}, which is just like the executable ($binfile) but without
53 # the debuginfo. Instead $binfile has a .gnudebuglink section which contains
54 # the name of a debuginfo only file. This file will be stored in the
55 # gdb.base/.debug subdirectory.
57 if [gdb_gnu_strip_debug $binfile] {
58 # check that you have a recent version of strip and objcopy installed
59 unsupported "cannot produce separate debug info files"
65 gdb_reinitialize_dir $srcdir/$subdir
68 if [target_info exists gdb_stub] {
72 # test simple breakpoint setting commands
75 # Test deleting all breakpoints when there are none installed,
76 # GDB should not prompt for confirmation.
77 # Note that gdb-init.exp provides a "delete_breakpoints" proc
78 # for general use elsewhere.
80 send_gdb "delete breakpoints\n"
82 -re "Delete all breakpoints.*$" {
86 fail "Delete all breakpoints when none (unexpected prompt)"
88 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
91 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
92 timeout { fail "Delete all breakpoints when none (timeout)" }
96 # test break at function
98 gdb_test "break main" \
99 "Breakpoint.*at.* file .*$srcfile, line.*" \
100 "breakpoint function"
103 # test break at quoted function
105 gdb_test "break \"marker2\"" \
106 "Breakpoint.*at.* file .*$srcfile, line.*" \
107 "breakpoint quoted function"
110 # test break at function in file
112 gdb_test "break $srcfile:factorial" \
113 "Breakpoint.*at.* file .*$srcfile, line.*" \
114 "breakpoint function in file"
116 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
119 # test break at line number
121 # Note that the default source file is the last one whose source text
122 # was printed. For native debugging, before we've executed the
123 # program, this is the file containing main, but for remote debugging,
124 # it's wherever the processor was stopped when we connected to the
125 # board. So, to be sure, we do a list command.
127 gdb_test "list main" \
128 ".*main \\(argc, argv, envp\\).*" \
129 "use `list' to establish default source file"
130 gdb_test "break $bp_location1" \
131 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
132 "breakpoint line number"
135 # test duplicate breakpoint
137 gdb_test "break $bp_location1" \
138 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
139 "breakpoint duplicate"
141 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
144 # test break at line number in file
146 gdb_test "break $srcfile:$bp_location2" \
147 "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
148 "breakpoint line number in file"
150 set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
151 set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
154 # Test putting a break at the start of a multi-line if conditional.
155 # Verify the breakpoint was put at the start of the conditional.
157 gdb_test "break multi_line_if_conditional" \
158 "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
159 "breakpoint at start of multi line if conditional"
161 gdb_test "break multi_line_while_conditional" \
162 "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
163 "breakpoint at start of multi line while conditional"
165 set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
166 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
169 # check to see what breakpoints are set
171 if [target_info exists gdb_stub] {
172 set main_line $bp_location5
174 set main_line $bp_location6
177 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
178 set bp_location8 [gdb_get_line_number "set breakpoint 8 here"]
179 set bp_location9 [gdb_get_line_number "set breakpoint 9 here"]
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 .*$srcfile:($bp_location8|$bp_location9).*
185 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial 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 .*$srcfile:($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"
256 # delete all breakpoints so we can start over, course this can be a test too
261 # test temporary breakpoint at function
264 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
267 # test break at function in file
270 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
271 "Temporary breakpoint function in file"
274 # test break at line number
276 send_gdb "tbreak $bp_location1\n"
278 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
279 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
280 timeout { fail "breakpoint line number #1 (timeout)" }
283 gdb_test "tbreak $bp_location6" "Breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
286 # test break at line number in file
288 send_gdb "tbreak $srcfile:$bp_location2\n"
290 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
291 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
292 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
295 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
296 gdb_test "tbreak $srcfile:$bp_location11" "Breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
299 # check to see what breakpoints are set (temporary this time)
301 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
302 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
303 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:$bp_location7.*\[\r\n\]
304 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
305 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
306 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
307 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
308 "Temporary breakpoint info"
313 # Verify that catchpoints for fork, vfork and exec don't trigger
314 # inappropriately. (There are no calls to those system functions
315 # in this test program.)
317 if ![runto_main] then { fail "break tests suppressed" }
321 -re "Catch requires an event name.*$gdb_prompt $"\
322 {pass "catch requires an event name"}
324 {fail "catch requires an event name"}
325 timeout {fail "(timeout) catch requires an event name"}
329 set name "set catch fork, never expected to trigger"
330 send_gdb "catch fork\n"
332 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
334 -re "Catch of fork not yet implemented.*$gdb_prompt $"
338 timeout {fail "(timeout) $name"}
342 set name "set catch vfork, never expected to trigger"
343 send_gdb "catch vfork\n"
345 # If we are on HP-UX 10.20, we expect an error message to be
346 # printed if we type "catch vfork" at the gdb gdb_prompt. This is
347 # because on HP-UX 10.20, we cannot catch vfork events.
349 if [istarget "hppa*-hp-hpux10.20"] then {
351 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
355 timeout {fail "(timeout) $name"}
359 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
361 -re "Catch of vfork not yet implemented.*$gdb_prompt $"
365 timeout {fail "(timeout) $name"}
369 set name "set catch exec, never expected to trigger"
370 send_gdb "catch exec\n"
372 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
374 -re "Catch of exec not yet implemented.*$gdb_prompt $"
376 -re "$gdb_prompt $" {fail $name}
377 timeout {fail "(timeout) $name"}
380 # Verify that GDB responds gracefully when asked to set a breakpoint
381 # on a nonexistent source line.
383 send_gdb "break 999\n"
385 -re "No line 999 in file .*$gdb_prompt $"\
386 {pass "break on non-existent source line"}
388 {fail "break on non-existent source line"}
389 timeout {fail "(timeout) break on non-existent source line"}
392 # Run to the desired default location. If not positioned here, the
393 # tests below don't work.
395 gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
398 # Verify that GDB allows one to just say "break", which is treated
399 # as the "default" breakpoint. Note that GDB gets cute when printing
400 # the informational message about other breakpoints at the same
401 # location. We'll hit that bird with this stone too.
405 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
406 {pass "break on default location, 1st time"}
408 {fail "break on default location, 1st time"}
409 timeout {fail "(timeout) break on default location, 1st time"}
414 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
415 {pass "break on default location, 2nd time"}
417 {fail "break on default location, 2nd time"}
418 timeout {fail "(timeout) break on default location, 2nd time"}
423 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
424 {pass "break on default location, 3rd time"}
426 {fail "break on default location, 3rd time"}
427 timeout {fail "(timeout) break on default location, 3rd time"}
432 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
433 {pass "break on default location, 4th time"}
435 {fail "break on default location, 4th time"}
436 timeout {fail "(timeout) break on default location, 4th time"}
439 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
440 # "silent" about its triggering.
442 if ![runto_main] then { fail "break tests suppressed" }
444 send_gdb "break $bp_location1\n"
446 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
447 {pass "set to-be-silent break bp_location1"}
449 {fail "set to-be-silent break bp_location1"}
450 timeout {fail "(timeout) set to-be-silent break bp_location1"}
453 send_gdb "commands $expect_out(1,string)\n"
457 -re ".*$gdb_prompt $"\
458 {pass "set silent break bp_location1"}
459 timeout {fail "(timeout) set silent break bp_location1"}
462 send_gdb "info break $expect_out(1,string)\n"
464 -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
465 {pass "info silent break bp_location1"}
467 {fail "info silent break bp_location1"}
468 timeout {fail "(timeout) info silent break bp_location1"}
470 send_gdb "continue\n"
472 -re "Continuing.\r\n$gdb_prompt $"\
473 {pass "hit silent break bp_location1"}
475 {fail "hit silent break bp_location1"}
476 timeout {fail "(timeout) hit silent break bp_location1"}
480 -re "#0 main .* at .*:$bp_location1.*$gdb_prompt $"\
481 {pass "stopped for silent break bp_location1"}
483 {fail "stopped for silent break bp_location1"}
484 timeout {fail "(timeout) stopped for silent break bp_location1"}
487 # Verify that GDB can at least parse a breakpoint with the
488 # "thread" keyword. (We won't attempt to test here that a
489 # thread-specific breakpoint really triggers appropriately.
490 # The gdb.threads subdirectory contains tests for that.)
492 set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
493 send_gdb "break $bp_location12 thread 999\n"
495 -re "Unknown thread 999.*$gdb_prompt $"\
496 {pass "thread-specific breakpoint on non-existent thread disallowed"}
498 {fail "thread-specific breakpoint on non-existent thread disallowed"}
499 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
501 send_gdb "break $bp_location12 thread foo\n"
503 -re "Junk after thread keyword..*$gdb_prompt $"\
504 {pass "thread-specific breakpoint on bogus thread ID disallowed"}
506 {fail "thread-specific breakpoint on bogus thread ID disallowed"}
507 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
510 # Verify that GDB responds gracefully to a breakpoint command with
513 send_gdb "break $bp_location12 foo\n"
515 -re "Junk at end of arguments..*$gdb_prompt $"\
516 {pass "breakpoint with trailing garbage disallowed"}
518 {fail "breakpoint with trailing garbage disallowed"}
519 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
522 # Verify that GDB responds gracefully to a "clear" command that has
523 # no matching breakpoint. (First, get us off the current source line,
524 # which we know has a breakpoint.)
528 -re ".*$gdb_prompt $"\
529 {pass "step over breakpoint"}
530 timeout {fail "(timeout) step over breakpoint"}
532 send_gdb "clear 81\n"
534 -re "No breakpoint at 81..*$gdb_prompt $"\
535 {pass "clear line has no breakpoint disallowed"}
537 {fail "clear line has no breakpoint disallowed"}
538 timeout {fail "(timeout) clear line has no breakpoint disallowed"}
542 -re "No breakpoint at this line..*$gdb_prompt $"\
543 {pass "clear current line has no breakpoint disallowed"}
545 {fail "clear current line has no breakpoint disallowed"}
546 timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
549 # Verify that we can set and clear multiple breakpoints.
551 # We don't test that it deletes the correct breakpoints. We do at
552 # least test that it deletes more than one breakpoint.
554 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
555 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
556 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
558 # Verify that a breakpoint can be set via a convenience variable.
560 send_gdb "set \$foo=$bp_location11\n"
563 {pass "set convenience variable \$foo to bp_location11"}
564 timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
566 send_gdb "break \$foo\n"
568 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
569 {pass "set breakpoint via convenience variable"}
571 {fail "set breakpoint via convenience variable"}
572 timeout {fail "(timeout) set breakpoint via convenience variable"}
575 # Verify that GDB responds gracefully to an attempt to set a
576 # breakpoint via a convenience variable whose type is not integer.
578 send_gdb "set \$foo=81.5\n"
581 {pass "set convenience variable \$foo to 81.5"}
582 timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
584 send_gdb "break \$foo\n"
586 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
587 {pass "set breakpoint via non-integer convenience variable disallowed"}
589 {fail "set breakpoint via non-integer convenience variable disallowed"}
590 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
593 # Verify that we can set and trigger a breakpoint in a user-called function.
595 send_gdb "break marker2\n"
597 -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
598 {pass "set breakpoint on to-be-called function"}
600 {fail "set breakpoint on to-be-called function"}
601 timeout {fail "(timeout) set breakpoint on to-be-called function"}
603 send_gdb "print marker2(99)\n"
605 -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 $"\
606 {pass "hit breakpoint on called function"}
608 {fail "hit breakpoint on called function"}
609 timeout {fail "(timeout) hit breakpoint on called function"}
612 # As long as we're stopped (breakpointed) in a called function,
613 # verify that we can successfully backtrace & such from here.
615 # In this and the following test, the _sr4export check apparently is needed
620 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
621 {pass "backtrace while in called function"}
622 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
623 {pass "backtrace while in called function"}
625 {fail "backtrace while in called function"}
626 timeout {fail "(timeout) backtrace while in called function"}
629 # Return from the called function. For remote targets, it's important to do
630 # this before runto_main, which otherwise may silently stop on the dummy
631 # breakpoint inserted by GDB at the program's entry point.
635 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
636 {pass "finish from called function"}
637 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
638 {pass "finish from called function"}
639 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
640 {pass "finish from called function"}
642 {fail "finish from called function"}
643 timeout {fail "(timeout) finish from called function"}
646 # Verify that GDB responds gracefully to a "finish" command with
649 if ![runto_main] then { fail "break tests suppressed" }
651 send_gdb "finish 123\n"
653 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
654 {pass "finish with arguments disallowed"}
656 {fail "finish with arguments disallowed"}
657 timeout {fail "(timeout) finish with arguments disallowed"}
660 # Verify that GDB responds gracefully to a request to "finish" from
661 # the outermost frame. On a stub that never exits, this will just
662 # run to the stubs routine, so we don't get this error... Thus the
668 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
669 {pass "finish from outermost frame disallowed"}
670 -re "Run till exit from.*\r\n$gdb_prompt $" {
671 pass "finish from outermost frame disallowed"
674 {fail "finish from outermost frame disallowed"}
675 timeout {fail "(timeout) finish from outermost frame disallowed"}
678 # Verify that we can explicitly ask GDB to stop on all shared library
679 # events, and that it does so.
681 if [istarget "hppa*-*-hpux*"] then {
682 if ![runto_main] then { fail "break tests suppressed" }
684 send_gdb "set stop-on-solib-events 1\n"
687 {pass "set stop-on-solib-events"}
688 timeout {fail "(timeout) set stop-on-solib-events"}
693 -re ".*Start it from the beginning.*y or n. $"\
696 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
697 {pass "triggered stop-on-solib-events"}
699 {fail "triggered stop-on-solib-events"}
700 timeout {fail "(timeout) triggered stop-on-solib-events"}
704 {fail "rerun for stop-on-solib-events"}
705 timeout {fail "(timeout) rerun for stop-on-solib-events"}
708 send_gdb "set stop-on-solib-events 0\n"
711 {pass "reset stop-on-solib-events"}
712 timeout {fail "(timeout) reset stop-on-solib-events"}
716 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
717 # gracefully responds to requests to create them.
719 if [istarget "hppa*-*-hpux*"] then {
720 if ![runto_main] then { fail "break tests suppressed" }
724 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
725 {pass "hw breaks disallowed"}
727 {fail "hw breaks disallowed"}
728 timeout {fail "(timeout) hw breaks disallowed"}
733 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
734 {pass "temporary hw breaks disallowed"}
736 {fail "temporary hw breaks disallowed"}
737 timeout {fail "(timeout) temporary hw breaks disallowed"}
745 # Test "next" over recursive function call.
748 proc test_next_with_recursion {} {
753 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
756 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
758 # Run until we call factorial with 6
762 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
763 -re ".*$gdb_prompt $" {
764 fail "run to factorial(6)";
767 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
770 # Continue until we call factorial recursively with 5.
772 if [gdb_test "continue" \
773 "Continuing.*Break.* factorial .value=5. .*" \
774 "continue to factorial(5)"] then { gdb_suppress_tests }
776 # Do a backtrace just to confirm how many levels deep we are.
778 if [gdb_test "backtrace" \
779 "#0\[ \t\]+ factorial .value=5..*" \
780 "backtrace from factorial(5)"] then { gdb_suppress_tests }
782 # Now a "next" should position us at the recursive call, which
783 # we will be performing with 4.
785 if [gdb_test "next" \
786 ".* factorial .value - 1.;.*" \
787 "next to recursive call"] then { gdb_suppress_tests }
789 # Disable the breakpoint at the entry to factorial by deleting them all.
790 # The "next" should run until we return to the next line from this
791 # recursive call to factorial with 4.
792 # Buggy versions of gdb will stop instead at the innermost frame on
793 # the line where we are trying to "next" to.
797 if [istarget "mips*tx39-*"] {
800 # We used to set timeout here for all other targets as well. This
801 # is almost certainly wrong. The proper timeout depends on the
802 # target system in use, and how we communicate with it, so there
803 # is no single value appropriate for all targets. The timeout
804 # should be established by the Dejagnu config file(s) for the
805 # board, and respected by the test suite.
807 # For example, if I'm running GDB over an SSH tunnel talking to a
808 # portmaster in California talking to an ancient 68k board running
809 # a crummy ROM monitor (a situation I can only wish were
810 # hypothetical), then I need a large timeout. But that's not the
811 # kind of knowledge that belongs in this file.
813 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
814 "next over recursive call"
816 # OK, we should be back in the same stack frame we started from.
817 # Do a backtrace just to confirm.
819 set result [gdb_test "backtrace" \
820 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
821 "backtrace from factorial(5.1)"]
822 if { $result != 0 } { gdb_suppress_tests }
824 if [target_info exists gdb,noresults] { gdb_suppress_tests }
825 gdb_continue_to_end "recursive next test"
826 gdb_stop_suppressing_tests;
829 test_next_with_recursion
834 proc test_different_dir {type test_different_dir xfail} {
835 global srcdir subdir objdir binfile srcfile timeout gdb_prompt
837 global bp_location6 decimal hex
839 set old_pf_prefix $pf_prefix
840 append pf_prefix " $type:"
844 gdb_reinitialize_dir $srcdir/$subdir
845 gdb_test "set debug-file-directory ${test_different_dir}" ".*" "set separate debug location"
848 if [target_info exists gdb_stub] {
853 # test break at function
858 gdb_test "break main" \
859 "Breakpoint.*at.* file .*$srcfile, line.*" \
860 "breakpoint function, optimized file"
863 # test break at function
868 gdb_test "break marker4" \
869 "Breakpoint.*at.* file .*$srcfile, line.*" \
870 "breakpoint small function, optimized file"
873 # run until the breakpoint at main is hit. For non-stubs-using targets.
880 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
881 pass "run until function breakpoint, optimized file"
883 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $" {
884 pass "run until function breakpoint, optimized file (code motion)"
886 -re "$gdb_prompt $" {
887 fail "run until function breakpoint, optimized file"
890 fail "run until function breakpoint, optimized file (timeout)"
895 # run until the breakpoint at a small function
899 # Add a second pass pattern. The behavior differs here between stabs
900 # and dwarf for one-line functions. Stabs preserves two line symbols
901 # (one before the prologue and one after) with the same line number,
902 # but dwarf regards these as duplicates and discards one of them.
903 # Therefore the address after the prologue (where the breakpoint is)
904 # has no exactly matching line symbol, and GDB reports the breakpoint
905 # as if it were in the middle of a line rather than at the beginning.
907 set bp_location13 [gdb_get_line_number "set breakpoint 13 here"]
908 set bp_location14 [gdb_get_line_number "set breakpoint 14 here"]
909 send_gdb "continue\n"
914 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
915 pass "run until breakpoint set at small function, optimized file"
917 -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
918 pass "run until breakpoint set at small function, optimized file"
920 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
921 # marker4() is defined at line 46 when compiled with -DPROTOTYPES
922 pass "run until breakpoint set at small function, optimized file (line bp_location14)"
924 -re ".*$gdb_prompt " {
925 fail "run until breakpoint set at small function, optimized file"
928 fail "run until breakpoint set at small function, optimized file (timeout)"
933 # Reset the default arguments for VxWorks
934 if [istarget "*-*-vxworks*"] {
936 verbose "Timeout is now $timeout seconds" 2
937 send_gdb "set args main\n"
938 gdb_expect -re ".*$gdb_prompt $" {}
941 set pf_prefix $old_pf_prefix
942 # proc test_different_dir
946 # now move the .debug file to a different location so that we can test
947 # the "set debug-file-directory" command.
949 remote_exec build "mv ${objdir}/${subdir}/.debug/${testfile}.debug ${objdir}/${subdir}"
950 set debugfile "${objdir}/${subdir}/${testfile}.debug"
952 test_different_dir debuglink "${objdir}/${subdir}" 0
955 # NT_GNU_BUILD_ID / .note.gnu.build-id test:
957 set build_id_debug_filename [build_id_debug_filename_get $binfile]
958 if ![string compare $build_id_debug_filename ""] then {
959 unsupported "build-id is not supported by the compiler"
961 # Spare debug files may confuse testsuite runs in the future.
962 remote_exec build "rm -f $debugfile"
964 set build_id_debugself_filename [build_id_debug_filename_get $debugfile]
965 set test "build-id support by binutils"
967 if ![string compare $build_id_debugself_filename ""] then {
970 } elseif {[string compare $build_id_debugself_filename $build_id_debug_filename] != 0} then {
976 file mkdir [file dirname ${objdir}/${subdir}/${build_id_debug_filename}]
977 remote_exec build "mv $debugfile ${objdir}/${subdir}/${build_id_debug_filename}"
979 test_different_dir build-id "${objdir}/${subdir}" $xfail
981 # Spare debug files may confuse testsuite runs in the future.
982 remote_exec build "rm -f ${objdir}/${subdir}/${build_id_debug_filename}"