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