1 # Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
2 # 2000, 2002, 2003, 2004, 2007, 2008, 2009 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 # Based on break.exp, written by Rob Savoye. (rob@cygnus.com)
18 # Modified to test gdb's handling of separate debug info files.
19 # Modified to test gdb's handling of a debug-id retrieval.
21 # This file has two parts. The first is testing that gdb behaves
22 # normally after reading in an executable and its corresponding
23 # separate debug file. The second moves the .debug file to a different
24 # location and tests the "set debug-file-directory" command.
25 # The third is for testing build-id retrievel by finding the separate
26 # ".debug-id/ab/cdef.debug" file.
34 # test running programs
39 set testfile "sepdebug"
40 set srcfile ${testfile}.c
41 set binfile ${objdir}/${subdir}/${testfile}${EXEEXT}
43 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
48 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
49 # ${binfile}, which is just like the executable ($binfile) but without
50 # the debuginfo. Instead $binfile has a .gnudebuglink section which contains
51 # the name of a debuginfo only file. This file will be stored in the
52 # gdb.base/.debug subdirectory.
54 if [gdb_gnu_strip_debug $binfile] {
55 # check that you have a recent version of strip and objcopy installed
56 unsupported "cannot produce separate debug info files"
62 gdb_reinitialize_dir $srcdir/$subdir
65 if [target_info exists gdb_stub] {
69 # test simple breakpoint setting commands
72 # Test deleting all breakpoints when there are none installed,
73 # GDB should not prompt for confirmation.
74 # Note that gdb-init.exp provides a "delete_breakpoints" proc
75 # for general use elsewhere.
77 send_gdb "delete breakpoints\n"
79 -re "Delete all breakpoints.*$" {
83 fail "Delete all breakpoints when none (unexpected prompt)"
85 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
88 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
89 timeout { fail "Delete all breakpoints when none (timeout)" }
93 # test break at function
95 gdb_test "break main" \
96 "Breakpoint.*at.* file .*$srcfile, line.*" \
100 # test break at quoted function
102 gdb_test "break \"marker2\"" \
103 "Breakpoint.*at.* file .*$srcfile, line.*" \
104 "breakpoint quoted function"
107 # test break at function in file
109 gdb_test "break $srcfile:factorial" \
110 "Breakpoint.*at.* file .*$srcfile, line.*" \
111 "breakpoint function in file"
113 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
116 # test break at line number
118 # Note that the default source file is the last one whose source text
119 # was printed. For native debugging, before we've executed the
120 # program, this is the file containing main, but for remote debugging,
121 # it's wherever the processor was stopped when we connected to the
122 # board. So, to be sure, we do a list command.
124 gdb_test "list main" \
125 ".*main \\(argc, argv, envp\\).*" \
126 "use `list' to establish default source file"
127 gdb_test "break $bp_location1" \
128 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
129 "breakpoint line number"
132 # test duplicate breakpoint
134 gdb_test "break $bp_location1" \
135 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
136 "breakpoint duplicate"
138 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
141 # test break at line number in file
143 gdb_test "break $srcfile:$bp_location2" \
144 "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
145 "breakpoint line number in file"
147 set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
148 set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
151 # Test putting a break at the start of a multi-line if conditional.
152 # Verify the breakpoint was put at the start of the conditional.
154 gdb_test "break multi_line_if_conditional" \
155 "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
156 "breakpoint at start of multi line if conditional"
158 gdb_test "break multi_line_while_conditional" \
159 "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
160 "breakpoint at start of multi line while conditional"
162 set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
163 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
166 # check to see what breakpoints are set
168 if [target_info exists gdb_stub] {
169 set main_line $bp_location5
171 set main_line $bp_location6
174 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
175 set bp_location8 [gdb_get_line_number "set breakpoint 8 here"]
176 set bp_location9 [gdb_get_line_number "set breakpoint 9 here"]
178 gdb_test "info break" \
179 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
180 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
181 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile:($bp_location8|$bp_location9).*
182 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:$bp_location7.*
183 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
184 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
185 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location2.*
186 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
187 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
190 # FIXME: The rest of this test doesn't work with anything that can't
192 # Huh? There doesn't *appear* to be anything that passes arguments
194 if [istarget "mips-idt-*"] then {
199 # run until the breakpoint at main is hit. For non-stubs-using targets.
203 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
204 pass "run until function breakpoint"
206 -re "$gdb_prompt $" {
207 fail "run until function breakpoint"
210 fail "run until function breakpoint (timeout)"
215 # run until the breakpoint at a line number
217 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
218 "run until breakpoint set at a line number"
221 # Run until the breakpoint set in a function in a file
223 for {set i 6} {$i >= 1} {incr i -1} {
224 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
225 "run until file:function($i) breakpoint"
229 # Run until the breakpoint set at a quoted function
231 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile:($bp_location8|$bp_location9).*" \
232 "run until quoted breakpoint"
234 # run until the file:function breakpoint at a line number in a file
236 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
237 "run until file:linenum breakpoint"
239 # Test break at offset +1
240 set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
242 gdb_test "break +1" \
243 "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
244 "breakpoint offset +1"
246 # Check to see if breakpoint is hit when stepped onto
249 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
250 "step onto breakpoint"
253 # delete all breakpoints so we can start over, course this can be a test too
258 # test temporary breakpoint at function
261 gdb_test "tbreak main" "Temporary breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
264 # test break at function in file
267 gdb_test "tbreak $srcfile:factorial" "Temporary breakpoint.*at.* file .*$srcfile, line.*" \
268 "Temporary breakpoint function in file"
271 # test break at line number
273 send_gdb "tbreak $bp_location1\n"
275 -re "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
276 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
277 timeout { fail "breakpoint line number #1 (timeout)" }
280 gdb_test "tbreak $bp_location6" "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
283 # test break at line number in file
285 send_gdb "tbreak $srcfile:$bp_location2\n"
287 -re "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
288 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
289 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
292 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
293 gdb_test "tbreak $srcfile:$bp_location11" "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
296 # check to see what breakpoints are set (temporary this time)
298 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
299 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
300 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:$bp_location7.*\[\r\n\]
301 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
302 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
303 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
304 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
305 "Temporary breakpoint info"
310 # Verify that catchpoints for fork, vfork and exec don't trigger
311 # inappropriately. (There are no calls to those system functions
312 # in this test program.)
314 if ![runto_main] then { fail "break tests suppressed" }
318 -re "Catch requires an event name.*$gdb_prompt $"\
319 {pass "catch requires an event name"}
321 {fail "catch requires an event name"}
322 timeout {fail "(timeout) catch requires an event name"}
326 set name "set catch fork, never expected to trigger"
327 send_gdb "catch fork\n"
329 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
331 -re "Catch of fork not yet implemented.*$gdb_prompt $"
335 timeout {fail "(timeout) $name"}
339 set name "set catch vfork, never expected to trigger"
340 send_gdb "catch vfork\n"
342 # If we are on HP-UX 10.20, we expect an error message to be
343 # printed if we type "catch vfork" at the gdb gdb_prompt. This is
344 # because on HP-UX 10.20, we cannot catch vfork events.
346 if [istarget "hppa*-hp-hpux10.20"] then {
348 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
352 timeout {fail "(timeout) $name"}
356 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
358 -re "Catch of vfork not yet implemented.*$gdb_prompt $"
362 timeout {fail "(timeout) $name"}
366 set name "set catch exec, never expected to trigger"
367 send_gdb "catch exec\n"
369 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
371 -re "Catch of exec not yet implemented.*$gdb_prompt $"
373 -re "$gdb_prompt $" {fail $name}
374 timeout {fail "(timeout) $name"}
377 # Verify that GDB responds gracefully when asked to set a breakpoint
378 # on a nonexistent source line.
380 send_gdb "break 999\n"
382 -re "No line 999 in file .*$gdb_prompt $"\
383 {pass "break on non-existent source line"}
385 {fail "break on non-existent source line"}
386 timeout {fail "(timeout) break on non-existent source line"}
389 # Run to the desired default location. If not positioned here, the
390 # tests below don't work.
392 gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
395 # Verify that GDB allows one to just say "break", which is treated
396 # as the "default" breakpoint. Note that GDB gets cute when printing
397 # the informational message about other breakpoints at the same
398 # location. We'll hit that bird with this stone too.
402 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
403 {pass "break on default location, 1st time"}
405 {fail "break on default location, 1st time"}
406 timeout {fail "(timeout) break on default location, 1st time"}
411 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
412 {pass "break on default location, 2nd time"}
414 {fail "break on default location, 2nd time"}
415 timeout {fail "(timeout) break on default location, 2nd time"}
420 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
421 {pass "break on default location, 3rd time"}
423 {fail "break on default location, 3rd time"}
424 timeout {fail "(timeout) break on default location, 3rd time"}
429 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
430 {pass "break on default location, 4th time"}
432 {fail "break on default location, 4th time"}
433 timeout {fail "(timeout) break on default location, 4th time"}
436 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
437 # "silent" about its triggering.
439 if ![runto_main] then { fail "break tests suppressed" }
441 send_gdb "break $bp_location1\n"
443 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
444 {pass "set to-be-silent break bp_location1"}
446 {fail "set to-be-silent break bp_location1"}
447 timeout {fail "(timeout) set to-be-silent break bp_location1"}
450 send_gdb "commands $expect_out(1,string)\n"
454 -re ".*$gdb_prompt $"\
455 {pass "set silent break bp_location1"}
456 timeout {fail "(timeout) set silent break bp_location1"}
459 send_gdb "info break $expect_out(1,string)\n"
461 -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
462 {pass "info silent break bp_location1"}
464 {fail "info silent break bp_location1"}
465 timeout {fail "(timeout) info silent break bp_location1"}
467 send_gdb "continue\n"
469 -re "Continuing.\r\n$gdb_prompt $"\
470 {pass "hit silent break bp_location1"}
472 {fail "hit silent break bp_location1"}
473 timeout {fail "(timeout) hit silent break bp_location1"}
477 -re "#0 main .* at .*:$bp_location1.*$gdb_prompt $"\
478 {pass "stopped for silent break bp_location1"}
480 {fail "stopped for silent break bp_location1"}
481 timeout {fail "(timeout) stopped for silent break bp_location1"}
484 # Verify that GDB can at least parse a breakpoint with the
485 # "thread" keyword. (We won't attempt to test here that a
486 # thread-specific breakpoint really triggers appropriately.
487 # The gdb.threads subdirectory contains tests for that.)
489 set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
490 send_gdb "break $bp_location12 thread 999\n"
492 -re "Unknown thread 999.*$gdb_prompt $"\
493 {pass "thread-specific breakpoint on non-existent thread disallowed"}
495 {fail "thread-specific breakpoint on non-existent thread disallowed"}
496 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
498 send_gdb "break $bp_location12 thread foo\n"
500 -re "Junk after thread keyword..*$gdb_prompt $"\
501 {pass "thread-specific breakpoint on bogus thread ID disallowed"}
503 {fail "thread-specific breakpoint on bogus thread ID disallowed"}
504 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
507 # Verify that GDB responds gracefully to a breakpoint command with
510 send_gdb "break $bp_location12 foo\n"
512 -re "Junk at end of arguments..*$gdb_prompt $"\
513 {pass "breakpoint with trailing garbage disallowed"}
515 {fail "breakpoint with trailing garbage disallowed"}
516 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
519 # Verify that GDB responds gracefully to a "clear" command that has
520 # no matching breakpoint. (First, get us off the current source line,
521 # which we know has a breakpoint.)
525 -re ".*$gdb_prompt $"\
526 {pass "step over breakpoint"}
527 timeout {fail "(timeout) step over breakpoint"}
529 send_gdb "clear 81\n"
531 -re "No breakpoint at 81..*$gdb_prompt $"\
532 {pass "clear line has no breakpoint disallowed"}
534 {fail "clear line has no breakpoint disallowed"}
535 timeout {fail "(timeout) clear line has no breakpoint disallowed"}
539 -re "No breakpoint at this line..*$gdb_prompt $"\
540 {pass "clear current line has no breakpoint disallowed"}
542 {fail "clear current line has no breakpoint disallowed"}
543 timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
546 # Verify that we can set and clear multiple breakpoints.
548 # We don't test that it deletes the correct breakpoints. We do at
549 # least test that it deletes more than one breakpoint.
551 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
552 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
553 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
555 # Verify that a breakpoint can be set via a convenience variable.
557 send_gdb "set \$foo=$bp_location11\n"
560 {pass "set convenience variable \$foo to bp_location11"}
561 timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
563 send_gdb "break \$foo\n"
565 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
566 {pass "set breakpoint via convenience variable"}
568 {fail "set breakpoint via convenience variable"}
569 timeout {fail "(timeout) set breakpoint via convenience variable"}
572 # Verify that GDB responds gracefully to an attempt to set a
573 # breakpoint via a convenience variable whose type is not integer.
575 send_gdb "set \$foo=81.5\n"
578 {pass "set convenience variable \$foo to 81.5"}
579 timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
581 send_gdb "break \$foo\n"
583 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
584 {pass "set breakpoint via non-integer convenience variable disallowed"}
586 {fail "set breakpoint via non-integer convenience variable disallowed"}
587 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
590 # Verify that we can set and trigger a breakpoint in a user-called function.
592 send_gdb "break marker2\n"
594 -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
595 {pass "set breakpoint on to-be-called function"}
597 {fail "set breakpoint on to-be-called function"}
598 timeout {fail "(timeout) set breakpoint on to-be-called function"}
600 send_gdb "print marker2(99)\n"
602 -re "The program being debugged stopped while in a function called from GDB.\r\nEvaluation of the expression containing the function\r\n.marker2. will be abandoned.\r\nWhen the function is done executing, GDB will silently stop..*$gdb_prompt $"\
603 {pass "hit breakpoint on called function"}
605 {fail "hit breakpoint on called function"}
606 timeout {fail "(timeout) hit breakpoint on called function"}
609 # As long as we're stopped (breakpointed) in a called function,
610 # verify that we can successfully backtrace & such from here.
612 # In this and the following test, the _sr4export check apparently is needed
617 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
618 {pass "backtrace while in called function"}
619 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
620 {pass "backtrace while in called function"}
622 {fail "backtrace while in called function"}
623 timeout {fail "(timeout) backtrace while in called function"}
626 # Return from the called function. For remote targets, it's important to do
627 # this before runto_main, which otherwise may silently stop on the dummy
628 # breakpoint inserted by GDB at the program's entry point.
632 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
633 {pass "finish from called function"}
634 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
635 {pass "finish from called function"}
636 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
637 {pass "finish from called function"}
639 {fail "finish from called function"}
640 timeout {fail "(timeout) finish from called function"}
643 # Verify that GDB responds gracefully to a "finish" command with
646 if ![runto_main] then { fail "break tests suppressed" }
648 send_gdb "finish 123\n"
650 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
651 {pass "finish with arguments disallowed"}
653 {fail "finish with arguments disallowed"}
654 timeout {fail "(timeout) finish with arguments disallowed"}
657 # Verify that GDB responds gracefully to a request to "finish" from
658 # the outermost frame. On a stub that never exits, this will just
659 # run to the stubs routine, so we don't get this error... Thus the
665 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
666 {pass "finish from outermost frame disallowed"}
667 -re "Run till exit from.*\r\n$gdb_prompt $" {
668 pass "finish from outermost frame disallowed"
671 {fail "finish from outermost frame disallowed"}
672 timeout {fail "(timeout) finish from outermost frame disallowed"}
675 # Verify that we can explicitly ask GDB to stop on all shared library
676 # events, and that it does so.
678 if [istarget "hppa*-*-hpux*"] then {
679 if ![runto_main] then { fail "break tests suppressed" }
681 send_gdb "set stop-on-solib-events 1\n"
684 {pass "set stop-on-solib-events"}
685 timeout {fail "(timeout) set stop-on-solib-events"}
690 -re ".*Start it from the beginning.*y or n. $"\
693 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
694 {pass "triggered stop-on-solib-events"}
696 {fail "triggered stop-on-solib-events"}
697 timeout {fail "(timeout) triggered stop-on-solib-events"}
701 {fail "rerun for stop-on-solib-events"}
702 timeout {fail "(timeout) rerun for stop-on-solib-events"}
705 send_gdb "set stop-on-solib-events 0\n"
708 {pass "reset stop-on-solib-events"}
709 timeout {fail "(timeout) reset stop-on-solib-events"}
713 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
714 # gracefully responds to requests to create them.
716 if [istarget "hppa*-*-hpux*"] then {
717 if ![runto_main] then { fail "break tests suppressed" }
721 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
722 {pass "hw breaks disallowed"}
724 {fail "hw breaks disallowed"}
725 timeout {fail "(timeout) hw breaks disallowed"}
730 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
731 {pass "temporary hw breaks disallowed"}
733 {fail "temporary hw breaks disallowed"}
734 timeout {fail "(timeout) temporary hw breaks disallowed"}
742 # Test "next" over recursive function call.
745 proc test_next_with_recursion {} {
750 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
753 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
755 # Run until we call factorial with 6
759 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
760 -re ".*$gdb_prompt $" {
761 fail "run to factorial(6)";
764 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
767 # Continue until we call factorial recursively with 5.
769 if [gdb_test "continue" \
770 "Continuing.*Break.* factorial .value=5. .*" \
771 "continue to factorial(5)"] then { gdb_suppress_tests }
773 # Do a backtrace just to confirm how many levels deep we are.
775 if [gdb_test "backtrace" \
776 "#0\[ \t\]+ factorial .value=5..*" \
777 "backtrace from factorial(5)"] then { gdb_suppress_tests }
779 # Now a "next" should position us at the recursive call, which
780 # we will be performing with 4.
782 if [gdb_test "next" \
783 ".* factorial .value - 1.;.*" \
784 "next to recursive call"] then { gdb_suppress_tests }
786 # Disable the breakpoint at the entry to factorial by deleting them all.
787 # The "next" should run until we return to the next line from this
788 # recursive call to factorial with 4.
789 # Buggy versions of gdb will stop instead at the innermost frame on
790 # the line where we are trying to "next" to.
794 if [istarget "mips*tx39-*"] {
797 # We used to set timeout here for all other targets as well. This
798 # is almost certainly wrong. The proper timeout depends on the
799 # target system in use, and how we communicate with it, so there
800 # is no single value appropriate for all targets. The timeout
801 # should be established by the Dejagnu config file(s) for the
802 # board, and respected by the test suite.
804 # For example, if I'm running GDB over an SSH tunnel talking to a
805 # portmaster in California talking to an ancient 68k board running
806 # a crummy ROM monitor (a situation I can only wish were
807 # hypothetical), then I need a large timeout. But that's not the
808 # kind of knowledge that belongs in this file.
810 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
811 "next over recursive call"
813 # OK, we should be back in the same stack frame we started from.
814 # Do a backtrace just to confirm.
816 set result [gdb_test "backtrace" \
817 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
818 "backtrace from factorial(5.1)"]
819 if { $result != 0 } { gdb_suppress_tests }
821 if [target_info exists gdb,noresults] { gdb_suppress_tests }
822 gdb_continue_to_end "recursive next test"
823 gdb_stop_suppressing_tests;
826 test_next_with_recursion
831 proc test_different_dir {type test_different_dir xfail} {
832 global srcdir subdir objdir binfile srcfile timeout gdb_prompt
834 global bp_location6 decimal hex
836 set old_pf_prefix $pf_prefix
837 append pf_prefix " $type:"
841 gdb_reinitialize_dir $srcdir/$subdir
842 gdb_test "set debug-file-directory ${test_different_dir}" ".*" "set separate debug location"
845 if [target_info exists gdb_stub] {
850 # test break at function
855 gdb_test "break main" \
856 "Breakpoint.*at.* file .*$srcfile, line.*" \
857 "breakpoint function, optimized file"
860 # test break at function
865 gdb_test "break marker4" \
866 "Breakpoint.*at.* file .*$srcfile, line.*" \
867 "breakpoint small function, optimized file"
870 # run until the breakpoint at main is hit. For non-stubs-using targets.
877 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
878 pass "run until function breakpoint, optimized file"
880 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $" {
881 pass "run until function breakpoint, optimized file (code motion)"
883 -re "$gdb_prompt $" {
884 fail "run until function breakpoint, optimized file"
887 fail "run until function breakpoint, optimized file (timeout)"
892 # run until the breakpoint at a small function
896 # Add a second pass pattern. The behavior differs here between stabs
897 # and dwarf for one-line functions. Stabs preserves two line symbols
898 # (one before the prologue and one after) with the same line number,
899 # but dwarf regards these as duplicates and discards one of them.
900 # Therefore the address after the prologue (where the breakpoint is)
901 # has no exactly matching line symbol, and GDB reports the breakpoint
902 # as if it were in the middle of a line rather than at the beginning.
904 set bp_location13 [gdb_get_line_number "set breakpoint 13 here"]
905 set bp_location14 [gdb_get_line_number "set breakpoint 14 here"]
906 send_gdb "continue\n"
911 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
912 pass "run until breakpoint set at small function, optimized file"
914 -re "Breakpoint $decimal, $hex in 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, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
918 # marker4() is defined at line 46 when compiled with -DPROTOTYPES
919 pass "run until breakpoint set at small function, optimized file (line bp_location14)"
921 -re ".*$gdb_prompt " {
922 fail "run until breakpoint set at small function, optimized file"
925 fail "run until breakpoint set at small function, optimized file (timeout)"
930 # Reset the default arguments for VxWorks
931 if [istarget "*-*-vxworks*"] {
933 verbose "Timeout is now $timeout seconds" 2
934 send_gdb "set args main\n"
935 gdb_expect -re ".*$gdb_prompt $" {}
938 set pf_prefix $old_pf_prefix
939 # proc test_different_dir
943 # now move the .debug file to a different location so that we can test
944 # the "set debug-file-directory" command.
946 remote_exec build "mv ${objdir}/${subdir}/.debug/${testfile}.debug ${objdir}/${subdir}"
947 set debugfile "${objdir}/${subdir}/${testfile}.debug"
949 test_different_dir debuglink "${objdir}/${subdir}" 0
952 # NT_GNU_BUILD_ID / .note.gnu.build-id test:
954 set build_id_debug_filename [build_id_debug_filename_get $binfile]
955 if ![string compare $build_id_debug_filename ""] then {
956 unsupported "build-id is not supported by the compiler"
958 # Spare debug files may confuse testsuite runs in the future.
959 remote_exec build "rm -f $debugfile"
961 set build_id_debugself_filename [build_id_debug_filename_get $debugfile]
962 set test "build-id support by binutils"
964 if ![string compare $build_id_debugself_filename ""] then {
967 } elseif {[string compare $build_id_debugself_filename $build_id_debug_filename] != 0} then {
973 file mkdir [file dirname ${objdir}/${subdir}/${build_id_debug_filename}]
974 remote_exec build "mv $debugfile ${objdir}/${subdir}/${build_id_debug_filename}"
976 test_different_dir build-id "${objdir}/${subdir}" $xfail
978 # Spare debug files may confuse testsuite runs in the future.
979 remote_exec build "rm -f ${objdir}/${subdir}/${build_id_debug_filename}"