1 # Copyright 1988-2023 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 { [build_executable "failed to prepare" "break" {break.c break1.c} {debug nowarnings}] } {
24 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
25 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
26 set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
27 set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
28 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
29 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
30 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
31 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
33 set main_line $bp_location6
35 # In C++ mode, we see a full prototype; in C mode, we only see the
36 # function name, with no parameter info.
38 return "${name}(?:\(\[^\r\n\]*\))?"
41 # test simple breakpoint setting commands
43 proc_with_prefix test_break {} {
46 # Test deleting all breakpoints when there are none installed,
47 # GDB should not prompt for confirmation.
48 # Note that lib/gdb.exp provides a "delete_breakpoints" proc
49 # for general use elsewhere.
50 send_gdb "delete breakpoints\n"
52 -re "Delete all breakpoints.*$" {
55 -re "$::gdb_prompt $" {
56 fail "delete all breakpoints when none (unexpected prompt)"
58 timeout { fail "delete all breakpoints when none (timeout after unexpected prompt)" }
61 -re ".*$::gdb_prompt $" { pass "delete all breakpoints when none" }
62 timeout { fail "delete all breakpoints when none (timeout)" }
65 # test break at function
66 gdb_test "break -q main" \
67 "Breakpoint.*at.* file .*$::srcfile, line.*" \
70 # test break at quoted function
71 gdb_test "break \"marker2\"" \
72 "Breakpoint.*at.* file .*$::srcfile1, line.*" \
73 "breakpoint quoted function"
75 # test break at function in file
76 gdb_test "break $::srcfile:factorial" \
77 "Breakpoint.*at.* file .*$::srcfile, line.*" \
78 "breakpoint function in file"
80 # test break at line number
82 # Note that the default source file is the last one whose source text
83 # was printed. For native debugging, before we've executed the
84 # program, this is the file containing main, but for remote debugging,
85 # it's wherever the processor was stopped when we connected to the
86 # board. So, to be sure, we do a list command.
87 gdb_test "list -q main" \
88 ".*main \\(int argc, char \\*\\*argv, char \\*\\*envp\\).*" \
89 "use `list' to establish default source file"
91 gdb_test "break $::bp_location1" \
92 "Breakpoint.*at.* file .*$::srcfile, line $::bp_location1\\." \
93 "breakpoint line number"
95 # test duplicate breakpoint
96 gdb_test "break $::bp_location1" \
97 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$::srcfile, line $::bp_location1\\." \
98 "breakpoint duplicate"
100 # test break at line number in file
101 gdb_test "break $::srcfile:$::bp_location2" \
102 "Breakpoint.*at.* file .*$::srcfile, line $::bp_location2\\." \
103 "breakpoint line number in file"
105 # Test putting a break at the start of a multi-line if conditional.
106 # Verify the breakpoint was put at the start of the conditional.
107 gdb_test "break multi_line_if_conditional" \
108 "Breakpoint.*at.* file .*$::srcfile, line $::bp_location3\\." \
109 "breakpoint at start of multi line if conditional"
111 gdb_test "break multi_line_while_conditional" \
112 "Breakpoint.*at.* file .*$::srcfile, line $::bp_location4\\." \
113 "breakpoint at start of multi line while conditional"
115 gdb_test "info break" \
116 [multi_line "Num Type\[ \]+Disp Enb Address\[ \]+What.*" \
117 "$::decimal\[\t \]+breakpoint keep y.* in [func main] at .*$::srcfile:$::main_line.*" \
118 "$::decimal\[\t \]+breakpoint keep y.* in [func marker2] at .*$::srcfile1:$::bp_location8.*" \
119 "$::decimal\[\t \]+breakpoint keep y.* in [func factorial] at .*$::srcfile:$::bp_location7.*" \
120 "$::decimal\[\t \]+breakpoint keep y.* in [func main] at .*$::srcfile:$::bp_location1.*" \
121 "$::decimal\[\t \]+breakpoint keep y.* in [func main] at .*$::srcfile:$::bp_location1.*" \
122 "$::decimal\[\t \]+breakpoint keep y.* in [func main] at .*$::srcfile:$::bp_location2.*" \
123 "$::decimal\[\t \]+breakpoint keep y.* in [func multi_line_if_conditional] at .*$::srcfile:$::bp_location3.*" \
124 "$::decimal\[\t \]+breakpoint keep y.* in [func multi_line_while_conditional] at .*$::srcfile:$::bp_location4"] \
128 # Test info breakpoint with arguments
138 gdb_test_multiple "info break 2 4 6" "info break 2 4 6" {
139 -re "1\[\t \]+breakpoint *keep y\[^\r\n\]*:$::main_line\[^\r\n\]*" {
143 -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in [func marker2] at \[^\r\n\]*" {
147 -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location7\[^\r\n\]*" {
151 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location1\[^\r\n\]*" {
155 -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location1\[^\r\n\]*" {
159 -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location2\[^\r\n\]*" {
163 -re ".*$::gdb_prompt $" {
164 if {!$see1 && $see2 && !$see3 && $see4 && !$see5 && $see6} {
165 pass "info break 2 4 6"
167 fail "info break 2 4 6"
179 gdb_test_multiple "info break 3-5" "info break 3-5" {
180 -re "1\[\t \]+breakpoint *keep y.* in [func main] at .*:$::main_line\[^\r\n\]*" {
184 -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in [func marker2] at \[^\r\n\]*" {
188 -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location7\[^\r\n\]*" {
192 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location1\[^\r\n\]*" {
196 -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location1\[^\r\n\]*" {
200 -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location2\[^\r\n\]*" {
204 -re ".*$::gdb_prompt $" {
205 if {!$see1 && !$see2 && $see3 && $see4 && $see5 && !$see6} {
206 pass "info break 3-5"
208 fail "info break 3-5"
214 # Test disable/enable with arguments
217 # Test with value history
219 with_test_prefix "with value history" {
227 # $2 is 2 and $$ is 5
228 gdb_test_no_output "disable \$2 \$\$" "disable using history values"
237 gdb_test_multiple "info break" "check disable with history values" {
238 -re "1\[\t \]+breakpoint *keep y.* in [func main] at .*:$::main_line\[^\r\n\]*" {
242 -re "2\[\t \]+breakpoint *keep n\[^\r\n\]* in [func marker2] at \[^\r\n\]*" {
246 -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location7\[^\r\n\]*" {
250 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location1\[^\r\n\]*" {
254 -re "5\[\t \]+breakpoint *keep n\[^\r\n\]*$::bp_location1\[^\r\n\]*" {
258 -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location2\[^\r\n\]*" {
262 -re ".*$::gdb_prompt $" {
263 if {$see1 && $see2 && $see3 && $see4 && $see5 && $see6} {
264 pass "check disable with history values"
266 fail "check disable with history values"
272 with_test_prefix "with convenience vars" {
274 gdb_test "set \$foo = 3"
275 gdb_test "set \$bar = 6"
276 gdb_test_no_output "disable \$foo \$bar" "disable with convenience values"
285 gdb_test_multiple "info break" "check disable with convenience values" {
286 -re "1\[\t \]+breakpoint *keep y.* in [func main] at .*:$::main_line\[^\r\n\]*" {
290 -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in [func marker2] at \[^\r\n\]*" {
294 -re "3\[\t \]+breakpoint *keep n\[^\r\n\]*$::bp_location7\[^\r\n\]*" {
298 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location1\[^\r\n\]*" {
302 -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$::bp_location1\[^\r\n\]*" {
306 -re "6\[\t \]+breakpoint *keep n\[^\r\n\]*$::bp_location2\[^\r\n\]*" {
310 -re ".*$::gdb_prompt $" {
311 if {$see1 && $see2 && $see3 && $see4 && $see5 && $see6} {
312 pass "check disable with convenience values"
314 fail "check disable with convenience values"
320 # test with bad values
322 with_test_prefix "bad values" {
324 gdb_test "disable 10" "No breakpoint number 10." \
325 "disable non-existent breakpoint 10"
327 gdb_test_no_output "set \$baz = 1.234"
328 gdb_test "disable \$baz" \
329 "Convenience variable must have integer value.*" \
330 "disable with non-integer convenience var"
331 gdb_test "disable \$grbx" \
332 "Convenience variable must have integer value.*" \
333 "disable with non-existent convenience var"
334 gdb_test "disable \$10" \
335 "History has not yet reached .10." \
336 "disable with non-existent history value"
337 gdb_test "disable \$1foo" \
338 "Convenience variable must have integer value.*" \
339 "disable with badly formed history value"
342 # FIXME: The rest of this test doesn't work with anything that can't
344 # Huh? There doesn't *appear* to be anything that passes arguments
348 # run until the breakpoint at main is hit. For non-stubs-using targets.
352 "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$::srcfile:$::bp_location6.*$::bp_location6\[\t \]+if .argc.* \{.*" \
353 "run until function breakpoint"
355 # Test the 'list' commands sets current file for the 'break LINENO' command.
356 set bp_marker1 [gdb_get_line_number "set breakpoint 15 here" $::srcfile1]
357 gdb_test "list marker1" ".*"
358 gdb_test "break $bp_marker1" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*$::srcfile1, line ${bp_marker1}\\." \
360 gdb_test_no_output {delete $bpnum}
363 # run until the breakpoint at a line number
365 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$::srcfile:$::bp_location1.*$::bp_location1\[\t \]+printf.*factorial.*" \
366 "run until breakpoint set at a line number"
369 # Run until the breakpoint set in a function in a file
371 for {set i 6} {$i >= 1} {incr i -1} {
372 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$::srcfile:$::bp_location7.*$::bp_location7\[\t \]+.*if .value > 1. \{.*" \
373 "run until file:function($i) breakpoint"
377 # Run until the breakpoint set at a quoted function
379 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$::srcfile1:$::bp_location8.*" \
380 "run until quoted breakpoint"
382 # run until the file:function breakpoint at a line number in a file
384 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$::srcfile:$::bp_location2.*$::bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
385 "run until file:linenum breakpoint"
387 # Test break at offset +1
388 set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
390 gdb_test "break +1" \
391 "Breakpoint.*at.* file .*$::srcfile, line $bp_location10\\." \
392 "breakpoint offset +1"
394 # Check to see if breakpoint is hit when stepped onto
397 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$::srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
398 "step onto breakpoint"
400 # Check to see if breakpoint can be set on ending brace of function
401 set bp_location10a [gdb_get_line_number "set breakpoint 10a here"]
403 gdb_test "break $bp_location10a" \
404 "Breakpoint.*at.* file .*$::srcfile, line $bp_location10a\\." \
405 "setting breakpoint at \}"
407 gdb_test "continue" \
408 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$::srcfile:$bp_location10a.*$bp_location10a\[\t \]+\}.*breakpoint 10a here.*" \
409 "continue to breakpoint at \}"
414 proc_with_prefix test_tbreak {} {
417 # test temporary breakpoint at function
418 gdb_test "tbreak -q main" "Temporary breakpoint.*at.* file .*$::srcfile, line.*" "temporary breakpoint function"
420 # test break at function in file
421 gdb_test "tbreak $::srcfile:factorial" "Temporary breakpoint.*at.* file .*$::srcfile, line.*" \
422 "Temporary breakpoint function in file"
424 # test break at line number
425 gdb_test "tbreak $::bp_location1" \
426 "Temporary breakpoint.*at.* file .*$::srcfile, line $::bp_location1.*" \
427 "temporary breakpoint line number #1"
429 gdb_test "tbreak $::bp_location6" "Temporary breakpoint.*at.* file .*$::srcfile, line $::bp_location6.*" "temporary breakpoint line number #2"
431 # test break at line number in file
432 gdb_test "tbreak $::srcfile:$::bp_location2" \
433 "Temporary breakpoint.*at.* file .*$::srcfile, line $::bp_location2.*" \
434 "temporary breakpoint line number in file #1"
436 gdb_test "tbreak $::srcfile:$::bp_location11" "Temporary breakpoint.*at.* file .*$::srcfile, line $::bp_location11.*" "Temporary breakpoint line number in file #2"
438 # check to see what breakpoints are set (temporary this time)
439 gdb_test "info break" \
440 [multi_line "Num Type.*Disp Enb Address.*What.*" \
441 "$::decimal\[\t \]+breakpoint del.*y.*in [func main] at .*$::srcfile:$::main_line.*" \
442 "$::decimal\[\t \]+breakpoint del.*y.*in [func factorial] at .*$::srcfile:$::bp_location7.*" \
443 "$::decimal\[\t \]+breakpoint del.*y.*in [func main] at .*$::srcfile:$::bp_location1.*" \
444 "$::decimal\[\t \]+breakpoint del.*y.*in [func main] at .*$::srcfile:$::bp_location6.*" \
445 "$::decimal\[\t \]+breakpoint del.*y.*in [func main] at .*$::srcfile:$::bp_location2.*" \
446 "$::decimal\[\t \]+breakpoint del.*y.*in [func main] at .*$::srcfile:$::bp_location11.*"] \
447 "Temporary breakpoint info"
454 # Verify that catchpoints for fork, vfork and exec don't trigger
455 # inappropriately. (There are no calls to those system functions
456 # in this test program.)
458 proc_with_prefix test_no_break_on_catchpoint {} {
465 gdb_test "catch fork" "Catchpoint \[0-9\]+ \\(fork\\)" \
466 "set catch fork, never expected to trigger"
468 gdb_test "catch vfork" "Catchpoint \[0-9\]+ \\(vfork\\)" \
469 "set catch vfork, never expected to trigger"
471 gdb_test "catch exec" "Catchpoint \[0-9\]+ \\(exec\\)" \
472 "set catch exec, never expected to trigger"
477 test_no_break_on_catchpoint
479 # Verify that GDB responds gracefully when asked to set a breakpoint
480 # on a nonexistent source line.
482 proc_with_prefix test_break_nonexistent_line {} {
489 gdb_test_no_output "set breakpoint pending off"
490 gdb_test "break 999" \
491 "No line 999 in the current file." \
492 "break on non-existent source line"
495 test_break_nonexistent_line
497 proc_with_prefix test_break_default {} {
504 # Run to the desired default location. If not positioned here, the
505 # tests below don't work.
507 gdb_test "until $::bp_location1" "main .* at .*:$::bp_location1.*" \
510 # Verify that GDB allows one to just say "break", which is treated
511 # as the "default" breakpoint. Note that GDB gets cute when printing
512 # the informational message about other breakpoints at the same
513 # location. We'll hit that bird with this stone too.
515 gdb_test "break" "Breakpoint \[0-9\]*.*" \
516 "break on default location, 1st time"
519 "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
520 "break on default location, 2nd time"
523 "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
524 "break on default location, 3rd time"
527 "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
528 "break on default location, 4th time"
530 # Check setting a breakpoint at the default location with a condition attached.
531 gdb_test "break if (1)" \
532 "Note: breakpoints \[0-9\]*, \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
533 "break on the default location, 5th time, but with a condition"
538 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
539 # "silent" about its triggering.
541 proc_with_prefix test_break_silent_and_more {} {
548 gdb_test_multiple "break $::bp_location1" \
549 "set to-be-silent break bp_location1" {
550 -re "Breakpoint (\[0-9\]*) at .*, line $::bp_location1.*$::gdb_prompt $" {
551 set bpno $expect_out(1,string)
552 pass "set to-be-silent break bp_location1"
556 gdb_test "commands $bpno\nsilent\nend" ">end" "set silent break bp_location1"
558 gdb_test "info break $bpno" \
559 "\[0-9\]*\[ \t\]*breakpoint.*:$::bp_location1\r\n\[ \t\]*silent.*" \
560 "info silent break bp_location1"
562 gdb_test "continue" "Continuing." \
563 "hit silent break bp_location1"
565 gdb_test "bt" "#0 main .* at .*:$::bp_location1.*" \
566 "stopped for silent break bp_location1"
568 # Verify the $_hit_bpnum convenience variable is set to the silent hit bpno.
569 gdb_test "printf \"%d\\n\", \$_hit_bpnum" "$bpno" \
570 "Silent breakpoint hit \$_hit_bpnum is silent $bpno"
572 # Verify that GDB can at least parse a breakpoint with the
573 # "thread" keyword. (We won't attempt to test here that a
574 # thread-specific breakpoint really triggers appropriately.
575 # The gdb.threads subdirectory contains tests for that.)
577 set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
578 gdb_test "break $bp_location12 thread 999" "Unknown thread 999.*" \
579 "thread-specific breakpoint on non-existent thread disallowed"
581 gdb_test "break $bp_location12 thread foo" \
582 "Invalid thread ID: foo" \
583 "thread-specific breakpoint on bogus thread ID disallowed"
585 # Verify that GDB responds gracefully to a breakpoint command with
588 gdb_test "break $bp_location12 foo" \
589 "malformed linespec error: unexpected string, \"foo\".*" \
590 "breakpoint with trailing garbage disallowed"
592 # Verify that GDB responds gracefully to a "clear" command that has
593 # no matching breakpoint. (First, get us off the current source line,
594 # which we know has a breakpoint.)
596 gdb_test "next" "marker1.*" "step over breakpoint"
598 gdb_test "clear 81" "No breakpoint at 81.*" \
599 "clear line has no breakpoint disallowed"
601 gdb_test "clear" "No breakpoint at this line.*" \
602 "clear current line has no breakpoint disallowed"
604 # Verify that we can set and clear multiple breakpoints.
606 # We don't test that it deletes the correct breakpoints. We do at
607 # least test that it deletes more than one breakpoint.
609 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
610 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
611 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
614 test_break_silent_and_more
616 # Verify that a breakpoint can be set via a convenience variable.
618 proc_with_prefix test_break_line_convenience_var {} {
621 if { ![runto_main] } {
625 gdb_test_no_output "set \$foo=$::bp_location11" \
626 "set convenience variable \$foo to bp_location11"
628 gdb_test "break \$foo" \
629 "Breakpoint (\[0-9\]*) at .*, line $::bp_location11.*"
631 # Verify that GDB responds gracefully to an attempt to set a
632 # breakpoint via a convenience variable whose type is not integer.
634 gdb_test_no_output "set \$foo=81.5" \
635 "set convenience variable \$foo to 81.5"
637 gdb_test "break \$foo" \
638 "Convenience variables used in line specs must have integer values.*" \
639 "non-integer convenience variable disallowed"
642 test_break_line_convenience_var
644 # Verify that we can set and trigger a breakpoint in a user-called function.
646 proc_with_prefix test_break_user_call {} {
649 if { ![runto_main] } {
653 gdb_test "break marker2" \
654 "Breakpoint (\[0-9\]*) at .*, line $::bp_location8.*" \
655 "set breakpoint on to-be-called function"
657 gdb_test "print marker2(99)" \
658 "The program being debugged stopped while in a function called from GDB.\r\nEvaluation of the expression containing the function\r\n.[func marker2]. will be abandoned.\r\nWhen the function is done executing, GDB will silently stop.*" \
659 "hit breakpoint on called function"
661 # As long as we're stopped (breakpointed) in a called function,
662 # verify that we can successfully backtrace & such from here.
664 "#0\[ \t\]*($::hex in )?marker2.*:$::bp_location8\r\n#1\[ \t\]*<function called from gdb>.*" \
665 "backtrace while in called function"
667 # Return from the called function. For remote targets, it's important to do
668 # this before runto_main, which otherwise may silently stop on the dummy
669 # breakpoint inserted by GDB at the program's entry point.
671 gdb_test_multiple "finish" "finish from called function" {
672 -re "Run till exit from .*marker2.* at .*$::bp_location8\r\n.*function called from gdb.*$::gdb_prompt $" {
673 pass "finish from called function"
675 -re "Run till exit from .*marker2.* at .*$::bp_location8\r\n.*Value returned.*$::gdb_prompt $" {
676 pass "finish from called function"
683 # Verify that GDB responds gracefully to a "finish" command with
686 proc_with_prefix test_finish_arguments {} {
693 send_gdb "finish 123\n"
695 -re "The \"finish\" command does not take any arguments.\r\n$::gdb_prompt $"\
696 {pass "finish with arguments disallowed"}
697 -re "$::gdb_prompt $"\
698 {fail "finish with arguments disallowed"}
699 timeout {fail "(timeout) finish with arguments disallowed"}
702 # Verify that GDB responds gracefully to a request to "finish" from
703 # the outermost frame. On a stub that never exits, this will just
704 # run to the stubs routine, so we don't get this error... Thus the
708 gdb_test_multiple "finish" "finish from outermost frame disallowed" {
709 -re "\"finish\" not meaningful in the outermost frame.\r\n$::gdb_prompt $" {
710 pass "finish from outermost frame disallowed"
712 -re "Run till exit from.*\r\n$::gdb_prompt $" {
713 pass "finish from outermost frame disallowed"
718 test_finish_arguments
724 # Test "next" over recursive function call.
727 proc_with_prefix test_next_with_recursion {} {
732 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
735 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
737 # Run until we call factorial with 6
740 gdb_test "" "Break.* factorial .value=6. .*" "run to factorial(6)"
742 # Continue until we call factorial recursively with 5.
744 gdb_test "continue" \
745 "Continuing.*Break.* factorial .value=5. .*" \
746 "continue to factorial(5)"
748 # Do a backtrace just to confirm how many levels deep we are.
750 gdb_test "backtrace" \
751 "#0\[ \t\]+ factorial .value=5..*" \
752 "backtrace from factorial(5)"
754 # Now a "next" should position us at the recursive call, which
755 # we will be performing with 4.
758 ".* factorial .value - 1.;.*" \
759 "next to recursive call"
761 # Disable the breakpoint at the entry to factorial by deleting them all.
762 # The "next" should run until we return to the next line from this
763 # recursive call to factorial with 4.
764 # Buggy versions of gdb will stop instead at the innermost frame on
765 # the line where we are trying to "next" to.
769 if [istarget "mips*tx39-*"] {
772 # We used to set timeout here for all other targets as well. This
773 # is almost certainly wrong. The proper timeout depends on the
774 # target system in use, and how we communicate with it, so there
775 # is no single value appropriate for all targets. The timeout
776 # should be established by the Dejagnu config file(s) for the
777 # board, and respected by the test suite.
779 # For example, if I'm running GDB over an SSH tunnel talking to a
780 # portmaster in California talking to an ancient 68k board running
781 # a crummy ROM monitor (a situation I can only wish were
782 # hypothetical), then I need a large timeout. But that's not the
783 # kind of knowledge that belongs in this file.
785 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
786 "next over recursive call"
788 # OK, we should be back in the same stack frame we started from.
789 # Do a backtrace just to confirm.
791 gdb_test "backtrace" \
792 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
793 "backtrace from factorial(5.1)"
795 if { ![target_info exists gdb,noresults] } {
796 gdb_continue_to_end "recursive next test"
800 test_next_with_recursion
805 # build a new file with optimization enabled so that we can try breakpoints
806 # on targets with optimized prologues
808 if { [build_executable "failed to prepare" "breako2" {break.c break1.c} {debug nowarnings optimize=-O2}] } {
812 proc_with_prefix test_break_optimized_prologue {} {
813 clean_restart breako2
815 # test break at function
816 gdb_test "break -q main" \
817 "Breakpoint.*at.* file .*, line.*" \
818 "breakpoint function, optimized file"
820 # test break at function
821 gdb_test "break marker4" \
822 "Breakpoint.*at.* file .*$::srcfile1, line.*" \
823 "breakpoint small function, optimized file"
825 # run until the breakpoint at main is hit. For non-stubs-using targets.
828 set test "run until function breakpoint, optimized file"
829 gdb_test_multiple "" $test {
830 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$::srcfile:$::bp_location6.*$::bp_location6\[\t \]+if .argc.* \{.*$::gdb_prompt $" {
833 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$::gdb_prompt $" {
834 pass "$test (code motion)"
838 # run until the breakpoint at a small function
840 # Add a second pass pattern. The behavior differs here between stabs
841 # and dwarf for one-line functions. Stabs preserves two line symbols
842 # (one before the prologue and one after) with the same line number,
843 # but dwarf regards these as duplicates and discards one of them.
844 # Therefore the address after the prologue (where the breakpoint is)
845 # has no exactly matching line symbol, and GDB reports the breakpoint
846 # as if it were in the middle of a line rather than at the beginning.
848 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $::srcfile1]
850 gdb_test_multiple "continue" \
851 "run until breakpoint set at small function, optimized file" {
852 -re "Breakpoint $::decimal, marker4 \\(d=(d@entry=)?177601976\\) at .*$::srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
853 pass "run until breakpoint set at small function, optimized file (line bp_location14)"
855 -re "Breakpoint $::decimal, factorial \\(.*\\) .*\{\r\n$::gdb_prompt" {
856 # GCC 4.3 emits bad line number information - see gcc/36748.
857 if { [test_compiler_info "gcc-4-3-*"] } {
860 fail "run until breakpoint set at small function, optimized file"
865 test_break_optimized_prologue
867 # test that 'rbreak' on a symbol that may be from a shared library doesn't
868 # cause a "Junk at end of arguments." error.
870 # On x86 GNU/Linux, this test will choke on e.g. __libc_start_main@plt.
872 # Note that this test won't necessarily choke on all targets even if
873 # all the rbreak issue is present. rbreak needs to match and set a
874 # breakpoint on a symbol causes 'break' to choke.
876 proc_with_prefix test_rbreak_shlib {} {
877 clean_restart breako2
879 gdb_test_no_output "set breakpoint pending on" "rbreak junk pending setup"
881 # We expect at least one breakpoint to be set when we "rbreak main".
882 gdb_test "rbreak main" \
883 ".*Breakpoint.*at.* file .*$::srcfile, line.*"
885 # Run to a breakpoint. Fail if we see "Junk at end of arguments".
888 gdb_test_multiple "" "rbreak junk" {
889 -re -wrap "Junk at end of arguments.*" {
892 -re -wrap ".*Breakpoint \[0-9\]+,.*" {
900 # Test break via convenience variable with file name
902 proc_with_prefix test_break_file_line_convenience_var {} {
903 clean_restart breako2
905 set line [gdb_get_line_number "set breakpoint 1 here"]
906 gdb_test_no_output "set \$l = $line"
909 set test "break $::srcfile:\$l"
910 gdb_test_multiple "$test" $test {
911 -re "Breakpoint $::decimal at $::hex: file .*break\\.c, line ($::decimal)\\.\r\n$::gdb_prompt $" {
912 # Save the actual line number on which the breakpoint was
913 # actually set. On some systems (Eg: Ubuntu 16.04 with GCC
914 # version 5.4.0), that line gets completely inlined, including
915 # the call to printf, and so we end up inserting the breakpoint
916 # on one of the following lines instead.
917 set line_actual $expect_out(1,string)
922 gdb_test_no_output "set \$foo=81.5" \
923 "set convenience variable \$foo to 81.5"
924 gdb_test "break $::srcfile:\$foo" \
925 "Convenience variables used in line specs must have integer values.*" \
926 "non-integer convenience variable disallowed"
929 test_break_file_line_convenience_var
931 # Test that commands can be cleared without error.
933 proc_with_prefix test_break_commands_clear {} {
934 clean_restart breako2
936 set line [gdb_get_line_number "set breakpoint 1 here"]
939 gdb_test "commands\nprint 232323\nend" ">end" "set some breakpoint commands"
940 gdb_test "commands\nend" ">end" "clear breakpoint commands"
942 # We verify that the commands were cleared by ensuring that the last
943 # breakpoint's location ends the output -- if there were commands,
944 # they would have been printed after the location.
945 gdb_test "info break" "$::srcfile:$::decimal" "verify that they were cleared"
948 test_break_commands_clear