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