1 # Copyright 1988-2014 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This file was written by Rob Savoye. (rob@cygnus.com)
18 if { [prepare_for_testing break.exp "break" {break.c break1.c} {debug nowarnings}] } {
24 # test simple breakpoint setting commands
27 # Test deleting all breakpoints when there are none installed,
28 # GDB should not prompt for confirmation.
29 # Note that lib/gdb.exp provides a "delete_breakpoints" proc
30 # for general use elsewhere.
32 send_gdb "delete breakpoints\n"
34 -re "Delete all breakpoints.*$" {
38 fail "Delete all breakpoints when none (unexpected prompt)"
40 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
43 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
44 timeout { fail "Delete all breakpoints when none (timeout)" }
48 # test break at function
50 gdb_test "break main" \
51 "Breakpoint.*at.* file .*$srcfile, line.*" \
55 # test break at quoted function
57 gdb_test "break \"marker2\"" \
58 "Breakpoint.*at.* file .*$srcfile1, line.*" \
59 "breakpoint quoted function"
62 # test break at function in file
64 gdb_test "break $srcfile:factorial" \
65 "Breakpoint.*at.* file .*$srcfile, line.*" \
66 "breakpoint function in file"
68 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
71 # test break at line number
73 # Note that the default source file is the last one whose source text
74 # was printed. For native debugging, before we've executed the
75 # program, this is the file containing main, but for remote debugging,
76 # it's wherever the processor was stopped when we connected to the
77 # board. So, to be sure, we do a list command.
79 gdb_test "list main" \
80 ".*main \\(argc, argv, envp\\).*" \
81 "use `list' to establish default source file"
82 gdb_test "break $bp_location1" \
83 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
84 "breakpoint line number"
87 # test duplicate breakpoint
89 gdb_test "break $bp_location1" \
90 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
91 "breakpoint duplicate"
93 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
96 # test break at line number in file
98 gdb_test "break $srcfile:$bp_location2" \
99 "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
100 "breakpoint line number in file"
102 set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
103 set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
106 # Test putting a break at the start of a multi-line if conditional.
107 # Verify the breakpoint was put at the start of the conditional.
109 gdb_test "break multi_line_if_conditional" \
110 "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
111 "breakpoint at start of multi line if conditional"
113 gdb_test "break multi_line_while_conditional" \
114 "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
115 "breakpoint at start of multi line while conditional"
117 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
119 set main_line $bp_location6
121 if {$hp_aCC_compiler} {
122 set proto "\\(int\\)"
127 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
128 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
129 set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
131 gdb_test "info break" \
132 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
133 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
134 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile1:($bp_location8|$bp_location9).*
135 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial$proto at .*$srcfile:$bp_location7.*
136 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
137 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
138 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location2.*
139 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
140 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
144 # Test info breakpoint with arguments
154 gdb_test_multiple "info break 2 4 6" "info break 2 4 6" {
155 -re "1\[\t \]+breakpoint *keep y\[^\r\n\]*:$main_line\[^\r\n\]*" {
159 -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in marker2 at \[^\r\n\]*" {
163 -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location7\[^\r\n\]*" {
167 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
171 -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
175 -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location2\[^\r\n\]*" {
179 -re ".*$gdb_prompt $" {
180 if { !$see1 && $see2 && !$see3 && $see4 && !$see5 && $see6 } then {
181 pass "info break 2 4 6"
183 fail "info break 2 4 6"
195 gdb_test_multiple "info break 3-5" "info break 3-5" {
196 -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
200 -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in marker2 at \[^\r\n\]*" {
204 -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location7\[^\r\n\]*" {
208 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
212 -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
216 -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location2\[^\r\n\]*" {
220 -re ".*$gdb_prompt $" {
221 if { !$see1 && !$see2 && $see3 && $see4 && $see5 && !$see6 } then {
222 pass "info break 3-5"
224 fail "info break 3-5"
230 # Test disable/enable with arguments
233 # Test with value history
235 gdb_test "print 1" "" ""
236 gdb_test "print 2" "" ""
237 gdb_test "print 3" "" ""
238 gdb_test "print 4" "" ""
239 gdb_test "print 5" "" ""
240 gdb_test "print 6" "" ""
242 # $2 is 2 and $$ is 5
243 gdb_test_no_output "disable \$2 \$\$" "disable using history values"
252 gdb_test_multiple "info break" "check disable with history values" {
253 -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
257 -re "2\[\t \]+breakpoint *keep n\[^\r\n\]* in marker2 at \[^\r\n\]*" {
261 -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location7\[^\r\n\]*" {
265 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
269 -re "5\[\t \]+breakpoint *keep n\[^\r\n\]*$bp_location1\[^\r\n\]*" {
273 -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location2\[^\r\n\]*" {
277 -re ".*$gdb_prompt $" {
278 if { $see1 && $see2 && $see3 && $see4 && $see5 && $see6 } then {
279 pass "check disable with history values"
281 fail "check disable with history values"
286 gdb_test "enable" "" ""
287 gdb_test "set \$foo = 3" "" ""
288 gdb_test "set \$bar = 6" "" ""
289 gdb_test_no_output "disable \$foo \$bar" "disable with convenience values"
298 gdb_test_multiple "info break" "check disable with convenience values" {
299 -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
303 -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in marker2 at \[^\r\n\]*" {
307 -re "3\[\t \]+breakpoint *keep n\[^\r\n\]*$bp_location7\[^\r\n\]*" {
311 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
315 -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
319 -re "6\[\t \]+breakpoint *keep n\[^\r\n\]*$bp_location2\[^\r\n\]*" {
323 -re ".*$gdb_prompt $" {
324 if { $see1 && $see2 && $see3 && $see4 && $see5 && $see6 } then {
325 pass "check disable with convenience values"
327 fail "check disable with convenience values"
332 # test with bad values
334 gdb_test "enable" "" ""
335 gdb_test "disable 10" "No breakpoint number 10." \
336 "disable non-existent breakpoint 10"
338 gdb_test_no_output "set \$baz = 1.234"
339 gdb_test "disable \$baz" \
340 "Convenience variable must have integer value.*" \
341 "disable with non-integer convenience var"
342 gdb_test "disable \$grbx" \
343 "Convenience variable must have integer value.*" \
344 "disable with non-existent convenience var"
345 gdb_test "disable \$10" \
346 "History has not yet reached .10." \
347 "disable with non-existent history value"
348 gdb_test "disable \$1foo" \
349 "Convenience variable must have integer value.*" \
350 "disable with badly formed history value"
352 # FIXME: The rest of this test doesn't work with anything that can't
354 # Huh? There doesn't *appear* to be anything that passes arguments
358 # run until the breakpoint at main is hit. For non-stubs-using targets.
362 "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*" \
363 "run until function breakpoint"
365 # Test the 'list' commands sets current file for the 'break LINENO' command.
366 set bp_marker1 [gdb_get_line_number "set breakpoint 16 here" ${srcfile1}]
367 gdb_test "list marker1" ".*"
368 gdb_test "break $bp_marker1" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*${srcfile1}, line ${bp_marker1}\\." \
370 gdb_test_no_output {delete $bpnum}
373 # run until the breakpoint at a line number
375 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
376 "run until breakpoint set at a line number"
379 # Run until the breakpoint set in a function in a file
381 for {set i 6} {$i >= 1} {incr i -1} {
382 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
383 "run until file:function($i) breakpoint"
387 # Run until the breakpoint set at a quoted function
389 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*" \
390 "run until quoted breakpoint"
392 # run until the file:function breakpoint at a line number in a file
394 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
395 "run until file:linenum breakpoint"
397 # Test break at offset +1
398 set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
400 gdb_test "break +1" \
401 "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
402 "breakpoint offset +1"
404 # Check to see if breakpoint is hit when stepped onto
407 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
408 "step onto breakpoint"
410 # Check to see if breakpoint can be set on ending brace of function
411 set bp_location10a [gdb_get_line_number "set breakpoint 10a here"]
413 gdb_test "break $bp_location10a" \
414 "Breakpoint.*at.* file .*$srcfile, line $bp_location10a\\." \
415 "setting breakpoint at }"
417 gdb_test "continue" \
418 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10a.*$bp_location10a\[\t \]+}.*breakpoint 10a here.*" \
419 "continue to breakpoint at }"
422 # delete all breakpoints so we can start over, course this can be a test too
427 # test temporary breakpoint at function
430 gdb_test "tbreak main" "Temporary breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
433 # test break at function in file
436 gdb_test "tbreak $srcfile:factorial" "Temporary breakpoint.*at.* file .*$srcfile, line.*" \
437 "Temporary breakpoint function in file"
440 # test break at line number
442 gdb_test "tbreak $bp_location1" \
443 "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location1.*" \
444 "Temporary breakpoint line number #1"
446 gdb_test "tbreak $bp_location6" "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
449 # test break at line number in file
451 gdb_test "tbreak $srcfile:$bp_location2" \
452 "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location2.*" \
453 "Temporary breakpoint line number in file #1"
455 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
456 gdb_test "tbreak $srcfile:$bp_location11" "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
459 # check to see what breakpoints are set (temporary this time)
461 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
462 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
463 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial$proto at .*$srcfile:$bp_location7.*\[\r\n\]
464 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
465 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
466 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
467 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
468 "Temporary breakpoint info"
473 # Verify that catchpoints for fork, vfork and exec don't trigger
474 # inappropriately. (There are no calls to those system functions
475 # in this test program.)
477 if ![runto_main] then { fail "break tests suppressed" }
480 "Catch requires an event name." \
481 "catch requires an event name"
484 set name "set catch fork, never expected to trigger"
485 gdb_test_multiple "catch fork" "$name" {
486 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $" {
489 -re "Catch of fork not yet implemented.*$gdb_prompt $" {
495 # If we are on HP-UX 10.20, we expect an error message to be
496 # printed if we type "catch vfork" at the gdb gdb_prompt. This is
497 # because on HP-UX 10.20, we cannot catch vfork events.
499 set name "set catch vfork, never expected to trigger"
501 if [istarget "hppa*-hp-hpux10.20"] then {
502 gdb_test "catch vfork" \
503 "Catch of vfork events not supported on HP-UX 10.20..*" \
506 gdb_test_multiple "catch vfork" "$name" {
507 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $" {
510 -re "Catch of vfork not yet implemented.*$gdb_prompt $" {
516 set name "set catch exec, never expected to trigger"
517 gdb_test_multiple "catch exec" "$name" {
518 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $" {
521 -re "Catch of exec not yet implemented.*$gdb_prompt $" {
526 # Verify that GDB responds gracefully when asked to set a breakpoint
527 # on a nonexistent source line.
529 gdb_test_no_output "set breakpoint pending off"
530 gdb_test "break 999" \
531 "No line 999 in the current file." \
532 "break on non-existent source line"
534 # Run to the desired default location. If not positioned here, the
535 # tests below don't work.
537 gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" \
540 # Verify that GDB allows one to just say "break", which is treated
541 # as the "default" breakpoint. Note that GDB gets cute when printing
542 # the informational message about other breakpoints at the same
543 # location. We'll hit that bird with this stone too.
545 gdb_test "break" "Breakpoint \[0-9\]*.*" \
546 "break on default location, 1st time"
549 "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
550 "break on default location, 2nd time"
553 "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
554 "break on default location, 3rd time"
557 "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
558 "break on default location, 4th time"
560 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
561 # "silent" about its triggering.
563 if ![runto_main] then { fail "break tests suppressed" }
565 gdb_test_multiple "break $bp_location1" \
566 "set to-be-silent break bp_location1" {
567 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $" {
568 pass "set to-be-silent break bp_location1"
572 gdb_test "commands $expect_out(1,string)\nsilent\nend" ">end" "set silent break bp_location1"
574 gdb_test "info break $expect_out(1,string)" \
575 "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*" \
576 "info silent break bp_location1"
578 gdb_test "continue" "Continuing." \
579 "hit silent break bp_location1"
581 gdb_test "bt" "#0 main .* at .*:$bp_location1.*" \
582 "stopped for silent break bp_location1"
584 # Verify that GDB can at least parse a breakpoint with the
585 # "thread" keyword. (We won't attempt to test here that a
586 # thread-specific breakpoint really triggers appropriately.
587 # The gdb.threads subdirectory contains tests for that.)
589 set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
590 gdb_test "break $bp_location12 thread 999" "Unknown thread 999.*" \
591 "thread-specific breakpoint on non-existent thread disallowed"
593 gdb_test "break $bp_location12 thread foo" \
594 "Junk after thread keyword.*" \
595 "thread-specific breakpoint on bogus thread ID disallowed"
597 # Verify that GDB responds gracefully to a breakpoint command with
600 gdb_test "break $bp_location12 foo" \
601 "malformed linespec error: unexpected string, \"foo\".*" \
602 "breakpoint with trailing garbage disallowed"
604 # Verify that GDB responds gracefully to a "clear" command that has
605 # no matching breakpoint. (First, get us off the current source line,
606 # which we know has a breakpoint.)
608 gdb_test "next" "marker1.*" "step over breakpoint"
610 gdb_test "clear 81" "No breakpoint at 81.*" \
611 "clear line has no breakpoint disallowed"
613 gdb_test "clear" "No breakpoint at this line.*" \
614 "clear current line has no breakpoint disallowed"
616 # Verify that we can set and clear multiple breakpoints.
618 # We don't test that it deletes the correct breakpoints. We do at
619 # least test that it deletes more than one breakpoint.
621 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
622 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
623 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
625 # Verify that a breakpoint can be set via a convenience variable.
627 gdb_test_no_output "set \$foo=$bp_location11" \
628 "set convenience variable \$foo to bp_location11"
630 gdb_test "break \$foo" \
631 "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*" \
632 "set breakpoint via convenience variable"
634 # Verify that GDB responds gracefully to an attempt to set a
635 # breakpoint via a convenience variable whose type is not integer.
637 gdb_test_no_output "set \$foo=81.5" \
638 "set convenience variable \$foo to 81.5"
640 gdb_test "break \$foo" \
641 "Convenience variables used in line specs must have integer values.*" \
642 "set breakpoint via non-integer convenience variable disallowed"
644 # Verify that we can set and trigger a breakpoint in a user-called function.
646 gdb_test "break marker2" \
647 "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*" \
648 "set breakpoint on to-be-called function"
650 gdb_test "print marker2(99)" \
651 "The program being debugged stopped while in a function called from GDB.\r\nEvaluation of the expression containing the function\r\n.marker2$proto. will be abandoned.\r\nWhen the function is done executing, GDB will silently stop.*" \
652 "hit breakpoint on called function"
654 # As long as we're stopped (breakpointed) in a called function,
655 # verify that we can successfully backtrace & such from here.
657 # In this and the following test, the _sr4export check apparently is needed
660 gdb_test_multiple "bt" "backtrace while in called function" {
661 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $" {
662 pass "backtrace while in called function"
664 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $" {
665 pass "backtrace while in called function"
669 # Return from the called function. For remote targets, it's important to do
670 # this before runto_main, which otherwise may silently stop on the dummy
671 # breakpoint inserted by GDB at the program's entry point.
673 gdb_test_multiple "finish" "finish from called function" {
674 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $" {
675 pass "finish from called function"
677 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $" {
678 pass "finish from called function"
680 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $" {
681 pass "finish from called function"
685 # Verify that GDB responds gracefully to a "finish" command with
688 if ![runto_main] then { fail "break tests suppressed" }
690 send_gdb "finish 123\n"
692 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
693 {pass "finish with arguments disallowed"}
695 {fail "finish with arguments disallowed"}
696 timeout {fail "(timeout) finish with arguments disallowed"}
699 # Verify that GDB responds gracefully to a request to "finish" from
700 # the outermost frame. On a stub that never exits, this will just
701 # run to the stubs routine, so we don't get this error... Thus the
705 gdb_test_multiple "finish" "finish from outermost frame disallowed" {
706 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $" {
707 pass "finish from outermost frame disallowed"
709 -re "Run till exit from.*\r\n$gdb_prompt $" {
710 pass "finish from outermost frame disallowed"
714 # Verify that we can explicitly ask GDB to stop on all shared library
715 # events, and that it does so.
717 if [istarget "hppa*-*-hpux*"] then {
718 if ![runto_main] then { fail "break tests suppressed" }
720 gdb_test_no_output "set stop-on-solib-events 1" \
721 "set stop-on-solib-events"
724 "Stopped due to shared library event.*" \
725 "triggered stop-on-solib-events" \
726 "Start it from the beginning.*y or n. $" \
729 gdb_test_no_output "set stop-on-solib-events 0" \
730 "reset stop-on-solib-events"
733 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
734 # gracefully responds to requests to create them.
736 if [istarget "hppa*-*-hpux*"] then {
737 if ![runto_main] then { fail "break tests suppressed" }
740 "No hardware breakpoint support in the target.*" \
741 "hw breaks disallowed"
744 "No hardware breakpoint support in the target.*" \
745 "temporary hw breaks disallowed"
752 # Test "next" over recursive function call.
755 proc test_next_with_recursion {} {
760 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
763 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
765 # Run until we call factorial with 6
768 gdb_test "" "Break.* factorial .value=6. .*" "run to factorial(6)"
770 # Continue until we call factorial recursively with 5.
772 if [gdb_test "continue" \
773 "Continuing.*Break.* factorial .value=5. .*" \
774 "continue to factorial(5)"] then { gdb_suppress_tests }
776 # Do a backtrace just to confirm how many levels deep we are.
778 if [gdb_test "backtrace" \
779 "#0\[ \t\]+ factorial .value=5..*" \
780 "backtrace from factorial(5)"] then { gdb_suppress_tests }
782 # Now a "next" should position us at the recursive call, which
783 # we will be performing with 4.
785 if [gdb_test "next" \
786 ".* factorial .value - 1.;.*" \
787 "next to recursive call"] then { gdb_suppress_tests }
789 # Disable the breakpoint at the entry to factorial by deleting them all.
790 # The "next" should run until we return to the next line from this
791 # recursive call to factorial with 4.
792 # Buggy versions of gdb will stop instead at the innermost frame on
793 # the line where we are trying to "next" to.
797 if [istarget "mips*tx39-*"] {
800 # We used to set timeout here for all other targets as well. This
801 # is almost certainly wrong. The proper timeout depends on the
802 # target system in use, and how we communicate with it, so there
803 # is no single value appropriate for all targets. The timeout
804 # should be established by the Dejagnu config file(s) for the
805 # board, and respected by the test suite.
807 # For example, if I'm running GDB over an SSH tunnel talking to a
808 # portmaster in California talking to an ancient 68k board running
809 # a crummy ROM monitor (a situation I can only wish were
810 # hypothetical), then I need a large timeout. But that's not the
811 # kind of knowledge that belongs in this file.
813 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
814 "next over recursive call"
816 # OK, we should be back in the same stack frame we started from.
817 # Do a backtrace just to confirm.
819 set result [gdb_test "backtrace" \
820 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
821 "backtrace from factorial(5.1)"]
822 if { $result != 0 } { gdb_suppress_tests }
824 if [target_info exists gdb,noresults] { gdb_suppress_tests }
825 gdb_continue_to_end "recursive next test"
826 gdb_stop_suppressing_tests
829 test_next_with_recursion
834 # build a new file with optimization enabled so that we can try breakpoints
835 # on targets with optimized prologues
837 if { [prepare_for_testing break.exp "breako2" {break.c break1.c} {debug nowarnings optimize=-O2}] } {
842 # test break at function
844 gdb_test "break main" \
845 "Breakpoint.*at.* file .*, line.*" \
846 "breakpoint function, optimized file"
849 # test break at function
851 gdb_test "break marker4" \
852 "Breakpoint.*at.* file .*$srcfile1, line.*" \
853 "breakpoint small function, optimized file"
856 # run until the breakpoint at main is hit. For non-stubs-using targets.
860 set test "run until function breakpoint, optimized file"
861 gdb_test_multiple "" $test {
862 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
865 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $" {
866 pass "$test (code motion)"
871 # run until the breakpoint at a small function
875 # Add a second pass pattern. The behavior differs here between stabs
876 # and dwarf for one-line functions. Stabs preserves two line symbols
877 # (one before the prologue and one after) with the same line number,
878 # but dwarf regards these as duplicates and discards one of them.
879 # Therefore the address after the prologue (where the breakpoint is)
880 # has no exactly matching line symbol, and GDB reports the breakpoint
881 # as if it were in the middle of a line rather than at the beginning.
883 set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
884 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
886 gdb_test_multiple "continue" \
887 "run until breakpoint set at small function, optimized file" {
888 -re "Breakpoint $decimal, marker4 \\(d=(d@entry=)?177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
889 pass "run until breakpoint set at small function, optimized file"
891 -re "Breakpoint $decimal, $hex in marker4 \\(d=(d@entry=)?177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
892 pass "run until breakpoint set at small function, optimized file"
894 -re "Breakpoint $decimal, marker4 \\(d=(d@entry=)?177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
895 # marker4() is defined at line 46 when compiled with -DPROTOTYPES
896 pass "run until breakpoint set at small function, optimized file (line bp_location14)"
898 -re "Breakpoint $decimal, factorial \\(.*\\) .*\{\r\n$gdb_prompt" {
899 # GCC 4.3 emits bad line number information - see gcc/36748.
900 if { [test_compiler_info "gcc-4-3-*"] } {
903 fail "run until breakpoint set at small function, optimized file"
907 clean_restart breako2
910 # test that 'rbreak' on a symbol that may be from a shared library doesn't
911 # cause a "Junk at end of arguments." error.
913 # On x86 GNU/Linux, this test will choke on e.g. __libc_start_main@plt.
915 # Note that this test won't necessarily choke on all targets even if
916 # all the rbreak issue is present. rbreak needs to match and set a
917 # breakpoint on a symbol causes 'break' to choke.
920 gdb_test_no_output "set breakpoint pending on" "rbreak junk pending setup"
922 # We expect at least one breakpoint to be set when we "rbreak main".
923 gdb_test "rbreak main" \
924 ".*Breakpoint.*at.* file .*$srcfile, line.*" \
925 "rbreak junk set breakpoint"
927 # Run to a breakpoint. Fail if we see "Junk at end of arguments".
930 set test "rbreak junk"
931 gdb_test_multiple "" $test {
932 -re "Junk at end of arguments" {
935 -re ".*Breakpoint \[0-9\]+,.*$gdb_prompt $" {
941 # Test break via convenience variable with file name
943 set line [gdb_get_line_number "set breakpoint 1 here"]
944 gdb_test_no_output "set \$l = $line"
945 gdb_breakpoint ${srcfile}:\$l
947 gdb_test_no_output "set \$foo=81.5" \
948 "set convenience variable \$foo to 81.5"
949 gdb_test "break $srcfile:\$foo" \
950 "Convenience variables used in line specs must have integer values.*" \
951 "set breakpoint via non-integer convenience variable disallowed"