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 # Based on break.exp by Rob Savoye. (rob@cygnus.com)
17 # Hardware breakpoint support by Maciej W. Rozycki and Daniel Jacobowitz.
18 # Only one hardware breakpoint is set at a time as targets may limit
19 # the number available.
22 if { [prepare_for_testing hbreak2.exp "hbreak2" {break.c break1.c} {debug nowarnings}] } {
28 if ![runto_main] then { fail "break tests suppressed" }
32 # Test whether the target supports hardware breakpoints at all.
34 gdb_test_multiple "hbreak main" "hardware breakpoint support" {
35 -re "No hardware breakpoint support in the target.*$gdb_prompt $" {
36 unsupported "hardware breakpoints"
39 -re "Hardware breakpoints used exceeds limit.*$gdb_prompt $" {
40 unsupported "hardware breakpoints"
43 -re "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*$gdb_prompt $" {
44 pass "hardware breakpoint support"
48 gdb_test_multiple "" "hardware breakpoint insertion" {
49 -re "Warning:\[\r\n\]+Cannot insert hardware breakpoint \[0-9\]+\.\[\r\n\]+Could not insert hardware breakpoints:\[\r\n\]+You may have requested too many hardware breakpoints/watchpoints\.\[\r\n\]+.*$gdb_prompt $" {
50 unsupported "hardware breakpoint insertion"
53 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:.*\[\r\n\]+.*\[\t \]+if .argc.* \{.*$gdb_prompt $" {
54 pass "hardware breakpoint insertion"
60 # Test simple hardware breakpoint setting commands.
64 # Test break at function.
66 gdb_test "hbreak main" \
67 "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*" \
68 "hardware breakpoint function"
72 # Test break at quoted function.
74 gdb_test "hbreak \"marker2\"" \
75 "Hardware assisted breakpoint.*at.* file .*$srcfile1, line.*" \
76 "hardware breakpoint quoted function"
80 # Test break at function in file.
82 gdb_test "hbreak $srcfile:factorial" \
83 "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*" \
84 "hardware breakpoint function in file"
87 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
90 # Test break at line number.
92 # Note that the default source file is the last one whose source text
93 # was printed. For native debugging, before we've executed the
94 # program, this is the file containing main, but for remote debugging,
95 # it's wherever the processor was stopped when we connected to the
96 # board. So, to be sure, we do a list command.
98 gdb_test "list main" \
99 ".*main \\(argc, argv, envp\\).*" \
100 "use `list' to establish default source file"
101 gdb_test "hbreak $bp_location1" \
102 "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
103 "hardware breakpoint line number"
106 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
109 # Test break at line number in file.
111 gdb_test "hbreak $srcfile:$bp_location2" \
112 "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
113 "hardware breakpoint line number in file"
116 set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
117 set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
120 # Test putting a break at the start of a multi-line if conditional.
121 # Verify the breakpoint was put at the start of the conditional.
123 gdb_test "hbreak multi_line_if_conditional" \
124 "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
125 "hardware breakpoint at start of multi line if conditional"
128 gdb_test "hbreak multi_line_while_conditional" \
129 "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
130 "hardware breakpoint at start of multi line while conditional"
132 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
134 set main_line $bp_location6
136 if {$hp_aCC_compiler} {
137 set proto "\\(int\\)"
142 set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
143 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
144 set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
146 gdb_test "info break" \
147 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
148 \[0-9\]+\[\t \]+hw breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
149 "hardware breakpoint info"
153 # Run until the breakpoint at main is hit. For non-stubs-using targets.
155 gdb_test "hbreak main" \
156 "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*" \
157 "hardware breakpoint function (2)"
160 "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*" \
161 "run until function breakpoint"
165 # Run until the breakpoint at a line number.
167 gdb_test "hbreak $bp_location1" \
168 "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
169 "hardware breakpoint line number (2)"
170 gdb_test "continue" \
171 "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
172 "run until breakpoint set at a line number"
176 # Run until the breakpoint set in a function in a file.
178 gdb_test "hbreak $srcfile:factorial" \
179 "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*" \
180 "hardware breakpoint function in file (2)"
181 for {set i 6} {$i >= 1} {incr i -1} {
182 gdb_test "continue" \
183 "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
184 "run until file:function($i) breakpoint"
189 # Run until the breakpoint set at a quoted function.
191 gdb_test "hbreak \"marker2\"" \
192 "Hardware assisted breakpoint.*at.* file .*$srcfile1, line.*" \
193 "hardware breakpoint quoted function (2)"
194 gdb_test "continue" \
195 "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*" \
196 "run until quoted breakpoint"
199 # Run until the file:function breakpoint at a line number in a file.
201 gdb_test "hbreak $srcfile:$bp_location2" \
202 "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
203 "hardware breakpoint line number in file (2)"
204 gdb_test "continue" \
205 "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
206 "run until file:linenum breakpoint"
209 # Test break at offset +1.
210 set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
212 gdb_test "hbreak +1" \
213 "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
214 "hardware breakpoint offset +1"
216 # Check to see if breakpoint is hit when stepped onto.
219 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
220 "step onto hardware breakpoint"
223 # Check to see if breakpoint can be set on ending brace of function.
224 set bp_location10a [gdb_get_line_number "set breakpoint 10a here"]
226 gdb_test "hbreak $bp_location10a" \
227 "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location10a\\." \
228 "setting hardware breakpoint at }"
230 gdb_test "continue" \
231 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10a.*$bp_location10a\[\t \]+}.*breakpoint 10a here.*" \
232 "continue to hardware breakpoint at }"
235 # Delete all breakpoints so we can start over, course this can be a test too.
240 # Test temporary breakpoint at function.
243 gdb_test "thbreak main" \
244 "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*" \
245 "temporary hardware breakpoint function"
249 # Test break at function in file.
252 gdb_test "thbreak $srcfile:factorial" \
253 "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*" \
254 "temporary hardware breakpoint function in file"
258 # Test break at line number.
260 gdb_test "thbreak $bp_location1" \
261 "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location1.*" \
262 "temporary hardware breakpoint line number #1"
265 gdb_test "thbreak $bp_location6" \
266 "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location6.*" \
267 "temporary hardware breakpoint line number #2"
271 # Test break at line number in file.
273 gdb_test "thbreak $srcfile:$bp_location2" \
274 "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location2.*" \
275 "temporary hardware breakpoint line number in file #1"
278 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
279 gdb_test "thbreak $srcfile:$bp_location11" \
280 "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location11.*" \
281 "temporary hardware breakpoint line number in file #2"
284 # Check to see what breakpoints are set (temporary this time).
286 gdb_test "info break" \
287 "Num Type.*Disp Enb Address.*What.*\[\r\n\]
288 \[0-9\]+\[\t \]+hw breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
289 "temporary hardware breakpoint info"
294 if ![runto_main] then { fail "break tests suppressed" }
296 # Verify that GDB responds gracefully when asked to set a breakpoint
297 # on a nonexistent source line.
299 gdb_test_no_output "set breakpoint pending off"
300 gdb_test "hbreak 999" \
301 "No line 999 in the current file." \
302 "hardware break on non-existent source line"
304 # Run to the desired default location. If not positioned here, the
305 # tests below don't work.
307 gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" \
311 # Verify that GDB allows one to just say "hbreak", which is treated
312 # as the "default" breakpoint.
314 gdb_test "hbreak" "Hardware assisted breakpoint \[0-9\]*.*" \
315 "hardware break on default location"
317 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
318 # "silent" about its triggering.
320 if ![runto_main] then { fail "break tests suppressed" }
322 gdb_test_multiple "hbreak $bp_location1" \
323 "set to-be-silent hardware break bp_location1" {
324 -re "Hardware assisted breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $" {
325 pass "set to-be-silent hardware break bp_location1"
329 gdb_test "commands $expect_out(1,string)\nsilent\nend" ">end" "set silent break bp_location1"
331 gdb_test "info break $expect_out(1,string)" \
332 "\[0-9\]*\[ \t\]*hw breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*" \
333 "info silent hardware break bp_location1"
335 gdb_test "continue" "Continuing." \
336 "hit silent hardware break bp_location1"
338 gdb_test "bt" "#0 main .* at .*:$bp_location1.*" \
339 "stopped for silent hardware break bp_location1"
341 # Verify that GDB can at least parse a breakpoint with the
342 # "thread" keyword. (We won't attempt to test here that a
343 # thread-specific breakpoint really triggers appropriately.
344 # The gdb.threads subdirectory contains tests for that.)
346 set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
347 gdb_test "hbreak $bp_location12 thread 999" "Unknown thread 999.*" \
348 "thread-specific hardware breakpoint on non-existent thread disallowed"
350 gdb_test "hbreak $bp_location12 thread foo" \
351 "Junk after thread keyword.*" \
352 "thread-specific hardware breakpoint on bogus thread ID disallowed"
354 # Verify that GDB responds gracefully to a breakpoint command with
357 gdb_test "hbreak $bp_location12 foo" \
358 "malformed linespec error: unexpected string, \"foo\".*" \
359 "hardware breakpoint with trailing garbage disallowed"
361 # Verify that GDB responds gracefully to a "clear" command that has
362 # no matching breakpoint. (First, get us off the current source line,
363 # which we know has a breakpoint.)
365 gdb_test "next" "marker1.*" "step over hardware breakpoint"
367 gdb_test "clear 81" "No breakpoint at 81.*" \
368 "clear line has no breakpoint disallowed"
370 gdb_test "clear" "No breakpoint at this line.*" \
371 "clear current line has no breakpoint disallowed"
374 # Verify that a breakpoint can be set via a convenience variable.
376 gdb_test_no_output "set \$foo=$bp_location11" \
377 "set convenience variable \$foo to bp_location11"
379 gdb_test "hbreak \$foo" \
380 "Hardware assisted breakpoint (\[0-9\]*) at .*, line $bp_location11.*" \
381 "set hardware breakpoint via convenience variable"
384 # Verify that GDB responds gracefully to an attempt to set a
385 # breakpoint via a convenience variable whose type is not integer.
387 gdb_test_no_output "set \$foo=81.5" \
388 "set convenience variable \$foo to 81.5"
390 gdb_test "hbreak \$foo" \
391 "Convenience variables used in line specs must have integer values.*" \
392 "set hardware breakpoint via non-integer convenience variable disallowed"
394 # Verify that we can set and trigger a breakpoint in a user-called function.
396 gdb_test "hbreak marker2" \
397 "Hardware assisted breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*" \
398 "set hardware breakpoint on to-be-called function"
400 gdb_test "print marker2(99)" \
401 "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.*" \
402 "hit hardware breakpoint on called function"
404 # As long as we're stopped (breakpointed) in a called function,
405 # verify that we can successfully backtrace & such from here.
407 # In this and the following test, the _sr4export check apparently is needed
410 gdb_test_multiple "bt" "backtrace while in called function" {
411 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $" {
412 pass "backtrace while in called function"
414 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $" {
415 pass "backtrace while in called function"
419 # Return from the called function. For remote targets, it's important to do
420 # this before runto_main, which otherwise may silently stop on the dummy
421 # breakpoint inserted by GDB at the program's entry point.
423 gdb_test_multiple "finish" "finish from called function" {
424 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $" {
425 pass "finish from called function"
427 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $" {
428 pass "finish from called function"
430 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $" {
431 pass "finish from called function"
439 # Test "next" over recursive function call.
442 proc test_next_with_recursion {} {
449 # Can't set a hardware breakpoint without a live target, so do it now
450 # before it's killed below.
451 gdb_test "hbreak factorial" \
452 "Hardware assisted breakpoint $decimal at .*" \
453 "hardware break at factorial"
455 gdb_test "kill" "" "kill program" \
456 "Kill the program being debugged.*y or n. $" "y"
458 # Run until we call factorial with 6
462 "Break.* factorial .value=6. .*" \
463 "run to factorial(6)"] then { gdb_suppress_tests }
465 # Continue until we call factorial recursively with 5.
467 if [gdb_test "continue" \
468 "Continuing.*Break.* factorial .value=5. .*" \
469 "continue to factorial(5)"] then { gdb_suppress_tests }
471 # Do a backtrace just to confirm how many levels deep we are.
473 if [gdb_test "backtrace" \
474 "#0\[ \t\]+ factorial .value=5..*" \
475 "backtrace from factorial(5)"] then { gdb_suppress_tests }
477 # Now a "next" should position us at the recursive call, which
478 # we will be performing with 4.
480 if [gdb_test "next" \
481 ".* factorial .value - 1.;.*" \
482 "next to recursive call"] then { gdb_suppress_tests }
484 # Disable the breakpoint at the entry to factorial by deleting them all.
485 # The "next" should run until we return to the next line from this
486 # recursive call to factorial with 4.
487 # Buggy versions of gdb will stop instead at the innermost frame on
488 # the line where we are trying to "next" to.
492 if [istarget "mips*tx39-*"] {
495 # We used to set timeout here for all other targets as well. This
496 # is almost certainly wrong. The proper timeout depends on the
497 # target system in use, and how we communicate with it, so there
498 # is no single value appropriate for all targets. The timeout
499 # should be established by the Dejagnu config file(s) for the
500 # board, and respected by the test suite.
502 # For example, if I'm running GDB over an SSH tunnel talking to a
503 # portmaster in California talking to an ancient 68k board running
504 # a crummy ROM monitor (a situation I can only wish were
505 # hypothetical), then I need a large timeout. But that's not the
506 # kind of knowledge that belongs in this file.
508 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
509 "next over recursive call"
511 # OK, we should be back in the same stack frame we started from.
512 # Do a backtrace just to confirm.
514 set result [gdb_test "backtrace" \
515 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
516 "backtrace from factorial(5.1)"]
517 if { $result != 0 } { gdb_suppress_tests }
519 if [target_info exists gdb,noresults] { gdb_suppress_tests }
520 gdb_continue_to_end "recursive next test"
521 gdb_stop_suppressing_tests
524 test_next_with_recursion
529 # Build a new file with optimization enabled so that we can try breakpoints
530 # on targets with optimized prologues.
532 if { [prepare_for_testing hbreak2.exp "hbreak2o2" {break.c break1.c} {debug nowarnings optimize=-O2}] } {
536 if ![runto_main] then { fail "break tests suppressed" }
540 # Test break at function.
542 gdb_test "hbreak main" \
543 "Hardware assisted breakpoint.*at.* file .*, line.*" \
544 "hardware breakpoint function, optimized file"
547 # Run until the breakpoint at main is hit. For non-stubs-using targets.
550 gdb_test_multiple "" "run until hardware function breakpoint, optimized file" {
551 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
552 pass "run until hardware function breakpoint, optimized file"
554 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $" {
555 pass "run until hardware function breakpoint, optimized file (code motion)"
561 # Test break at function.
563 gdb_test "hbreak marker4" \
564 "Hardware assisted breakpoint.*at.* file .*$srcfile1, line.*" \
565 "hardware breakpoint small function, optimized file"
568 # Run until the breakpoint at a small function.
572 # Add a second pass pattern. The behavior differs here between stabs
573 # and dwarf for one-line functions. Stabs preserves two line symbols
574 # (one before the prologue and one after) with the same line number,
575 # but dwarf regards these as duplicates and discards one of them.
576 # Therefore the address after the prologue (where the breakpoint is)
577 # has no exactly matching line symbol, and GDB reports the breakpoint
578 # as if it were in the middle of a line rather than at the beginning.
580 set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
581 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
583 gdb_test_multiple "continue" \
584 "run until hardware breakpoint set at small function, optimized file" {
585 -re "Breakpoint $decimal, marker4 \\(d=(d@entry=)?177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
586 pass "run until hardware breakpoint set at small function, optimized file"
588 -re "Breakpoint $decimal, $hex in marker4 \\(d=(d@entry=)?177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
589 pass "run until hardware breakpoint set at small function, optimized file"
591 -re "Breakpoint $decimal, marker4 \\(d=(d@entry=)?177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
592 # marker4() is defined at line 46 when compiled with -DPROTOTYPES
593 pass "run until hardware breakpoint set at small function, optimized file (line bp_location14)"
595 -re "Breakpoint $decimal, factorial \\(.*\\) .*\{\r\n$gdb_prompt" {
596 # GCC 4.3 emits bad line number information - see gcc/36748.
597 if { [test_compiler_info "gcc-4-3-*"] } {
600 fail "run until hardware breakpoint set at small function, optimized file"