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