1 # Copyright 1988-2019 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 "failed to prepare" "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 \\(int argc, char \\*\\*argv, char \\*\\*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 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
122 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
124 gdb_test "info break" \
125 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
126 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
127 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile1:$bp_location8.*
128 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:$bp_location7.*
129 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
130 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
131 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location2.*
132 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
133 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
137 # Test info breakpoint with arguments
147 gdb_test_multiple "info break 2 4 6" "info break 2 4 6" {
148 -re "1\[\t \]+breakpoint *keep y\[^\r\n\]*:$main_line\[^\r\n\]*" {
152 -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in marker2 at \[^\r\n\]*" {
156 -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location7\[^\r\n\]*" {
160 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
164 -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
168 -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location2\[^\r\n\]*" {
172 -re ".*$gdb_prompt $" {
173 if { !$see1 && $see2 && !$see3 && $see4 && !$see5 && $see6 } then {
174 pass "info break 2 4 6"
176 fail "info break 2 4 6"
188 gdb_test_multiple "info break 3-5" "info break 3-5" {
189 -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
193 -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in marker2 at \[^\r\n\]*" {
197 -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location7\[^\r\n\]*" {
201 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
205 -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
209 -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location2\[^\r\n\]*" {
213 -re ".*$gdb_prompt $" {
214 if { !$see1 && !$see2 && $see3 && $see4 && $see5 && !$see6 } then {
215 pass "info break 3-5"
217 fail "info break 3-5"
223 # Test disable/enable with arguments
226 # Test with value history
228 gdb_test "print 1" "" ""
229 gdb_test "print 2" "" ""
230 gdb_test "print 3" "" ""
231 gdb_test "print 4" "" ""
232 gdb_test "print 5" "" ""
233 gdb_test "print 6" "" ""
235 # $2 is 2 and $$ is 5
236 gdb_test_no_output "disable \$2 \$\$" "disable using history values"
245 gdb_test_multiple "info break" "check disable with history values" {
246 -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
250 -re "2\[\t \]+breakpoint *keep n\[^\r\n\]* in marker2 at \[^\r\n\]*" {
254 -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location7\[^\r\n\]*" {
258 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
262 -re "5\[\t \]+breakpoint *keep n\[^\r\n\]*$bp_location1\[^\r\n\]*" {
266 -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location2\[^\r\n\]*" {
270 -re ".*$gdb_prompt $" {
271 if { $see1 && $see2 && $see3 && $see4 && $see5 && $see6 } then {
272 pass "check disable with history values"
274 fail "check disable with history values"
279 gdb_test "enable" "" ""
280 gdb_test "set \$foo = 3" "" ""
281 gdb_test "set \$bar = 6" "" ""
282 gdb_test_no_output "disable \$foo \$bar" "disable with convenience values"
291 gdb_test_multiple "info break" "check disable with convenience values" {
292 -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
296 -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in marker2 at \[^\r\n\]*" {
300 -re "3\[\t \]+breakpoint *keep n\[^\r\n\]*$bp_location7\[^\r\n\]*" {
304 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
308 -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
312 -re "6\[\t \]+breakpoint *keep n\[^\r\n\]*$bp_location2\[^\r\n\]*" {
316 -re ".*$gdb_prompt $" {
317 if { $see1 && $see2 && $see3 && $see4 && $see5 && $see6 } then {
318 pass "check disable with convenience values"
320 fail "check disable with convenience values"
325 # test with bad values
327 gdb_test "enable" "" ""
328 gdb_test "disable 10" "No breakpoint number 10." \
329 "disable non-existent breakpoint 10"
331 gdb_test_no_output "set \$baz = 1.234"
332 gdb_test "disable \$baz" \
333 "Convenience variable must have integer value.*" \
334 "disable with non-integer convenience var"
335 gdb_test "disable \$grbx" \
336 "Convenience variable must have integer value.*" \
337 "disable with non-existent convenience var"
338 gdb_test "disable \$10" \
339 "History has not yet reached .10." \
340 "disable with non-existent history value"
341 gdb_test "disable \$1foo" \
342 "Convenience variable must have integer value.*" \
343 "disable with badly formed history value"
345 # FIXME: The rest of this test doesn't work with anything that can't
347 # Huh? There doesn't *appear* to be anything that passes arguments
351 # run until the breakpoint at main is hit. For non-stubs-using targets.
355 "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*" \
356 "run until function breakpoint"
358 # Test the 'list' commands sets current file for the 'break LINENO' command.
359 set bp_marker1 [gdb_get_line_number "set breakpoint 15 here" ${srcfile1}]
360 gdb_test "list marker1" ".*"
361 gdb_test "break $bp_marker1" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*${srcfile1}, line ${bp_marker1}\\." \
363 gdb_test_no_output {delete $bpnum}
366 # run until the breakpoint at a line number
368 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
369 "run until breakpoint set at a line number"
372 # Run until the breakpoint set in a function in a file
374 for {set i 6} {$i >= 1} {incr i -1} {
375 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
376 "run until file:function($i) breakpoint"
380 # Run until the breakpoint set at a quoted function
382 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:$bp_location8.*" \
383 "run until quoted breakpoint"
385 # run until the file:function breakpoint at a line number in a file
387 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
388 "run until file:linenum breakpoint"
390 # Test break at offset +1
391 set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
393 gdb_test "break +1" \
394 "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
395 "breakpoint offset +1"
397 # Check to see if breakpoint is hit when stepped onto
400 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
401 "step onto breakpoint"
403 # Check to see if breakpoint can be set on ending brace of function
404 set bp_location10a [gdb_get_line_number "set breakpoint 10a here"]
406 gdb_test "break $bp_location10a" \
407 "Breakpoint.*at.* file .*$srcfile, line $bp_location10a\\." \
408 "setting breakpoint at }"
410 gdb_test "continue" \
411 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10a.*$bp_location10a\[\t \]+}.*breakpoint 10a here.*" \
412 "continue to breakpoint at }"
415 # delete all breakpoints so we can start over, course this can be a test too
420 # test temporary breakpoint at function
423 gdb_test "tbreak main" "Temporary breakpoint.*at.* file .*$srcfile, line.*" "temporary breakpoint function"
426 # test break at function in file
429 gdb_test "tbreak $srcfile:factorial" "Temporary breakpoint.*at.* file .*$srcfile, line.*" \
430 "Temporary breakpoint function in file"
433 # test break at line number
435 gdb_test "tbreak $bp_location1" \
436 "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location1.*" \
437 "temporary breakpoint line number #1"
439 gdb_test "tbreak $bp_location6" "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "temporary breakpoint line number #2"
442 # test break at line number in file
444 gdb_test "tbreak $srcfile:$bp_location2" \
445 "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location2.*" \
446 "temporary breakpoint line number in file #1"
448 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
449 gdb_test "tbreak $srcfile:$bp_location11" "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
452 # check to see what breakpoints are set (temporary this time)
454 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
455 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
456 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:$bp_location7.*\[\r\n\]
457 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
458 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
459 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
460 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
461 "Temporary breakpoint info"
466 # Verify that catchpoints for fork, vfork and exec don't trigger
467 # inappropriately. (There are no calls to those system functions
468 # in this test program.)
470 if ![runto_main] then { fail "break tests suppressed" }
473 "Catch requires an event name." \
474 "catch requires an event name"
476 gdb_test "catch fork" "Catchpoint \[0-9\]+ \\(fork\\)" \
477 "set catch fork, never expected to trigger"
479 gdb_test "catch vfork" "Catchpoint \[0-9\]+ \\(vfork\\)" \
480 "set catch vfork, never expected to trigger"
482 gdb_test "catch exec" "Catchpoint \[0-9\]+ \\(exec\\)" \
483 "set catch exec, never expected to trigger"
485 # Verify that GDB responds gracefully when asked to set a breakpoint
486 # on a nonexistent source line.
488 gdb_test_no_output "set breakpoint pending off"
489 gdb_test "break 999" \
490 "No line 999 in the current file." \
491 "break on non-existent source line"
493 # Run to the desired default location. If not positioned here, the
494 # tests below don't work.
496 gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" \
499 # Verify that GDB allows one to just say "break", which is treated
500 # as the "default" breakpoint. Note that GDB gets cute when printing
501 # the informational message about other breakpoints at the same
502 # location. We'll hit that bird with this stone too.
504 gdb_test "break" "Breakpoint \[0-9\]*.*" \
505 "break on default location, 1st time"
508 "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
509 "break on default location, 2nd time"
512 "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
513 "break on default location, 3rd time"
516 "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
517 "break on default location, 4th time"
519 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
520 # "silent" about its triggering.
522 if ![runto_main] then { fail "break tests suppressed" }
524 gdb_test_multiple "break $bp_location1" \
525 "set to-be-silent break bp_location1" {
526 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $" {
527 pass "set to-be-silent break bp_location1"
531 gdb_test "commands $expect_out(1,string)\nsilent\nend" ">end" "set silent break bp_location1"
533 gdb_test "info break $expect_out(1,string)" \
534 "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*" \
535 "info silent break bp_location1"
537 gdb_test "continue" "Continuing." \
538 "hit silent break bp_location1"
540 gdb_test "bt" "#0 main .* at .*:$bp_location1.*" \
541 "stopped for silent break bp_location1"
543 # Verify that GDB can at least parse a breakpoint with the
544 # "thread" keyword. (We won't attempt to test here that a
545 # thread-specific breakpoint really triggers appropriately.
546 # The gdb.threads subdirectory contains tests for that.)
548 set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
549 gdb_test "break $bp_location12 thread 999" "Unknown thread 999.*" \
550 "thread-specific breakpoint on non-existent thread disallowed"
552 gdb_test "break $bp_location12 thread foo" \
553 "Invalid thread ID: foo" \
554 "thread-specific breakpoint on bogus thread ID disallowed"
556 # Verify that GDB responds gracefully to a breakpoint command with
559 gdb_test "break $bp_location12 foo" \
560 "malformed linespec error: unexpected string, \"foo\".*" \
561 "breakpoint with trailing garbage disallowed"
563 # Verify that GDB responds gracefully to a "clear" command that has
564 # no matching breakpoint. (First, get us off the current source line,
565 # which we know has a breakpoint.)
567 gdb_test "next" "marker1.*" "step over breakpoint"
569 gdb_test "clear 81" "No breakpoint at 81.*" \
570 "clear line has no breakpoint disallowed"
572 gdb_test "clear" "No breakpoint at this line.*" \
573 "clear current line has no breakpoint disallowed"
575 # Verify that we can set and clear multiple breakpoints.
577 # We don't test that it deletes the correct breakpoints. We do at
578 # least test that it deletes more than one breakpoint.
580 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
581 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
582 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
584 # Verify that a breakpoint can be set via a convenience variable.
586 gdb_test_no_output "set \$foo=$bp_location11" \
587 "set convenience variable \$foo to bp_location11"
589 gdb_test "break \$foo" \
590 "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*" \
591 "set breakpoint via convenience variable"
593 # Verify that GDB responds gracefully to an attempt to set a
594 # breakpoint via a convenience variable whose type is not integer.
596 gdb_test_no_output "set \$foo=81.5" \
597 "set convenience variable \$foo to 81.5"
599 gdb_test "break \$foo" \
600 "Convenience variables used in line specs must have integer values.*" \
601 "set breakpoint via non-integer convenience variable disallowed"
603 # Verify that we can set and trigger a breakpoint in a user-called function.
605 gdb_test "break marker2" \
606 "Breakpoint (\[0-9\]*) at .*, line $bp_location8.*" \
607 "set breakpoint on to-be-called function"
609 gdb_test "print marker2(99)" \
610 "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.*" \
611 "hit breakpoint on called function"
613 # As long as we're stopped (breakpointed) in a called function,
614 # verify that we can successfully backtrace & such from here.
616 "#0\[ \t\]*($hex in )?marker2.*:$bp_location8\r\n#1\[ \t\]*<function called from gdb>.*" \
617 "backtrace while in called function"
619 # Return from the called function. For remote targets, it's important to do
620 # this before runto_main, which otherwise may silently stop on the dummy
621 # breakpoint inserted by GDB at the program's entry point.
623 gdb_test_multiple "finish" "finish from called function" {
624 -re "Run till exit from .*marker2.* at .*$bp_location8\r\n.*function called from gdb.*$gdb_prompt $" {
625 pass "finish from called function"
627 -re "Run till exit from .*marker2.* at .*$bp_location8\r\n.*Value returned.*$gdb_prompt $" {
628 pass "finish from called function"
632 # Verify that GDB responds gracefully to a "finish" command with
635 if ![runto_main] then { fail "break tests suppressed" }
637 send_gdb "finish 123\n"
639 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
640 {pass "finish with arguments disallowed"}
642 {fail "finish with arguments disallowed"}
643 timeout {fail "(timeout) finish with arguments disallowed"}
646 # Verify that GDB responds gracefully to a request to "finish" from
647 # the outermost frame. On a stub that never exits, this will just
648 # run to the stubs routine, so we don't get this error... Thus the
652 gdb_test_multiple "finish" "finish from outermost frame disallowed" {
653 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $" {
654 pass "finish from outermost frame disallowed"
656 -re "Run till exit from.*\r\n$gdb_prompt $" {
657 pass "finish from outermost frame disallowed"
665 # Test "next" over recursive function call.
668 proc test_next_with_recursion {} {
673 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
676 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
678 # Run until we call factorial with 6
681 gdb_test "" "Break.* factorial .value=6. .*" "run to factorial(6)"
683 # Continue until we call factorial recursively with 5.
685 if [gdb_test "continue" \
686 "Continuing.*Break.* factorial .value=5. .*" \
687 "continue to factorial(5)"] then { gdb_suppress_tests }
689 # Do a backtrace just to confirm how many levels deep we are.
691 if [gdb_test "backtrace" \
692 "#0\[ \t\]+ factorial .value=5..*" \
693 "backtrace from factorial(5)"] then { gdb_suppress_tests }
695 # Now a "next" should position us at the recursive call, which
696 # we will be performing with 4.
698 if [gdb_test "next" \
699 ".* factorial .value - 1.;.*" \
700 "next to recursive call"] then { gdb_suppress_tests }
702 # Disable the breakpoint at the entry to factorial by deleting them all.
703 # The "next" should run until we return to the next line from this
704 # recursive call to factorial with 4.
705 # Buggy versions of gdb will stop instead at the innermost frame on
706 # the line where we are trying to "next" to.
710 if [istarget "mips*tx39-*"] {
713 # We used to set timeout here for all other targets as well. This
714 # is almost certainly wrong. The proper timeout depends on the
715 # target system in use, and how we communicate with it, so there
716 # is no single value appropriate for all targets. The timeout
717 # should be established by the Dejagnu config file(s) for the
718 # board, and respected by the test suite.
720 # For example, if I'm running GDB over an SSH tunnel talking to a
721 # portmaster in California talking to an ancient 68k board running
722 # a crummy ROM monitor (a situation I can only wish were
723 # hypothetical), then I need a large timeout. But that's not the
724 # kind of knowledge that belongs in this file.
726 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
727 "next over recursive call"
729 # OK, we should be back in the same stack frame we started from.
730 # Do a backtrace just to confirm.
732 set result [gdb_test "backtrace" \
733 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
734 "backtrace from factorial(5.1)"]
735 if { $result != 0 } { gdb_suppress_tests }
737 if [target_info exists gdb,noresults] { gdb_suppress_tests }
738 gdb_continue_to_end "recursive next test"
739 gdb_stop_suppressing_tests
742 test_next_with_recursion
747 # build a new file with optimization enabled so that we can try breakpoints
748 # on targets with optimized prologues
750 if { [prepare_for_testing "failed to prepare" "breako2" {break.c break1.c} {debug nowarnings optimize=-O2}] } {
755 # test break at function
757 gdb_test "break main" \
758 "Breakpoint.*at.* file .*, line.*" \
759 "breakpoint function, optimized file"
762 # test break at function
764 gdb_test "break marker4" \
765 "Breakpoint.*at.* file .*$srcfile1, line.*" \
766 "breakpoint small function, optimized file"
769 # run until the breakpoint at main is hit. For non-stubs-using targets.
773 set test "run until function breakpoint, optimized file"
774 gdb_test_multiple "" $test {
775 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
778 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $" {
779 pass "$test (code motion)"
784 # run until the breakpoint at a small function
788 # Add a second pass pattern. The behavior differs here between stabs
789 # and dwarf for one-line functions. Stabs preserves two line symbols
790 # (one before the prologue and one after) with the same line number,
791 # but dwarf regards these as duplicates and discards one of them.
792 # Therefore the address after the prologue (where the breakpoint is)
793 # has no exactly matching line symbol, and GDB reports the breakpoint
794 # as if it were in the middle of a line rather than at the beginning.
796 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
798 gdb_test_multiple "continue" \
799 "run until breakpoint set at small function, optimized file" {
800 -re "Breakpoint $decimal, marker4 \\(d=(d@entry=)?177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
801 pass "run until breakpoint set at small function, optimized file (line bp_location14)"
803 -re "Breakpoint $decimal, factorial \\(.*\\) .*\{\r\n$gdb_prompt" {
804 # GCC 4.3 emits bad line number information - see gcc/36748.
805 if { [test_compiler_info "gcc-4-3-*"] } {
808 fail "run until breakpoint set at small function, optimized file"
812 clean_restart breako2
815 # test that 'rbreak' on a symbol that may be from a shared library doesn't
816 # cause a "Junk at end of arguments." error.
818 # On x86 GNU/Linux, this test will choke on e.g. __libc_start_main@plt.
820 # Note that this test won't necessarily choke on all targets even if
821 # all the rbreak issue is present. rbreak needs to match and set a
822 # breakpoint on a symbol causes 'break' to choke.
825 gdb_test_no_output "set breakpoint pending on" "rbreak junk pending setup"
827 # We expect at least one breakpoint to be set when we "rbreak main".
828 gdb_test "rbreak main" \
829 ".*Breakpoint.*at.* file .*$srcfile, line.*" \
830 "rbreak junk set breakpoint"
832 # Run to a breakpoint. Fail if we see "Junk at end of arguments".
835 set test "rbreak junk"
836 gdb_test_multiple "" $test {
837 -re "Junk at end of arguments" {
840 -re ".*Breakpoint \[0-9\]+,.*$gdb_prompt $" {
846 # Test break via convenience variable with file name
848 set line [gdb_get_line_number "set breakpoint 1 here"]
849 gdb_test_no_output "set \$l = $line"
852 set test "break ${srcfile}:\$l"
853 gdb_test_multiple "$test" $test {
854 -re "Breakpoint $decimal at $hex: file .*break\\.c, line ($decimal)\\.\r\n$gdb_prompt $" {
855 # Save the actual line number on which the breakpoint was
856 # actually set. On some systems (Eg: Ubuntu 16.04 with GCC
857 # version 5.4.0), that line gets completely inlined, including
858 # the call to printf, and so we end up inserting the breakpoint
859 # on one of the following lines instead.
860 set line_actual $expect_out(1,string)
865 gdb_test_no_output "set \$foo=81.5" \
866 "set convenience variable \$foo to 81.5"
867 gdb_test "break $srcfile:\$foo" \
868 "Convenience variables used in line specs must have integer values.*" \
869 "set breakpoint via non-integer convenience variable disallowed"
873 # Test that commands can be cleared without error.
876 gdb_test "commands\nprint 232323\nend" ">end" "set some breakpoint commands"
877 gdb_test "commands\nend" ">end" "clear breakpoint commands"
878 # We verify that the commands were cleared by ensuring that the last
879 # breakpoint's location ends the output -- if there were commands,
880 # they would have been printed after the location.
881 gdb_test "info break" "$srcfile:$line_actual" "verify that they were cleared"