1 # Copyright
1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
2 #
2000, 2002, 2003, 2004
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
2 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
, write to the Free Software
17 # Foundation
, Inc.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
19 # Please email
any bugs
, comments
, and
/or additions to this file to
:
20 # bug
-gdb@prep.ai.mit.edu
22 # Based
on break.exp
, written by Rob Savoye.
(rob@cygnus.com
)
23 # Modified to test gdb
's handling of separate debug info files.
25 # This file has two parts. The first is testing that gdb behaves
26 # normally after reading in an executable and its corresponding
27 # separate debug file. The second moves the .debug file to a different
28 # location and tests the "set debug-file-directory" command.
36 # test running programs
41 set testfile "sepdebug"
42 set srcfile ${testfile}.c
43 set binfile ${objdir}/${subdir}/${testfile}
45 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
46 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
49 # FIXME: this is nasty. We need to check for the stabs debug format.
50 # To do this we must run gdb on the unstripped executable, list 'main
'
51 # (as to have a default source file), use get_debug_format (which does
52 # 'info source
') and then see if the debug info is stabs. If so, we
53 # bail out. We cannot do this any other way because get_debug_format
54 # finds out the debug format using gdb itself, and in case of stabs we
55 # get an error loading the program if it is already stripped. An
56 # alternative would be to find out the debug info from the flags
57 # passed to dejagnu when the test is run.
61 gdb_reinitialize_dir $srcdir/$subdir
63 gdb_test "list main" "" ""
65 if { [test_debug_format "stabs"] } then {
66 # the separate debug info feature doesn't work well in binutils with stabs.
67 # It produces a corrupted debug
info only file
, and gdb chokes
on it.
68 # It is almost impossible to capture the failing message out of gdb
,
69 # because it happens inside gdb_load. At that point
any error message
70 # is intercepted by dejagnu itself
, and
, because of the error threshold
,
71 #
any faulty test result is changed into an UNRESOLVED.
72 #
(see dejagnu
/lib
/framework.exp
)
73 unsupported
"no separate debug info handling with stabs"
75 } elseif
{ [test_debug_format
"unknown"] } then {
76 # gdb doesn
't know what the debug format is. We are out of luck here.
77 unsupported "unknown debugging format"
82 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
83 # ${binfile}, which is just like the executable ($binfile) but without
84 # the debuginfo. Instead $binfile has a .gnudebuglink section which contains
85 # the name of a debuginfo only file. This file will be stored in the
86 # gdb.base/.debug subdirectory.
88 if [gdb_gnu_strip_debug $binfile] {
89 # check that you have a recent version of strip and objcopy installed
90 unsupported "cannot produce separate debug info files"
96 gdb_reinitialize_dir $srcdir/$subdir
99 if [target_info exists gdb_stub] {
103 # test simple breakpoint setting commands
106 # Test deleting all breakpoints when there are none installed,
107 # GDB should not prompt for confirmation.
108 # Note that gdb-init.exp provides a "delete_breakpoints" proc
109 # for general use elsewhere.
111 send_gdb "delete breakpoints\n"
113 -re "Delete all breakpoints.*$" {
116 -re "$gdb_prompt $" {
117 fail "Delete all breakpoints when none (unexpected prompt)"
119 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
122 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
123 timeout { fail "Delete all breakpoints when none (timeout)" }
127 # test break at function
129 gdb_test "break main" \
130 "Breakpoint.*at.* file .*$srcfile, line.*" \
131 "breakpoint function"
134 # test break at quoted function
136 gdb_test "break \"marker2\"" \
137 "Breakpoint.*at.* file .*$srcfile, line.*" \
138 "breakpoint quoted function"
141 # test break at function in file
143 gdb_test "break $srcfile:factorial" \
144 "Breakpoint.*at.* file .*$srcfile, line.*" \
145 "breakpoint function in file"
147 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
150 # test break at line number
152 # Note that the default source file is the last one whose source text
153 # was printed. For native debugging, before we've executed the
154 #
program, this is the file containing main
, but
for remote debugging
,
155 # it
's wherever the processor was stopped when we connected to the
156 # board. So, to be sure, we do a list command.
158 gdb_test "list main" \
159 ".*main \\(argc, argv, envp\\).*" \
160 "use `list' to establish default source file
"
161 gdb_test
"break $bp_location1" \
162 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
163 "breakpoint line number"
166 # test duplicate breakpoint
168 gdb_test
"break $bp_location1" \
169 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
170 "breakpoint duplicate"
172 set bp_location2
[gdb_get_line_number
"set breakpoint 2 here"]
175 # test
break at line number in file
177 gdb_test
"break $srcfile:$bp_location2" \
178 "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
179 "breakpoint line number in file"
181 set bp_location3
[gdb_get_line_number
"set breakpoint 3 here"]
182 set bp_location4
[gdb_get_line_number
"set breakpoint 4 here"]
185 # Test putting a
break at the start of a multi
-line
if conditional.
186 # Verify the breakpoint was put at the start of the conditional.
188 gdb_test
"break multi_line_if_conditional" \
189 "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
190 "breakpoint at start of multi line if conditional"
192 gdb_test
"break multi_line_while_conditional" \
193 "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
194 "breakpoint at start of multi line while conditional"
196 set bp_location5
[gdb_get_line_number
"set breakpoint 5 here"]
197 set bp_location6
[gdb_get_line_number
"set breakpoint 6 here"]
200 # check to see what breakpoints are
set
202 if [target_info
exists gdb_stub
] {
203 set main_line $bp_location5
205 set main_line $bp_location6
208 set bp_location7
[gdb_get_line_number
"set breakpoint 7 here"]
209 set bp_location8
[gdb_get_line_number
"set breakpoint 8 here"]
210 set bp_location9
[gdb_get_line_number
"set breakpoint 9 here"]
212 gdb_test
"info break" \
213 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
214 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in main at .
*$srcfile
:$main_line.
*
215 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in marker2 at .
*$srcfile
:($bp_location8|$bp_location9
).
*
216 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in factorial at .
*$srcfile
:$bp_location7.
*
217 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in main at .
*$srcfile
:$bp_location1.
*
218 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in main at .
*$srcfile
:$bp_location1.
*
219 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in main at .
*$srcfile
:$bp_location2.
*
220 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in multi_line_if_conditional at .
*$srcfile
:$bp_location3.
*
221 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in multi_line_while_conditional at .
*$srcfile
:$bp_location4
" \
224 # FIXME
: The rest of this test doesn
't work with anything that can't
226 # Huh? There doesn
't *appear* to be anything that passes arguments
228 if [istarget "mips-idt-*"] then {
233 # run until the breakpoint at main is hit. For non-stubs-using targets.
235 if ![target_info exists use_gdb_stub] {
236 if [istarget "*-*-vxworks*"] then {
237 send_gdb "run vxmain \"2\"\n"
239 verbose "Timeout is now $timeout seconds" 2
244 -re "The program .* has been started already.*y or n. $" {
248 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
249 { pass "run until function breakpoint" }
250 -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
251 timeout { fail "run until function breakpoint (timeout)" }
254 if ![target_info exists gdb_stub] {
255 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue"
260 # run until the breakpoint at a line number
262 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
263 "run until breakpoint set at a line number"
266 # Run until the breakpoint set in a function in a file
268 for {set i 6} {$i >= 1} {incr i -1} {
269 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
270 "run until file:function($i) breakpoint"
274 # Run until the breakpoint set at a quoted function
276 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile:($bp_location8|$bp_location9).*" \
277 "run until quoted breakpoint"
279 # run until the file:function breakpoint at a line number in a file
281 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
282 "run until file:linenum breakpoint"
284 # Test break at offset +1
285 set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
287 gdb_test "break +1" \
288 "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
289 "breakpoint offset +1"
291 # Check to see if breakpoint is hit when stepped onto
294 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
295 "step onto breakpoint"
298 # delete all breakpoints so we can start over, course this can be a test too
303 # test temporary breakpoint at function
306 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
309 # test break at function in file
312 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
313 "Temporary breakpoint function in file"
316 # test break at line number
318 send_gdb "tbreak $bp_location1\n"
320 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
321 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
322 timeout { fail "breakpoint line number #1 (timeout)" }
325 gdb_test "tbreak $bp_location6" "Breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
328 # test break at line number in file
330 send_gdb "tbreak $srcfile:$bp_location2\n"
332 -re "Breakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
333 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
334 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
337 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
338 gdb_test "tbreak $srcfile:$bp_location11" "Breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
341 # check to see what breakpoints are set (temporary this time)
343 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
344 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
345 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:$bp_location7.*\[\r\n\]
346 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
347 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
348 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
349 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
350 "Temporary breakpoint info"
355 # Verify that catchpoints for fork, vfork and exec don't trigger
356 # inappropriately.
(There are no calls to those
system functions
357 # in this test
program.
)
359 if ![runto_main
] then { fail
"break tests suppressed" }
363 -re
"Catch requires an event name.*$gdb_prompt $"\
364 {pass
"catch requires an event name"}
366 {fail
"catch requires an event name"}
367 timeout
{fail
"(timeout) catch requires an event name"}
371 set name "set catch fork, never expected to trigger"
372 send_gdb
"catch fork\n"
374 -re
"Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
376 -re
"Catch of fork not yet implemented.*$gdb_prompt $"
380 timeout
{fail
"(timeout) $name"}
384 set name "set catch vfork, never expected to trigger"
385 send_gdb
"catch vfork\n"
387 #
If we are
on HP
-UX
10.20, we expect an error message to be
388 # printed
if we type
"catch vfork" at the gdb gdb_prompt. This is
389 # because
on HP
-UX
10.20, we cannot catch vfork events.
391 if [istarget
"hppa*-hp-hpux10.20"] then {
393 -re
"Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
397 timeout
{fail
"(timeout) $name"}
401 -re
"Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
403 -re
"Catch of vfork not yet implemented.*$gdb_prompt $"
407 timeout
{fail
"(timeout) $name"}
411 set name "set catch exec, never expected to trigger"
412 send_gdb
"catch exec\n"
414 -re
"Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
416 -re
"Catch of exec not yet implemented.*$gdb_prompt $"
418 -re
"$gdb_prompt $" {fail $name}
419 timeout
{fail
"(timeout) $name"}
422 # Verify that GDB responds gracefully when asked to
set a breakpoint
423 #
on a nonexistent source line.
425 send_gdb
"break 999\n"
427 -re
"No line 999 in file .*$gdb_prompt $"\
428 {pass
"break on non-existent source line"}
430 {fail
"break on non-existent source line"}
431 timeout
{fail
"(timeout) break on non-existent source line"}
434 # Run to the desired default location.
If not positioned here
, the
435 # tests below don
't work.
437 gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
440 # Verify that GDB allows one to just say "break", which is treated
441 # as the "default" breakpoint. Note that GDB gets cute when printing
442 # the informational message about other breakpoints at the same
443 # location. We'll hit that bird with this stone too.
447 -re
"Breakpoint \[0-9\]*.*$gdb_prompt $"\
448 {pass
"break on default location, 1st time"}
450 {fail
"break on default location, 1st time"}
451 timeout
{fail
"(timeout) break on default location, 1st time"}
456 -re
"Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
457 {pass
"break on default location, 2nd time"}
459 {fail
"break on default location, 2nd time"}
460 timeout
{fail
"(timeout) break on default location, 2nd time"}
465 -re
"Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
466 {pass
"break on default location, 3rd time"}
468 {fail
"break on default location, 3rd time"}
469 timeout
{fail
"(timeout) break on default location, 3rd time"}
474 -re
"Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
475 {pass
"break on default location, 4th time"}
477 {fail
"break on default location, 4th time"}
478 timeout
{fail
"(timeout) break on default location, 4th time"}
481 # Verify that a
"silent" breakpoint can be set, and that GDB is indeed
482 #
"silent" about its triggering.
484 if ![runto_main
] then { fail
"break tests suppressed" }
486 send_gdb
"break $bp_location1\n"
488 -re
"Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
489 {pass
"set to-be-silent break bp_location1"}
491 {fail
"set to-be-silent break bp_location1"}
492 timeout
{fail
"(timeout) set to-be-silent break bp_location1"}
495 send_gdb
"commands $expect_out(1,string)\n"
499 -re
".*$gdb_prompt $"\
500 {pass
"set silent break bp_location1"}
501 timeout
{fail
"(timeout) set silent break bp_location1"}
504 send_gdb
"info break $expect_out(1,string)\n"
506 -re
"\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
507 {pass
"info silent break bp_location1"}
509 {fail
"info silent break bp_location1"}
510 timeout
{fail
"(timeout) info silent break bp_location1"}
512 send_gdb
"continue\n"
514 -re
"Continuing.\r\n$gdb_prompt $"\
515 {pass
"hit silent break bp_location1"}
517 {fail
"hit silent break bp_location1"}
518 timeout
{fail
"(timeout) hit silent break bp_location1"}
522 -re
"#0 main .* at .*:$bp_location1.*$gdb_prompt $"\
523 {pass
"stopped for silent break bp_location1"}
525 {fail
"stopped for silent break bp_location1"}
526 timeout
{fail
"(timeout) stopped for silent break bp_location1"}
529 # Verify that GDB can at least
parse a breakpoint with the
530 #
"thread" keyword. (We won't attempt to test here that a
531 # thread
-specific breakpoint really triggers appropriately.
532 # The gdb.threads subdirectory contains tests
for that.
)
534 set bp_location12
[gdb_get_line_number
"set breakpoint 12 here"]
535 send_gdb
"break $bp_location12 thread 999\n"
537 -re
"Unknown thread 999.*$gdb_prompt $"\
538 {pass
"thread-specific breakpoint on non-existent thread disallowed"}
540 {fail
"thread-specific breakpoint on non-existent thread disallowed"}
541 timeout
{fail
"(timeout) thread-specific breakpoint on non-existent thread disallowed"}
543 send_gdb
"break $bp_location12 thread foo\n"
545 -re
"Junk after thread keyword..*$gdb_prompt $"\
546 {pass
"thread-specific breakpoint on bogus thread ID disallowed"}
548 {fail
"thread-specific breakpoint on bogus thread ID disallowed"}
549 timeout
{fail
"(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
552 # Verify that GDB responds gracefully to a breakpoint command with
555 send_gdb
"break $bp_location12 foo\n"
557 -re
"Junk at end of arguments..*$gdb_prompt $"\
558 {pass
"breakpoint with trailing garbage disallowed"}
560 {fail
"breakpoint with trailing garbage disallowed"}
561 timeout
{fail
"(timeout) breakpoint with trailing garbage disallowed"}
564 # Verify that GDB responds gracefully to a
"clear" command that has
565 # no matching breakpoint.
(First
, get us
off the current source line
,
566 # which we know has a breakpoint.
)
570 -re
".*$gdb_prompt $"\
571 {pass
"step over breakpoint"}
572 timeout
{fail
"(timeout) step over breakpoint"}
574 send_gdb
"clear 81\n"
576 -re
"No breakpoint at 81..*$gdb_prompt $"\
577 {pass
"clear line has no breakpoint disallowed"}
579 {fail
"clear line has no breakpoint disallowed"}
580 timeout
{fail
"(timeout) clear line has no breakpoint disallowed"}
584 -re
"No breakpoint at this line..*$gdb_prompt $"\
585 {pass
"clear current line has no breakpoint disallowed"}
587 {fail
"clear current line has no breakpoint disallowed"}
588 timeout
{fail
"(timeout) clear current line has no breakpoint disallowed"}
591 # Verify that we can
set and clear multiple breakpoints.
593 # We don
't test that it deletes the correct breakpoints. We do at
594 # least test that it deletes more than one breakpoint.
596 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
597 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
598 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
600 # Verify that a breakpoint can be set via a convenience variable.
602 send_gdb "set \$foo=$bp_location11\n"
605 {pass "set convenience variable \$foo to bp_location11"}
606 timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
608 send_gdb "break \$foo\n"
610 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
611 {pass "set breakpoint via convenience variable"}
613 {fail "set breakpoint via convenience variable"}
614 timeout {fail "(timeout) set breakpoint via convenience variable"}
617 # Verify that GDB responds gracefully to an attempt to set a
618 # breakpoint via a convenience variable whose type is not integer.
620 send_gdb "set \$foo=81.5\n"
623 {pass "set convenience variable \$foo to 81.5"}
624 timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
626 send_gdb "break \$foo\n"
628 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
629 {pass "set breakpoint via non-integer convenience variable disallowed"}
631 {fail "set breakpoint via non-integer convenience variable disallowed"}
632 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
635 # Verify that we can set and trigger a breakpoint in a user-called function.
637 send_gdb "break marker2\n"
639 -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
640 {pass "set breakpoint on to-be-called function"}
642 {fail "set breakpoint on to-be-called function"}
643 timeout {fail "(timeout) set breakpoint on to-be-called function"}
645 send_gdb "print marker2(99)\n"
647 -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 $"\
648 {pass "hit breakpoint on called function"}
650 {fail "hit breakpoint on called function"}
651 timeout {fail "(timeout) hit breakpoint on called function"}
654 # As long as we're stopped
(breakpointed
) in a called function
,
655 # verify that we can successfully backtrace
& such from here.
657 # In this and the following test
, the _sr4export check apparently is needed
662 -re
"#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
663 {pass
"backtrace while in called function"}
664 -re
"#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
665 {pass
"backtrace while in called function"}
667 {fail
"backtrace while in called function"}
668 timeout
{fail
"(timeout) backtrace while in called function"}
671 #
Return from the called function.
For remote targets
, it
's important to do
672 # this before runto_main, which otherwise may silently stop on the dummy
673 # breakpoint inserted by GDB at the program's entry point.
677 -re
"Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
678 {pass
"finish from called function"}
679 -re
"Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
680 {pass
"finish from called function"}
681 -re
"Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
682 {pass
"finish from called function"}
684 {fail
"finish from called function"}
685 timeout
{fail
"(timeout) finish from called function"}
688 # Verify that GDB responds gracefully to a
"finish" command with
691 if ![runto_main
] then { fail
"break tests suppressed" }
693 send_gdb
"finish 123\n"
695 -re
"The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
696 {pass
"finish with arguments disallowed"}
698 {fail
"finish with arguments disallowed"}
699 timeout
{fail
"(timeout) finish with arguments disallowed"}
702 # Verify that GDB responds gracefully to a request to
"finish" from
703 # the outermost frame.
On a stub that never exits
, this will just
704 # run to the stubs routine
, so we don
't get this error... Thus the
710 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
711 {pass "finish from outermost frame disallowed"}
712 -re "Run till exit from.*\r\n$gdb_prompt $" {
713 pass "finish from outermost frame disallowed"
716 {fail "finish from outermost frame disallowed"}
717 timeout {fail "(timeout) finish from outermost frame disallowed"}
720 # Verify that we can explicitly ask GDB to stop on all shared library
721 # events, and that it does so.
723 if [istarget "hppa*-*-hpux*"] then {
724 if ![runto_main] then { fail "break tests suppressed" }
726 send_gdb "set stop-on-solib-events 1\n"
729 {pass "set stop-on-solib-events"}
730 timeout {fail "(timeout) set stop-on-solib-events"}
735 -re ".*Start it from the beginning.*y or n. $"\
738 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
739 {pass "triggered stop-on-solib-events"}
741 {fail "triggered stop-on-solib-events"}
742 timeout {fail "(timeout) triggered stop-on-solib-events"}
746 {fail "rerun for stop-on-solib-events"}
747 timeout {fail "(timeout) rerun for stop-on-solib-events"}
750 send_gdb "set stop-on-solib-events 0\n"
753 {pass "reset stop-on-solib-events"}
754 timeout {fail "(timeout) reset stop-on-solib-events"}
758 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
759 # gracefully responds to requests to create them.
761 if [istarget "hppa*-*-hpux*"] then {
762 if ![runto_main] then { fail "break tests suppressed" }
766 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
767 {pass "hw breaks disallowed"}
769 {fail "hw breaks disallowed"}
770 timeout {fail "(timeout) hw breaks disallowed"}
775 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
776 {pass "temporary hw breaks disallowed"}
778 {fail "temporary hw breaks disallowed"}
779 timeout {fail "(timeout) temporary hw breaks disallowed"}
787 # Test "next" over recursive function call.
790 proc test_next_with_recursion {} {
795 if [target_info exists use_gdb_stub] {
796 # Reload the program.
800 # FIXME: should be using runto
801 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
806 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
808 # Run until we call factorial with 6
810 if [istarget "*-*-vxworks*"] then {
811 send_gdb "run vxmain \"6\"\n"
816 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
817 -re ".*$gdb_prompt $" {
818 fail "run to factorial(6)";
821 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
824 # Continue until we call factorial recursively with 5.
826 if [gdb_test "continue" \
827 "Continuing.*Break.* factorial .value=5. .*" \
828 "continue to factorial(5)"] then { gdb_suppress_tests }
830 # Do a backtrace just to confirm how many levels deep we are.
832 if [gdb_test "backtrace" \
833 "#0\[ \t\]+ factorial .value=5..*" \
834 "backtrace from factorial(5)"] then { gdb_suppress_tests }
836 # Now a "next" should position us at the recursive call, which
837 # we will be performing with 4.
839 if [gdb_test "next" \
840 ".* factorial .value - 1.;.*" \
841 "next to recursive call"] then { gdb_suppress_tests }
843 # Disable the breakpoint at the entry to factorial by deleting them all.
844 # The "next" should run until we return to the next line from this
845 # recursive call to factorial with 4.
846 # Buggy versions of gdb will stop instead at the innermost frame on
847 # the line where we are trying to "next" to.
851 if [istarget "mips*tx39-*"] {
854 # We used to set timeout here for all other targets as well. This
855 # is almost certainly wrong. The proper timeout depends on the
856 # target system in use, and how we communicate with it, so there
857 # is no single value appropriate for all targets. The timeout
858 # should be established by the Dejagnu config file(s) for the
859 # board, and respected by the test suite.
861 # For example, if I'm running GDB over an SSH tunnel talking to a
862 # portmaster in California talking to an ancient
68k board running
863 # a crummy ROM
monitor (a situation I can only wish were
864 # hypothetical
), then I need a large timeout. But that
's not the
865 # kind of knowledge that belongs in this file.
867 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
868 "next over recursive call"
870 # OK, we should be back in the same stack frame we started from.
871 # Do a backtrace just to confirm.
873 set result [gdb_test "backtrace" \
874 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
875 "backtrace from factorial(5.1)"]
876 if { $result != 0 } { gdb_suppress_tests }
878 if [target_info exists gdb,noresults] { gdb_suppress_tests }
879 gdb_continue_to_end "recursive next test"
880 gdb_stop_suppressing_tests;
883 test_next_with_recursion
888 # now move the .debug file to a different location so that we can test
889 # the "set debug-file-directory" command.
891 remote_exec build "mv ${objdir}/${subdir}/.debug/${testfile}.debug ${objdir}/${subdir}"
894 gdb_reinitialize_dir $srcdir/$subdir
895 gdb_test "set debug-file-directory ${objdir}/${subdir}" ".*" "set separate debug location"
898 if [target_info exists gdb_stub] {
903 # test break at function
905 gdb_test "break main" \
906 "Breakpoint.*at.* file .*$srcfile, line.*" \
907 "breakpoint function, optimized file"
910 # test break at function
912 gdb_test "break marker4" \
913 "Breakpoint.*at.* file .*$srcfile, line.*" \
914 "breakpoint small function, optimized file"
917 # run until the breakpoint at main is hit. For non-stubs-using targets.
919 if ![target_info exists use_gdb_stub] {
920 if [istarget "*-*-vxworks*"] then {
921 send_gdb "run vxmain \"2\"\n"
923 verbose "Timeout is now $timeout seconds" 2
928 -re "The program .* has been started already.*y or n. $" {
932 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
933 { pass "run until function breakpoint, optimized file" }
934 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $"\
935 { pass "run until function breakpoint, optimized file (code motion)" }
936 -re ".*$gdb_prompt $" { fail "run until function breakpoint, optimized file" }
937 timeout { fail "run until function breakpoint, optimized file (timeout)" }
940 if ![target_info exists gdb_stub] {
941 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue, optimized file"
946 # run until the breakpoint at a small function
950 # Add a second pass pattern. The behavior differs here between stabs
951 # and dwarf for one-line functions. Stabs preserves two line symbols
952 # (one before the prologue and one after) with the same line number,
953 # but dwarf regards these as duplicates and discards one of them.
954 # Therefore the address after the prologue (where the breakpoint is)
955 # has no exactly matching line symbol, and GDB reports the breakpoint
956 # as if it were in the middle of a line rather than at the beginning.
958 set bp_location13 [gdb_get_line_number "set breakpoint 13 here"]
959 set bp_location14 [gdb_get_line_number "set breakpoint 14 here"]
960 send_gdb "continue\n"
962 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
963 pass "run until breakpoint set at small function, optimized file"
965 -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
966 pass "run until breakpoint set at small function, optimized file"
968 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
969 # marker4() is defined at line 46 when compiled with -DPROTOTYPES
970 pass "run until breakpoint set at small function, optimized file (line bp_location14)"
972 -re ".*$gdb_prompt " {
973 fail "run until breakpoint set at small function, optimized file"
976 fail "run until breakpoint set at small function, optimized file (timeout)"
981 # Reset the default arguments for VxWorks
982 if [istarget "*-*-vxworks*"] {
984 verbose "Timeout is now $timeout seconds" 2
985 send_gdb "set args main\n"
986 gdb_expect -re ".*$gdb_prompt $" {}