1 # Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
2 # 2000, 2002, 2003, 2004, 2007, 2008, 2009, 2010
3 # Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Based on break.exp, written by Rob Savoye. (rob@cygnus.com)
19 # Modified to test gdb's handling of separate debug info files.
20 # Modified to test gdb's handling of a debug-id retrieval.
22 # This file has two parts. The first is testing that gdb behaves
23 # normally after reading in an executable and its corresponding
24 # separate debug file. The second moves the .debug file to a different
25 # location and tests the "set debug-file-directory" command.
26 # The third is for testing build-id retrievel by finding the separate
27 # ".debug-id/ab/cdef.debug" file.
35 # test running programs
40 set testfile "sepdebug"
41 set srcfile ${testfile}.c
42 set binfile ${objdir}/${subdir}/${testfile}${EXEEXT}
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
49 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
50 # ${binfile}, which is just like the executable ($binfile) but without
51 # the debuginfo. Instead $binfile has a .gnudebuglink section which contains
52 # the name of a debuginfo only file. This file will be stored in the
53 # gdb.base/.debug subdirectory.
55 if [gdb_gnu_strip_debug $binfile] {
56 # check that you have a recent version of strip and objcopy installed
57 unsupported "cannot produce separate debug info files"
63 gdb_reinitialize_dir $srcdir/$subdir
65 if { $gdb_file_cmd_debug_info != "debug" } then {
66 fail "No debug information found."
69 if [target_info exists gdb_stub] {
73 # test simple breakpoint setting commands
76 # Test deleting all breakpoints when there are none installed,
77 # GDB should not prompt for confirmation.
78 # Note that gdb-init.exp provides a "delete_breakpoints" proc
79 # for general use elsewhere.
81 send_gdb "delete breakpoints\n"
83 -re "Delete all breakpoints.*$" {
87 fail "Delete all breakpoints when none (unexpected prompt)"
89 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
92 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
93 timeout { fail "Delete all breakpoints when none (timeout)" }
97 # test break at function
99 gdb_test "break main" \
100 "Breakpoint.*at.* file .*$srcfile, line.*" \
101 "breakpoint function"
104 # test break at quoted function
106 gdb_test "break \"marker2\"" \
107 "Breakpoint.*at.* file .*$srcfile, line.*" \
108 "breakpoint quoted function"
111 # test break at function in file
113 gdb_test "break $srcfile:factorial" \
114 "Breakpoint.*at.* file .*$srcfile, line.*" \
115 "breakpoint function in file"
117 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
120 # test break at line number
122 # Note that the default source file is the last one whose source text
123 # was printed. For native debugging, before we've executed the
124 # program, this is the file containing main, but for remote debugging,
125 # it's wherever the processor was stopped when we connected to the
126 # board. So, to be sure, we do a list command.
128 gdb_test "list main" \
129 ".*main \\(argc, argv, envp\\).*" \
130 "use `list' to establish default source file"
131 gdb_test "break $bp_location1" \
132 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
133 "breakpoint line number"
136 # test duplicate breakpoint
138 gdb_test "break $bp_location1" \
139 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
140 "breakpoint duplicate"
142 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
145 # test break at line number in file
147 gdb_test "break $srcfile:$bp_location2" \
148 "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
149 "breakpoint line number in file"
151 set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
152 set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
155 # Test putting a break at the start of a multi-line if conditional.
156 # Verify the breakpoint was put at the start of the conditional.
158 gdb_test "break multi_line_if_conditional" \
159 "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
160 "breakpoint at start of multi line if conditional"
162 gdb_test "break multi_line_while_conditional" \
163 "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
164 "breakpoint at start of multi line while conditional"
166 set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
167 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
170 # check to see what breakpoints are set
172 if [target_info exists gdb_stub] {
173 set main_line $bp_location5
175 set main_line $bp_location6
178 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
179 set bp_location8 [gdb_get_line_number "set breakpoint 8 here"]
180 set bp_location9 [gdb_get_line_number "set breakpoint 9 here"]
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 .*$srcfile:($bp_location8|$bp_location9).*
186 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial 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.
207 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
208 pass "run until function breakpoint"
210 -re "$gdb_prompt $" {
211 fail "run until function breakpoint"
214 fail "run until function breakpoint (timeout)"
219 # run until the breakpoint at a line number
221 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
222 "run until breakpoint set at a line number"
225 # Run until the breakpoint set in a function in a file
227 for {set i 6} {$i >= 1} {incr i -1} {
228 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
229 "run until file:function($i) breakpoint"
233 # Run until the breakpoint set at a quoted function
235 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile:($bp_location8|$bp_location9).*" \
236 "run until quoted breakpoint"
238 # run until the file:function breakpoint at a line number in a file
240 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
241 "run until file:linenum breakpoint"
243 # Test break at offset +1
244 set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
246 gdb_test "break +1" \
247 "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
248 "breakpoint offset +1"
250 # Check to see if breakpoint is hit when stepped onto
253 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
254 "step onto breakpoint"
257 # delete all breakpoints so we can start over, course this can be a test too
262 # test temporary breakpoint at function
265 gdb_test "tbreak main" "Temporary breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
268 # test break at function in file
271 gdb_test "tbreak $srcfile:factorial" "Temporary breakpoint.*at.* file .*$srcfile, line.*" \
272 "Temporary breakpoint function in file"
275 # test break at line number
277 send_gdb "tbreak $bp_location1\n"
279 -re "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
280 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
281 timeout { fail "breakpoint line number #1 (timeout)" }
284 gdb_test "tbreak $bp_location6" "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
287 # test break at line number in file
289 send_gdb "tbreak $srcfile:$bp_location2\n"
291 -re "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
292 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
293 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
296 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
297 gdb_test "tbreak $srcfile:$bp_location11" "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
300 # check to see what breakpoints are set (temporary this time)
302 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
303 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
304 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:$bp_location7.*\[\r\n\]
305 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
306 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
307 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
308 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
309 "Temporary breakpoint info"
314 # Verify that catchpoints for fork, vfork and exec don't trigger
315 # inappropriately. (There are no calls to those system functions
316 # in this test program.)
318 if ![runto_main] then { fail "break tests suppressed" }
322 -re "Catch requires an event name.*$gdb_prompt $"\
323 {pass "catch requires an event name"}
325 {fail "catch requires an event name"}
326 timeout {fail "(timeout) catch requires an event name"}
330 set name "set catch fork, never expected to trigger"
331 send_gdb "catch fork\n"
333 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
335 -re "Catch of fork not yet implemented.*$gdb_prompt $"
339 timeout {fail "(timeout) $name"}
343 set name "set catch vfork, never expected to trigger"
344 send_gdb "catch vfork\n"
346 # If we are on HP-UX 10.20, we expect an error message to be
347 # printed if we type "catch vfork" at the gdb gdb_prompt. This is
348 # because on HP-UX 10.20, we cannot catch vfork events.
350 if [istarget "hppa*-hp-hpux10.20"] then {
352 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
356 timeout {fail "(timeout) $name"}
360 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
362 -re "Catch of vfork not yet implemented.*$gdb_prompt $"
366 timeout {fail "(timeout) $name"}
370 set name "set catch exec, never expected to trigger"
371 send_gdb "catch exec\n"
373 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
375 -re "Catch of exec not yet implemented.*$gdb_prompt $"
377 -re "$gdb_prompt $" {fail $name}
378 timeout {fail "(timeout) $name"}
381 # Verify that GDB responds gracefully when asked to set a breakpoint
382 # on a nonexistent source line.
384 send_gdb "break 999\n"
386 -re "No line 999 in file .*$gdb_prompt $"\
387 {pass "break on non-existent source line"}
389 {fail "break on non-existent source line"}
390 timeout {fail "(timeout) break on non-existent source line"}
393 # Run to the desired default location. If not positioned here, the
394 # tests below don't work.
396 gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
399 # Verify that GDB allows one to just say "break", which is treated
400 # as the "default" breakpoint. Note that GDB gets cute when printing
401 # the informational message about other breakpoints at the same
402 # location. We'll hit that bird with this stone too.
406 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
407 {pass "break on default location, 1st time"}
409 {fail "break on default location, 1st time"}
410 timeout {fail "(timeout) break on default location, 1st time"}
415 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
416 {pass "break on default location, 2nd time"}
418 {fail "break on default location, 2nd time"}
419 timeout {fail "(timeout) break on default location, 2nd time"}
424 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
425 {pass "break on default location, 3rd time"}
427 {fail "break on default location, 3rd time"}
428 timeout {fail "(timeout) break on default location, 3rd time"}
433 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
434 {pass "break on default location, 4th time"}
436 {fail "break on default location, 4th time"}
437 timeout {fail "(timeout) break on default location, 4th time"}
440 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
441 # "silent" about its triggering.
443 if ![runto_main] then { fail "break tests suppressed" }
445 send_gdb "break $bp_location1\n"
447 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
448 {pass "set to-be-silent break bp_location1"}
450 {fail "set to-be-silent break bp_location1"}
451 timeout {fail "(timeout) set to-be-silent break bp_location1"}
454 send_gdb "commands $expect_out(1,string)\n"
458 -re ".*$gdb_prompt $"\
459 {pass "set silent break bp_location1"}
460 timeout {fail "(timeout) set silent break bp_location1"}
463 send_gdb "info break $expect_out(1,string)\n"
465 -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
466 {pass "info silent break bp_location1"}
468 {fail "info silent break bp_location1"}
469 timeout {fail "(timeout) info silent break bp_location1"}
471 send_gdb "continue\n"
473 -re "Continuing.\r\n$gdb_prompt $"\
474 {pass "hit silent break bp_location1"}
476 {fail "hit silent break bp_location1"}
477 timeout {fail "(timeout) hit silent break bp_location1"}
481 -re "#0 main .* at .*:$bp_location1.*$gdb_prompt $"\
482 {pass "stopped for silent break bp_location1"}
484 {fail "stopped for silent break bp_location1"}
485 timeout {fail "(timeout) stopped for silent break bp_location1"}
488 # Verify that GDB can at least parse a breakpoint with the
489 # "thread" keyword. (We won't attempt to test here that a
490 # thread-specific breakpoint really triggers appropriately.
491 # The gdb.threads subdirectory contains tests for that.)
493 set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
494 send_gdb "break $bp_location12 thread 999\n"
496 -re "Unknown thread 999.*$gdb_prompt $"\
497 {pass "thread-specific breakpoint on non-existent thread disallowed"}
499 {fail "thread-specific breakpoint on non-existent thread disallowed"}
500 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
502 send_gdb "break $bp_location12 thread foo\n"
504 -re "Junk after thread keyword..*$gdb_prompt $"\
505 {pass "thread-specific breakpoint on bogus thread ID disallowed"}
507 {fail "thread-specific breakpoint on bogus thread ID disallowed"}
508 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
511 # Verify that GDB responds gracefully to a breakpoint command with
514 send_gdb "break $bp_location12 foo\n"
516 -re "Junk at end of arguments..*$gdb_prompt $"\
517 {pass "breakpoint with trailing garbage disallowed"}
519 {fail "breakpoint with trailing garbage disallowed"}
520 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
523 # Verify that GDB responds gracefully to a "clear" command that has
524 # no matching breakpoint. (First, get us off the current source line,
525 # which we know has a breakpoint.)
529 -re ".*$gdb_prompt $"\
530 {pass "step over breakpoint"}
531 timeout {fail "(timeout) step over breakpoint"}
533 send_gdb "clear 81\n"
535 -re "No breakpoint at 81..*$gdb_prompt $"\
536 {pass "clear line has no breakpoint disallowed"}
538 {fail "clear line has no breakpoint disallowed"}
539 timeout {fail "(timeout) clear line has no breakpoint disallowed"}
543 -re "No breakpoint at this line..*$gdb_prompt $"\
544 {pass "clear current line has no breakpoint disallowed"}
546 {fail "clear current line has no breakpoint disallowed"}
547 timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
550 # Verify that we can set and clear multiple breakpoints.
552 # We don't test that it deletes the correct breakpoints. We do at
553 # least test that it deletes more than one breakpoint.
555 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
556 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
557 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
559 # Verify that a breakpoint can be set via a convenience variable.
561 send_gdb "set \$foo=$bp_location11\n"
564 {pass "set convenience variable \$foo to bp_location11"}
565 timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
567 send_gdb "break \$foo\n"
569 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
570 {pass "set breakpoint via convenience variable"}
572 {fail "set breakpoint via convenience variable"}
573 timeout {fail "(timeout) set breakpoint via convenience variable"}
576 # Verify that GDB responds gracefully to an attempt to set a
577 # breakpoint via a convenience variable whose type is not integer.
579 send_gdb "set \$foo=81.5\n"
582 {pass "set convenience variable \$foo to 81.5"}
583 timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
585 send_gdb "break \$foo\n"
587 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
588 {pass "set breakpoint via non-integer convenience variable disallowed"}
590 {fail "set breakpoint via non-integer convenience variable disallowed"}
591 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
594 # Verify that we can set and trigger a breakpoint in a user-called function.
596 send_gdb "break marker2\n"
598 -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
599 {pass "set breakpoint on to-be-called function"}
601 {fail "set breakpoint on to-be-called function"}
602 timeout {fail "(timeout) set breakpoint on to-be-called function"}
604 send_gdb "print marker2(99)\n"
606 -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 $"\
607 {pass "hit breakpoint on called function"}
609 {fail "hit breakpoint on called function"}
610 timeout {fail "(timeout) hit breakpoint on called function"}
613 # As long as we're stopped (breakpointed) in a called function,
614 # verify that we can successfully backtrace & such from here.
616 # In this and the following test, the _sr4export check apparently is needed
621 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
622 {pass "backtrace while in called function"}
623 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
624 {pass "backtrace while in called function"}
626 {fail "backtrace while in called function"}
627 timeout {fail "(timeout) backtrace while in called function"}
630 # Return from the called function. For remote targets, it's important to do
631 # this before runto_main, which otherwise may silently stop on the dummy
632 # breakpoint inserted by GDB at the program's entry point.
636 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
637 {pass "finish from called function"}
638 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
639 {pass "finish from called function"}
640 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
641 {pass "finish from called function"}
643 {fail "finish from called function"}
644 timeout {fail "(timeout) finish from called function"}
647 # Verify that GDB responds gracefully to a "finish" command with
650 if ![runto_main] then { fail "break tests suppressed" }
652 send_gdb "finish 123\n"
654 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
655 {pass "finish with arguments disallowed"}
657 {fail "finish with arguments disallowed"}
658 timeout {fail "(timeout) finish with arguments disallowed"}
661 # Verify that GDB responds gracefully to a request to "finish" from
662 # the outermost frame. On a stub that never exits, this will just
663 # run to the stubs routine, so we don't get this error... Thus the
669 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
670 {pass "finish from outermost frame disallowed"}
671 -re "Run till exit from.*\r\n$gdb_prompt $" {
672 pass "finish from outermost frame disallowed"
675 {fail "finish from outermost frame disallowed"}
676 timeout {fail "(timeout) finish from outermost frame disallowed"}
679 # Verify that we can explicitly ask GDB to stop on all shared library
680 # events, and that it does so.
682 if [istarget "hppa*-*-hpux*"] then {
683 if ![runto_main] then { fail "break tests suppressed" }
685 send_gdb "set stop-on-solib-events 1\n"
688 {pass "set stop-on-solib-events"}
689 timeout {fail "(timeout) set stop-on-solib-events"}
694 -re ".*Start it from the beginning.*y or n. $"\
697 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
698 {pass "triggered stop-on-solib-events"}
700 {fail "triggered stop-on-solib-events"}
701 timeout {fail "(timeout) triggered stop-on-solib-events"}
705 {fail "rerun for stop-on-solib-events"}
706 timeout {fail "(timeout) rerun for stop-on-solib-events"}
709 send_gdb "set stop-on-solib-events 0\n"
712 {pass "reset stop-on-solib-events"}
713 timeout {fail "(timeout) reset stop-on-solib-events"}
717 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
718 # gracefully responds to requests to create them.
720 if [istarget "hppa*-*-hpux*"] then {
721 if ![runto_main] then { fail "break tests suppressed" }
725 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
726 {pass "hw breaks disallowed"}
728 {fail "hw breaks disallowed"}
729 timeout {fail "(timeout) hw breaks disallowed"}
734 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
735 {pass "temporary hw breaks disallowed"}
737 {fail "temporary hw breaks disallowed"}
738 timeout {fail "(timeout) temporary hw breaks disallowed"}
746 # Test "next" over recursive function call.
749 proc test_next_with_recursion {} {
754 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
757 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
759 # Run until we call factorial with 6
763 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
764 -re ".*$gdb_prompt $" {
765 fail "run to factorial(6)";
768 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
771 # Continue until we call factorial recursively with 5.
773 if [gdb_test "continue" \
774 "Continuing.*Break.* factorial .value=5. .*" \
775 "continue to factorial(5)"] then { gdb_suppress_tests }
777 # Do a backtrace just to confirm how many levels deep we are.
779 if [gdb_test "backtrace" \
780 "#0\[ \t\]+ factorial .value=5..*" \
781 "backtrace from factorial(5)"] then { gdb_suppress_tests }
783 # Now a "next" should position us at the recursive call, which
784 # we will be performing with 4.
786 if [gdb_test "next" \
787 ".* factorial .value - 1.;.*" \
788 "next to recursive call"] then { gdb_suppress_tests }
790 # Disable the breakpoint at the entry to factorial by deleting them all.
791 # The "next" should run until we return to the next line from this
792 # recursive call to factorial with 4.
793 # Buggy versions of gdb will stop instead at the innermost frame on
794 # the line where we are trying to "next" to.
798 if [istarget "mips*tx39-*"] {
801 # We used to set timeout here for all other targets as well. This
802 # is almost certainly wrong. The proper timeout depends on the
803 # target system in use, and how we communicate with it, so there
804 # is no single value appropriate for all targets. The timeout
805 # should be established by the Dejagnu config file(s) for the
806 # board, and respected by the test suite.
808 # For example, if I'm running GDB over an SSH tunnel talking to a
809 # portmaster in California talking to an ancient 68k board running
810 # a crummy ROM monitor (a situation I can only wish were
811 # hypothetical), then I need a large timeout. But that's not the
812 # kind of knowledge that belongs in this file.
814 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
815 "next over recursive call"
817 # OK, we should be back in the same stack frame we started from.
818 # Do a backtrace just to confirm.
820 set result [gdb_test "backtrace" \
821 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
822 "backtrace from factorial(5.1)"]
823 if { $result != 0 } { gdb_suppress_tests }
825 if [target_info exists gdb,noresults] { gdb_suppress_tests }
826 gdb_continue_to_end "recursive next test"
827 gdb_stop_suppressing_tests;
830 test_next_with_recursion
835 proc test_different_dir {type test_different_dir xfail} {
836 global srcdir subdir objdir binfile srcfile timeout gdb_prompt
838 global bp_location6 decimal hex
840 set old_pf_prefix $pf_prefix
841 append pf_prefix " $type:"
845 gdb_reinitialize_dir $srcdir/$subdir
846 gdb_test "set debug-file-directory ${test_different_dir}" ".*" "set separate debug location"
849 if [target_info exists gdb_stub] {
854 # test break at function
859 gdb_test "break main" \
860 "Breakpoint.*at.* file .*$srcfile, line.*" \
861 "breakpoint function, optimized file"
864 # test break at function
869 gdb_test "break marker4" \
870 "Breakpoint.*at.* file .*$srcfile, line.*" \
871 "breakpoint small function, optimized file"
874 # run until the breakpoint at main is hit. For non-stubs-using targets.
881 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
882 pass "run until function breakpoint, optimized file"
884 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $" {
885 pass "run until function breakpoint, optimized file (code motion)"
887 -re "$gdb_prompt $" {
888 fail "run until function breakpoint, optimized file"
891 fail "run until function breakpoint, optimized file (timeout)"
896 # run until the breakpoint at a small function
900 # Add a second pass pattern. The behavior differs here between stabs
901 # and dwarf for one-line functions. Stabs preserves two line symbols
902 # (one before the prologue and one after) with the same line number,
903 # but dwarf regards these as duplicates and discards one of them.
904 # Therefore the address after the prologue (where the breakpoint is)
905 # has no exactly matching line symbol, and GDB reports the breakpoint
906 # as if it were in the middle of a line rather than at the beginning.
908 set bp_location13 [gdb_get_line_number "set breakpoint 13 here"]
909 set bp_location14 [gdb_get_line_number "set breakpoint 14 here"]
910 send_gdb "continue\n"
915 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
916 pass "run until breakpoint set at small function, optimized file"
918 -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
919 pass "run until breakpoint set at small function, optimized file"
921 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
922 # marker4() is defined at line 46 when compiled with -DPROTOTYPES
923 pass "run until breakpoint set at small function, optimized file (line bp_location14)"
925 -re ".*$gdb_prompt " {
926 fail "run until breakpoint set at small function, optimized file"
929 fail "run until breakpoint set at small function, optimized file (timeout)"
934 # Reset the default arguments for VxWorks
935 if [istarget "*-*-vxworks*"] {
937 verbose "Timeout is now $timeout seconds" 2
938 send_gdb "set args main\n"
939 gdb_expect -re ".*$gdb_prompt $" {}
942 set pf_prefix $old_pf_prefix
943 # proc test_different_dir
947 # now move the .debug file to a different location so that we can test
948 # the "set debug-file-directory" command.
950 remote_exec build "mv ${objdir}/${subdir}/.debug/${testfile}.debug ${objdir}/${subdir}"
951 set debugfile "${objdir}/${subdir}/${testfile}.debug"
953 test_different_dir debuglink "${objdir}/${subdir}" 0
956 # Test CRC mismatch is reported.
958 if {[build_executable sepdebug.exp sepdebug2 sepdebug2.c debug] != -1
959 && ![gdb_gnu_strip_debug ${objdir}/${subdir}/sepdebug2]} {
961 remote_exec build "cp ${debugfile} ${objdir}/${subdir}/.debug/sepdebug2.debug"
965 gdb_reinitialize_dir $srcdir/$subdir
967 set escapedobjdirsubdir [string_to_regexp ${objdir}/${subdir}]
969 gdb_test "file ${objdir}/${subdir}/sepdebug2" "warning: the debug information found in \"${escapedobjdirsubdir}/\\.debug/sepdebug2\\.debug\" does not match \"${escapedobjdirsubdir}/sepdebug2\" \\(CRC mismatch\\)\\..*\\(no debugging symbols found\\).*" "CRC mismatch is reported"
973 # NT_GNU_BUILD_ID / .note.gnu.build-id test:
975 set build_id_debug_filename [build_id_debug_filename_get $binfile]
976 if ![string compare $build_id_debug_filename ""] then {
977 unsupported "build-id is not supported by the compiler"
979 # Spare debug files may confuse testsuite runs in the future.
980 remote_exec build "rm -f $debugfile"
982 set build_id_debugself_filename [build_id_debug_filename_get $debugfile]
983 set test "build-id support by binutils"
985 if ![string compare $build_id_debugself_filename ""] then {
988 } elseif {[string compare $build_id_debugself_filename $build_id_debug_filename] != 0} then {
994 file mkdir [file dirname ${objdir}/${subdir}/${build_id_debug_filename}]
995 remote_exec build "mv $debugfile ${objdir}/${subdir}/${build_id_debug_filename}"
997 test_different_dir build-id "${objdir}/${subdir}" $xfail
999 # Test also multiple directories can be specified. Without the build-id
1000 # reference GDB would find the separate debug info just at the same
1001 # location as the executable file.
1003 test_different_dir multiple-dirs "/doesnotexist:${objdir}/${subdir}" $xfail
1005 # Spare debug files may confuse testsuite runs in the future.
1006 remote_exec build "rm -f ${objdir}/${subdir}/${build_id_debug_filename}"