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