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