1#   Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
2#   2000, 2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
3#   Free Software Foundation, Inc.
4
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.
9#
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.
14#
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/>.
17
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.
21
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.
28
29
30if $tracelevel then {
31    strace $tracelevel
32}
33
34#
35# test running programs
36#
37
38set testfile "sepdebug"
39set srcfile ${testfile}.c
40set binfile ${objdir}/${subdir}/${testfile}${EXEEXT}
41
42if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
43    untested sepdebug.exp
44    return -1
45}
46
47# Note: the procedure gdb_gnu_strip_debug will produce an executable called
48# ${binfile}, which is just like the executable ($binfile) but without
49# the debuginfo. Instead $binfile has a .gnudebuglink section which contains
50# the name of a debuginfo only file. This file will be stored in the
51# gdb.base/ subdirectory.
52
53if [gdb_gnu_strip_debug $binfile] {
54    # check that you have a recent version of strip and objcopy installed
55    unsupported "cannot produce separate debug info files"
56    return -1
57}
58
59gdb_exit
60gdb_start
61gdb_reinitialize_dir $srcdir/$subdir
62gdb_load ${binfile}
63if { $gdb_file_cmd_debug_info != "debug" } then {
64    fail "No debug information found."
65}
66
67if [target_info exists gdb_stub] {
68    gdb_step_for_stub;
69}
70#
71# test simple breakpoint setting commands
72#
73
74#
75# test break at function
76#
77gdb_test "break main" \
78    "Breakpoint.*at.* file .*$srcfile, line.*" \
79    "breakpoint function"
80
81#
82# test break at quoted function
83#
84gdb_test "break \"marker2\"" \
85    "Breakpoint.*at.* file .*$srcfile, line.*" \
86    "breakpoint quoted function"
87
88#
89# test break at function in file
90#
91gdb_test "break $srcfile:factorial" \
92    "Breakpoint.*at.* file .*$srcfile, line.*" \
93    "breakpoint function in file"
94
95set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
96
97#
98# test break at line number
99#
100# Note that the default source file is the last one whose source text
101# was printed.  For native debugging, before we've executed the
102# program, this is the file containing main, but for remote debugging,
103# it's wherever the processor was stopped when we connected to the
104# board.  So, to be sure, we do a list command.
105#
106gdb_test "list main" \
107    ".*main \\(argc, argv, envp\\).*" \
108    "use `list' to establish default source file"
109gdb_test "break $bp_location1" \
110    "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
111    "breakpoint line number"
112
113#
114# test duplicate breakpoint
115#
116gdb_test "break $bp_location1" \
117    "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
118    "breakpoint duplicate"
119
120set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
121
122#
123# test break at line number in file
124#
125gdb_test "break $srcfile:$bp_location2" \
126    "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
127    "breakpoint line number in file"
128
129set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
130set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
131
132#
133# Test putting a break at the start of a multi-line if conditional.
134# Verify the breakpoint was put at the start of the conditional.
135#
136gdb_test "break multi_line_if_conditional" \
137    "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
138    "breakpoint at start of multi line if conditional"
139
140gdb_test "break multi_line_while_conditional" \
141    "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
142    "breakpoint at start of multi line while conditional"
143
144set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
145set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
146
147#
148# check to see what breakpoints are set
149#
150if [target_info exists gdb_stub] {
151    set main_line $bp_location5
152} else {
153    set main_line $bp_location6
154}
155
156set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
157set bp_location8 [gdb_get_line_number "set breakpoint 8 here"]
158set bp_location9 [gdb_get_line_number "set breakpoint 9 here"]
159
160gdb_test "info break" \
161    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
162\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$main_line.*
163\[0-9\]+\[\t \]+breakpoint     keep y.* in marker2 at .*$srcfile:($bp_location8|$bp_location9).*
164\[0-9\]+\[\t \]+breakpoint     keep y.* in factorial at .*$srcfile:$bp_location7.*
165\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$bp_location1.*
166\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$bp_location1.*
167\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$bp_location2.*
168\[0-9\]+\[\t \]+breakpoint     keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
169\[0-9\]+\[\t \]+breakpoint     keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
170    "breakpoint info"
171
172# FIXME: The rest of this test doesn't work with anything that can't
173# handle arguments.
174# Huh? There doesn't *appear* to be anything that passes arguments
175# below.
176if [istarget "mips-idt-*"] then {
177    return
178}
179
180#
181# run until the breakpoint at main is hit. For non-stubs-using targets.
182#
183gdb_run_cmd
184gdb_expect {
185    -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
186	pass "run until function breakpoint"
187    }
188    -re "$gdb_prompt $" {
189	fail "run until function breakpoint"
190    }
191    timeout {
192	fail "run until function breakpoint (timeout)"
193    }
194}
195
196#
197# run until the breakpoint at a line number
198#
199gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
200			"run until breakpoint set at a line number"
201
202#
203# Run until the breakpoint set in a function in a file
204#
205for {set i 6} {$i >= 1} {incr i -1} {
206	gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
207			"run until file:function($i) breakpoint"
208}
209
210#
211# Run until the breakpoint set at a quoted function
212#
213gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile:($bp_location8|$bp_location9).*" \
214		"run until quoted breakpoint"
215#
216# run until the file:function breakpoint at a line number in a file
217#
218gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
219		"run until file:linenum breakpoint"
220
221# Test break at offset +1
222set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
223
224gdb_test "break +1" \
225    "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
226    "breakpoint offset +1"
227
228# Check to see if breakpoint is hit when stepped onto
229
230gdb_test "step" \
231    ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
232    "step onto breakpoint"
233
234#
235# delete all breakpoints so we can start over, course this can be a test too
236#
237delete_breakpoints
238
239#
240# test temporary breakpoint at function
241#
242
243gdb_test "tbreak main" "Temporary breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
244
245#
246# test break at function in file
247#
248
249gdb_test "tbreak $srcfile:factorial" "Temporary breakpoint.*at.* file .*$srcfile, line.*" \
250	"Temporary breakpoint function in file"
251
252#
253# test break at line number
254#
255
256gdb_test "tbreak $bp_location1" \
257    "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location1.*" \
258    "Temporary breakpoint line number #1"
259
260gdb_test "tbreak $bp_location6" \
261    "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location6.*" \
262    "Temporary breakpoint line number #2"
263
264#
265# test break at line number in file
266#
267
268gdb_test "tbreak $srcfile:$bp_location2" \
269    "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location2.*" \
270    "Temporary breakpoint line number in file #1"
271
272set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
273gdb_test  "tbreak $srcfile:$bp_location11" "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
274
275#
276# check to see what breakpoints are set (temporary this time)
277#
278gdb_test "info break" "Num     Type.*Disp Enb Address.*What.*\[\r\n\]
279\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
280\[0-9\]+\[\t \]+breakpoint     del.*y.*in factorial at .*$srcfile:$bp_location7.*\[\r\n\]
281\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
282\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
283\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
284\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$bp_location11.*" \
285    "Temporary breakpoint info"
286
287
288#***********
289
290# Verify that catchpoints for fork, vfork and exec don't trigger
291# inappropriately.  (There are no calls to those system functions
292# in this test program.)
293#
294if ![runto_main] then { fail "sepdebug tests suppressed" }
295
296gdb_test "catch" "Catch requires an event name.*" \
297    "catch requires an event name"
298
299set name "set catch fork, never expected to trigger"
300gdb_test_multiple "catch fork" $name {
301    -re "Catchpoint \[0-9\]* .fork.*$gdb_prompt $" {
302	pass $name
303    }
304    -re "Catch of fork not yet implemented.*$gdb_prompt $" {
305	pass $name
306    }
307}
308
309# If we are on HP-UX 10.20, we expect an error message to be
310# printed if we type "catch vfork" at the gdb gdb_prompt.  This is
311# because on HP-UX 10.20, we cannot catch vfork events.
312
313set name "set catch vfork, never expected to trigger"
314gdb_test_multiple "catch vfork" $name {
315    -re "Catch of vfork events not supported on HP-UX 10.20.*" {
316	pass $name
317    }
318    -re "Catchpoint \[0-9\]* .vfork.*$gdb_prompt $" {
319	pass $name
320    }
321    -re "Catch of vfork not yet implemented.*$gdb_prompt $" {
322	pass $name
323    }
324}
325
326set name "set catch exec, never expected to trigger"
327gdb_test_multiple "catch exec" $name {
328    -re "Catchpoint \[0-9\]* .exec.*$gdb_prompt $" {
329	pass $name
330    }
331    -re "Catch of exec not yet implemented.*$gdb_prompt $" {
332	pass $name
333    }
334}
335
336# Verify that GDB responds gracefully when asked to set a breakpoint
337# on a nonexistent source line.
338#
339
340gdb_test "break 999" "No line 999 in file .*" \
341    "break on non-existent source line"
342
343# Run to the desired default location. If not positioned here, the
344# tests below don't work.
345#
346gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
347
348
349# Verify that GDB allows one to just say "break", which is treated
350# as the "default" breakpoint.  Note that GDB gets cute when printing
351# the informational message about other breakpoints at the same
352# location.  We'll hit that bird with this stone too.
353#
354
355gdb_test "break" "Breakpoint \[0-9\]*.*" \
356    "break on default location, 1st time"
357
358gdb_test "break" \
359    "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
360    "break on default location, 2nd time"
361
362gdb_test "break" \
363    "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
364    "break on default location, 3rd time"
365
366gdb_test "break" \
367    "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
368    "break on default location, 4th time"
369
370# Verify that a "silent" breakpoint can be set, and that GDB is indeed
371# "silent" about its triggering.
372#
373if ![runto_main] then { fail "sepdebug tests suppressed" }
374
375gdb_test_multiple "break $bp_location1" \
376    "set to-be-silent break bp_location1" {
377	-re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $" {
378	    pass "set to-be-silent break bp_location1"
379	}
380}
381
382send_gdb "commands $expect_out(1,string)\n"
383send_gdb "silent\n"
384send_gdb "end\n"
385gdb_expect {
386  -re ".*$gdb_prompt $"\
387          {pass "set silent break bp_location1"}
388  timeout {fail "(timeout) set silent break bp_location1"}
389}
390
391gdb_test "info break $expect_out(1,string)" \
392    "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*" \
393    "info silent break bp_location1"
394
395gdb_test "continue" "Continuing.*" "hit silent break bp_location1"
396
397gdb_test "bt" "#0  main .* at .*:$bp_location1.*" \
398    "stopped for silent break bp_location1"
399
400# Verify that GDB can at least parse a breakpoint with the
401# "thread" keyword.  (We won't attempt to test here that a
402# thread-specific breakpoint really triggers appropriately.
403# The gdb.threads subdirectory contains tests for that.)
404#
405set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
406
407gdb_test "break $bp_location12 thread 999" "Unknown thread 999.*" \
408    "thread-specific breakpoint on non-existent thread disallowed"
409
410gdb_test "break $bp_location12 thread foo" \
411    "Junk after thread keyword.*" \
412    "thread-specific breakpoint on bogus thread ID disallowed"
413
414# Verify that GDB responds gracefully to a breakpoint command with
415# trailing garbage.
416#
417
418gdb_test "break $bp_location12 foo" \
419    "Junk at end of arguments.*" \
420    "breakpoint with trailing garbage disallowed"
421
422# Verify that GDB responds gracefully to a "clear" command that has
423# no matching breakpoint.  (First, get us off the current source line,
424# which we know has a breakpoint.)
425#
426
427gdb_test "next" "marker1.*" "step over breakpoint"
428
429gdb_test "clear 81" "No breakpoint at 81.*" \
430    "clear line has no breakpoint disallowed"
431
432gdb_test "clear" "No breakpoint at this line.*" \
433    "clear current line has no breakpoint disallowed"
434
435# Verify that we can set and clear multiple breakpoints.
436#
437# We don't test that it deletes the correct breakpoints.  We do at
438# least test that it deletes more than one breakpoint.
439#
440gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
441gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
442gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
443
444# Verify that a breakpoint can be set via a convenience variable.
445#
446
447gdb_test_no_output "set \$foo=$bp_location11" \
448    "set convenience variable \$foo to bp_location11"
449
450gdb_test "break \$foo" \
451    "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*" \
452    "set breakpoint via convenience variable"
453
454# Verify that GDB responds gracefully to an attempt to set a
455# breakpoint via a convenience variable whose type is not integer.
456#
457
458gdb_test_no_output "set \$foo=81.5" \
459    "set convenience variable \$foo to 81.5"
460
461gdb_test "break \$foo" \
462    "Convenience variables used in line specs must have integer values.*" \
463    "set breakpoint via non-integer convenience variable disallowed"
464
465# Verify that we can set and trigger a breakpoint in a user-called function.
466#
467
468gdb_test "break marker2" \
469    "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*" \
470    "set breakpoint on to-be-called function"
471
472gdb_test "print marker2(99)" \
473    "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.*" \
474    "hit breakpoint on called function"
475
476# As long as we're stopped (breakpointed) in a called function,
477# verify that we can successfully backtrace & such from here.
478#
479# In this and the following test, the _sr4export check apparently is needed
480# for hppa*-*-hpux.
481#
482
483gdb_test_multiple "bt" "backtrace while in called function" {
484    -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $" {
485	pass "backtrace while in called function"
486    }
487    -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $" {
488	pass "backtrace while in called function"
489    }
490}
491
492# Return from the called function.  For remote targets, it's important to do
493# this before runto_main, which otherwise may silently stop on the dummy
494# breakpoint inserted by GDB at the program's entry point.
495#
496
497gdb_test_multiple "finish" "finish from called function" {
498    -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $" {
499	pass "finish from called function"
500    }
501    -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $" {
502	pass "finish from called function"
503    }
504    -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $" {
505	pass "finish from called function"
506    }
507}
508
509# Verify that GDB responds gracefully to a "finish" command with
510# arguments.
511#
512if ![runto_main] then { fail "sepdebug tests suppressed" }
513
514gdb_test "finish 123" \
515    "The \"finish\" command does not take any arguments.*" \
516    "finish with arguments disallowed"
517
518# Verify that GDB responds gracefully to a request to "finish" from
519# the outermost frame.  On a stub that never exits, this will just
520# run to the stubs routine, so we don't get this error...  Thus the
521# second condition.
522#
523
524gdb_test_multiple "finish" "finish from outermost frame disallowed" {
525    -re "\"finish\" not meaningful in the outermost frame.*$gdb_prompt $" {
526	pass "finish from outermost frame disallowed"
527    }
528    -re "Run till exit from.*$gdb_prompt $" {
529	pass "finish from outermost frame disallowed"
530    }
531}
532
533# Verify that we can explicitly ask GDB to stop on all shared library
534# events, and that it does so.
535#
536if [istarget "hppa*-*-hpux*"] then {
537    if ![runto_main] then { fail "sepdebug tests suppressed" }
538
539    gdb_test_no_output "set stop-on-solib-events 1" \
540	"set stop-on-solib-events"
541
542    gdb_test "run" \
543	"Stopped due to shared library event.*" \
544	"triggered stop-on-solib-events" \
545	"Start it from the beginning.*y or n. $" \
546	"y"
547
548    gdb_test_no_output "set stop-on-solib-events 0" \
549      "reset stop-on-solib-events"
550}
551
552# Hardware breakpoints are unsupported on HP-UX.  Verify that GDB
553# gracefully responds to requests to create them.
554#
555if [istarget "hppa*-*-hpux*"] then {
556    if ![runto_main] then { fail "sepdebug tests suppressed" }
557
558    gdb_test "hbreak" \
559	"No hardware breakpoint support in the target.*" \
560	"hw breaks disallowed"
561
562    gdb_test "thbreak" \
563      "No hardware breakpoint support in the target.*" \
564      "temporary hw breaks disallowed"
565}
566
567#********
568
569
570#
571# Test "next" over recursive function call.
572#
573
574proc test_next_with_recursion {} {
575    global gdb_prompt
576    global decimal
577    global binfile
578
579    gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
580    delete_breakpoints
581
582    gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
583
584    # Run until we call factorial with 6
585
586    gdb_run_cmd
587    gdb_expect {
588	-re "Break.* factorial .value=6. .*$gdb_prompt $" {}
589	-re ".*$gdb_prompt $" {
590	    fail "run to factorial(6)";
591	    gdb_suppress_tests;
592	}
593	timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
594    }
595
596    # Continue until we call factorial recursively with 5.
597
598    if [gdb_test "continue" \
599	"Continuing.*Break.* factorial .value=5. .*" \
600	"continue to factorial(5)"] then { gdb_suppress_tests }
601
602    # Do a backtrace just to confirm how many levels deep we are.
603
604    if [gdb_test "backtrace" \
605	"#0\[ \t\]+ factorial .value=5..*" \
606	"backtrace from factorial(5)"] then { gdb_suppress_tests }
607
608    # Now a "next" should position us at the recursive call, which
609    # we will be performing with 4.
610
611    if [gdb_test "next" \
612	".* factorial .value - 1.;.*" \
613	"next to recursive call"] then { gdb_suppress_tests }
614
615    # Disable the breakpoint at the entry to factorial by deleting them all.
616    # The "next" should run until we return to the next line from this
617    # recursive call to factorial with 4.
618    # Buggy versions of gdb will stop instead at the innermost frame on
619    # the line where we are trying to "next" to.
620
621    delete_breakpoints
622
623    if [istarget "mips*tx39-*"] {
624	set timeout 60
625    }
626    # We used to set timeout here for all other targets as well.  This
627    # is almost certainly wrong.  The proper timeout depends on the
628    # target system in use, and how we communicate with it, so there
629    # is no single value appropriate for all targets.  The timeout
630    # should be established by the Dejagnu config file(s) for the
631    # board, and respected by the test suite.
632    #
633    # For example, if I'm running GDB over an SSH tunnel talking to a
634    # portmaster in California talking to an ancient 68k board running
635    # a crummy ROM monitor (a situation I can only wish were
636    # hypothetical), then I need a large timeout.  But that's not the
637    # kind of knowledge that belongs in this file.
638
639    gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
640	    "next over recursive call"
641
642    # OK, we should be back in the same stack frame we started from.
643    # Do a backtrace just to confirm.
644
645    set result [gdb_test "backtrace" \
646	    "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
647	    "backtrace from factorial(5.1)"]
648    if { $result != 0 } { gdb_suppress_tests }
649
650    if [target_info exists gdb,noresults] { gdb_suppress_tests }
651  gdb_continue_to_end "recursive next test"
652   gdb_stop_suppressing_tests;
653}
654
655test_next_with_recursion
656
657
658#********
659
660proc test_different_dir {type test_different_dir xfail} {
661    global srcdir subdir objdir binfile srcfile timeout gdb_prompt
662    global pf_prefix
663    global bp_location6 decimal hex
664
665    set old_pf_prefix $pf_prefix
666    append pf_prefix " $type:"
667
668    gdb_exit
669    gdb_start
670    gdb_reinitialize_dir $srcdir/$subdir
671    gdb_test_no_output "set debug-file-directory ${test_different_dir}" \
672	"set separate debug location"
673    gdb_load ${binfile}
674
675    if [target_info exists gdb_stub] {
676	gdb_step_for_stub;
677    }
678
679    #
680    # test break at function
681    #
682    if {$xfail} {
683	setup_xfail "*-*-*"
684    }
685    gdb_test "break main" \
686	"Breakpoint.*at.* file .*$srcfile, line.*" \
687	"breakpoint function, optimized file"
688
689    #
690    # test break at function
691    #
692    if {$xfail} {
693	setup_xfail "*-*-*"
694    }
695    gdb_test "break marker4" \
696	"Breakpoint.*at.* file .*$srcfile, line.*" \
697	"breakpoint small function, optimized file"
698
699    #
700    # run until the breakpoint at main is hit. For non-stubs-using targets.
701    #
702    gdb_run_cmd
703    if {$xfail} {
704	setup_xfail "*-*-*"
705    }
706    gdb_expect {
707	-re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
708	    pass "run until function breakpoint, optimized file"
709	}
710	-re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $" {
711	    pass "run until function breakpoint, optimized file (code motion)"
712	}
713	-re "$gdb_prompt $" {
714	    fail "run until function breakpoint, optimized file"
715	}
716	timeout {
717	    fail "run until function breakpoint, optimized file (timeout)"
718	}
719    }
720
721    #
722    # run until the breakpoint at a small function
723    #
724
725    #
726    # Add a second pass pattern.  The behavior differs here between stabs
727    # and dwarf for one-line functions.  Stabs preserves two line symbols
728    # (one before the prologue and one after) with the same line number,
729    # but dwarf regards these as duplicates and discards one of them.
730    # Therefore the address after the prologue (where the breakpoint is)
731    # has no exactly matching line symbol, and GDB reports the breakpoint
732    # as if it were in the middle of a line rather than at the beginning.
733
734    set bp_location13 [gdb_get_line_number "set breakpoint 13 here"]
735    set bp_location14 [gdb_get_line_number "set breakpoint 14 here"]
736    if {$xfail} {
737	setup_xfail "*-*-*"
738    }
739
740    gdb_test_multiple "continue" "run until breakpoint set at small function, optimized file" {
741	-re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*$gdb_prompt $" {
742	    pass "run until breakpoint set at small function, optimized file"
743	}
744	-re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*$gdb_prompt $" {
745	    pass "run until breakpoint set at small function, optimized file"
746	}
747	-re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*$gdb_prompt $" {
748	    # marker4() is defined at line 46 when compiled with -DPROTOTYPES
749	    pass "run until breakpoint set at small function, optimized file (line bp_location14)"
750	}
751    }
752
753
754    # Reset the default arguments for VxWorks
755    if [istarget "*-*-vxworks*"] {
756	set timeout 10
757	verbose "Timeout is now $timeout seconds" 2
758	gdb_test_no_output "set args main"
759    }
760
761    set pf_prefix $old_pf_prefix
762# proc test_different_dir
763}
764
765
766# now move the .debug file to a different location so that we can test
767# the "set debug-file-directory" command.
768
769set different_dir "${objdir}/${subdir}/${testfile}.dir"
770set debugfile "${different_dir}/${objdir}/${subdir}/${testfile}.debug"
771remote_exec build "rm -rf $different_dir"
772remote_exec build "mkdir -p [file dirname $debugfile]"
773remote_exec build "mv -f ${objdir}/${subdir}/${testfile}.debug $debugfile"
774
775test_different_dir debuglink $different_dir 0
776
777
778# Test CRC mismatch is reported.
779
780if {[build_executable sepdebug.exp sepdebug2 sepdebug2.c debug] != -1
781    && ![gdb_gnu_strip_debug ${objdir}/${subdir}/sepdebug2]} {
782
783    remote_exec build "cp ${debugfile} ${objdir}/${subdir}/sepdebug2.debug"
784
785    gdb_exit
786    gdb_start
787    gdb_reinitialize_dir $srcdir/$subdir
788
789    set escapedobjdirsubdir [string_to_regexp ${objdir}/${subdir}]
790
791    gdb_test "file ${objdir}/${subdir}/sepdebug2" "warning: the debug information found in \"${escapedobjdirsubdir}/sepdebug2\\.debug\" does not match \"${escapedobjdirsubdir}/sepdebug2\" \\(CRC mismatch\\)\\..*\\(no debugging symbols found\\).*" "CRC mismatch is reported"
792}
793
794
795# NT_GNU_BUILD_ID / .note.gnu.build-id test:
796
797set build_id_debug_filename [build_id_debug_filename_get $binfile]
798if ![string compare $build_id_debug_filename ""] then {
799    unsupported "build-id is not supported by the compiler"
800
801    # Spare debug files may confuse testsuite runs in the future.
802    remote_exec build "rm -f $debugfile"
803} else {
804    set build_id_debugself_filename [build_id_debug_filename_get $debugfile]
805    set test "build-id support by binutils"
806    set xfail 0
807    if ![string compare $build_id_debugself_filename ""] then {
808	unsupported $test
809	set xfail 1
810    } elseif {[string compare $build_id_debugself_filename $build_id_debug_filename] != 0} then {
811	fail $test
812    } else {
813	pass $test
814    }
815
816    file mkdir [file dirname ${objdir}/${subdir}/${build_id_debug_filename}]
817    remote_exec build "mv $debugfile ${objdir}/${subdir}/${build_id_debug_filename}"
818
819    test_different_dir build-id "${objdir}/${subdir}" $xfail
820
821    # Test also multiple directories can be specified.  Without the build-id
822    # reference GDB would find the separate debug info just at the same
823    # location as the executable file.
824
825    test_different_dir multiple-dirs "/doesnotexist:${objdir}/${subdir}" $xfail
826
827    # Spare debug files may confuse testsuite runs in the future.
828    remote_exec build "rm -f ${objdir}/${subdir}/${build_id_debug_filename}"
829}
830