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