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