1 # Copyright 1992-2013 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/>.
19 set testfile "watchpoint"
20 set srcfile ${testfile}.c
21 set binfile ${objdir}/${subdir}/${testfile}
23 if [get_compiler_info] {
27 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
28 untested watchpoint.exp
32 # True if we're forcing no hardware watchpoints.
35 # Prepare for watchpoint tests by setting up two breakpoints and one
38 # We use breakpoints at marker functions to get past all the startup code,
39 # so we can get to the watchpoints in a reasonable amount of time from a
40 # known starting point.
42 # For simplicity, so we always know how to reference specific breakpoints or
43 # watchpoints by number, we expect a particular ordering and numbering of
44 # each in the combined breakpoint/watchpoint table, as follows:
47 # 1 Breakpoint marker1()
48 # 2 Breakpoint marker2()
57 if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] {
62 if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] {
67 if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] {
71 gdb_test "watch ival3" ".*\[Ww\]atchpoint 3: ival3.*" "set watchpoint on ival3"
73 if [gdb_test "info watch" "3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] {
78 # After installing the watchpoint, we disable it until we are ready
79 # to use it. This allows the test program to run at full speed until
80 # we get to the first marker function.
82 if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] {
91 # Test simple watchpoint.
94 proc test_simple_watchpoint {} {
99 # Ensure that the watchpoint is disabled when we startup.
101 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] {
105 # Run until we get to the first marker function.
109 set test "run to marker1 in test_simple_watchpoint"
110 set retcode [gdb_test_multiple "" $test {
111 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
116 if { $retcode != 0 } {
120 # After reaching the marker function, enable the watchpoint.
122 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] {
127 gdb_test "break func1" "Breakpoint.*at.*"
128 gdb_test_no_output "set \$func1_breakpoint_number = \$bpnum"
130 gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, func1.*" \
131 "continue to breakpoint at func1"
133 # Continue until the first change, from -1 to 0
135 set test "watchpoint hit, first time"
136 gdb_test_multiple "cont" $test {
137 -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
140 -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
141 setup_xfail "m68*-*-*" 2597
142 fail "thought it hit breakpoint at func1 twice"
143 gdb_test_no_output "delete \$func1_breakpoint_number"
144 gdb_test "continue" "\
145 Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
150 # Check that the hit count is reported correctly
151 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 1 time.*" "Watchpoint hit count is 1"
153 gdb_test_no_output "delete \$func1_breakpoint_number"
155 # Continue until the next change, from 0 to 1.
156 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time"
158 # Check that the hit count is reported correctly
159 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 2 times.*" "Watchpoint hit count is 2"
161 # Continue until the next change, from 1 to 2.
162 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time"
164 # Check that the hit count is reported correctly
165 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 3 times.*" "Watchpoint hit count is 3"
167 # Continue until the next change, from 2 to 3.
168 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time"
170 # Check that the hit count is reported correctly
171 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 4 times.*" "Watchpoint hit count is 4"
173 # Continue until the next change, from 3 to 4.
174 # Note that this one is outside the loop.
176 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time"
178 # Check that the hit count is reported correctly
179 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 5 times.*" "Watchpoint hit count is 5"
181 # Continue until we hit the finishing marker function.
182 # Make sure we hit no more watchpoints.
184 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \(\).*" \
185 "continue to marker2"
187 # Disable the watchpoint so we run at full speed until we exit.
189 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] {
194 # Run until process exits.
196 if [target_info exists gdb,noresults] { return }
198 gdb_continue_to_end "continue to exit in test_simple_watchpoint"
201 # Test disabling watchpoints.
203 proc test_disabling_watchpoints {} {
210 gdb_test "info watch" "\[0-9]+\[ \]*.*watchpoint.*ival3.*" "watchpoints found in watchpoint/breakpoint table"
212 # Ensure that the watchpoint is disabled when we startup.
214 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] {
219 # Run until we get to the first marker function.
223 set test "run to marker1 in test_disabling_watchpoints"
224 set retcode [gdb_test_multiple "" $test {
225 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
230 if { $retcode != 0 } {
234 # After reaching the marker function, enable the watchpoint.
236 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] {
241 # Continue until the first change, from -1 to 0
242 # Don't check the old value, because on VxWorks the variable value
243 # will not have been reinitialized.
244 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, first time"
246 # Continue until the next change, from 0 to 1.
247 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, second time"
249 # Disable the watchpoint but leave breakpoints
251 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] {
256 # Check watchpoint list, looking for the entry that confirms the
257 # watchpoint is disabled.
258 gdb_test "info watchpoints" "\[0-9]+\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
260 # Continue until we hit the finishing marker function.
261 # Make sure we hit no more watchpoints.
262 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \
263 "disabled watchpoint skipped"
265 if [target_info exists gdb,noresults] { return }
267 gdb_continue_to_end "continue to exit in test_disabling_watchpoints"
270 # Test stepping and other mundane operations with watchpoints enabled
271 proc test_stepping {} {
274 if [runto marker1] then {
275 gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
277 # Well, let's not be too mundane. It should be a *bit* of a challenge
278 gdb_test "break func2 if 0" "Breakpoint.*at.*"
279 gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*"
281 gdb_test "p func1 ()" "= 73" \
282 "calling function with watchpoint enabled"
285 # "finish" brings us back to main.
286 # On some targets (e.g. alpha) gdb will stop from the finish in midline
287 # of the marker1 call. This is due to register restoring code on
288 # the alpha and might be caused by stack adjustment instructions
289 # on other targets. In this case we will step once more.
294 -re "Run.*exit from.*marker1.* at" {
295 pass "finish from marker1"
297 default { fail "finish from marker1 (timeout)" ; return }
301 -re "marker1 \\(\\);.*$gdb_prompt $" {
305 -re "func1 \\(\\);.*$gdb_prompt $" {
306 pass "back at main from marker1"
308 -re ".*$gdb_prompt $" {
309 fail "back at main from marker1"
311 default { fail "back at main from marker1 (timeout)" ; return }
314 gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp"
316 # Now test that "until" works. It's a bit tricky to test
317 # "until", because compilers don't always arrange the code
318 # exactly the same way, and we might get slightly different
319 # sequences of statements. But the following should be true
320 # (if not it is a compiler or a debugger bug): The user who
321 # does "until" at every statement of a loop should end up
322 # stepping through the loop once, and the debugger should not
323 # stop for any of the remaining iterations.
325 gdb_test "until" "ival1 = count.*" "until to ival1 assignment"
326 gdb_test "until" "ival3 = count.*" "until to ival3 assignment"
327 set test "until out of loop"
328 gdb_test_multiple "until" $test {
329 -re "(for \\(count = 0|\}).*$gdb_prompt $" {
330 gdb_test "until" "ival1 = count; /. Outside loop ./" $test
332 -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
337 gdb_test "step" "ival2 = count.*" "step to ival2 assignment"
341 # Test stepping and other mundane operations with watchpoints enabled
342 proc test_watchpoint_triggered_in_syscall {} {
345 # These tests won't work without printf support.
346 if [gdb_skip_stdio_test "watchpoints triggered in syscall"] {
349 # Run until we get to the first marker function.
352 set testname "Watch buffer passed to read syscall"
353 if [runto marker2] then {
354 gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]"
355 gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]"
356 gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]"
357 gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]"
358 gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]"
359 gdb_test "break marker4" ".*Breakpoint.*"
361 gdb_test_no_output "set doread = 1"
363 # If we send gdb "123\n" before gdb has switched the tty, then it goes
364 # to gdb, not the inferior, and we lose. So that is why we have
365 # watchpoint.c prompt us, so we can wait for that prompt.
367 send_gdb "continue\n";
369 -re "Continuing\\.\r\ntype stuff for buf now:" {
370 pass "continue to read"
373 fail "continue to read";
379 gdb_test_multiple "123" $test {
380 -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
381 -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
382 -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
383 -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
384 -re ".*$gdb_prompt $" { pass $test }
387 # Examine the values in buf to see how many watchpoints we
388 # should have printed.
389 set test "print buf\[0\]"
390 gdb_test_multiple $test $test {
391 -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass $test }
392 -re ".*= 0.*$gdb_prompt $" { $test }
394 set test "print buf\[1\]"
395 gdb_test_multiple $test $test {
396 -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass $test }
397 -re ".*= 0.*$gdb_prompt $" { pass $test }
399 set test "print buf\[2\]"
400 gdb_test_multiple $test $test {
401 -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass $test }
402 -re ".*= 0.*$gdb_prompt $" { pass $test }
404 set test "print buf\[3\]"
405 gdb_test_multiple $test $test {
406 -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass $test }
407 -re ".*= 0.*$gdb_prompt $" { pass $test }
410 # Did we find what we were looking for? If not, flunk it.
411 if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"}
413 # Continue until we hit the finishing marker function.
414 # Make sure we hit no more watchpoints.
415 gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \
416 "continue to marker4"
418 # Disable everything so we can finish the program at full speed
419 gdb_test_no_output "disable" "disable in test_watchpoint_triggered_in_syscall"
421 if [target_info exists gdb,noresults] { return }
423 gdb_continue_to_end "continue to exit in test_watchpoint_triggered_in_syscall"
427 # Do a simple test of of watching through a pointer when the pointer
428 # itself changes. Should add some more complicated stuff here.
430 proc test_complex_watchpoint {} {
433 if [runto marker4] then {
434 gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
435 gdb_test "break marker5" ".*Breakpoint.*"
437 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "Test complex watchpoint"
439 # Continue until we hit the marker5 function.
440 # Make sure we hit no more watchpoints.
442 gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \
443 "did not trigger wrong watchpoint"
445 # Test watches of things declared locally in a function.
446 # In particular, test that a watch of stack-based things
447 # is deleted when the stack-based things go out of scope.
449 gdb_test_no_output "disable" "disable in test_complex_watchpoint"
450 gdb_test "break marker6" ".*Breakpoint.*"
451 gdb_test "cont" "Continuing.*Breakpoint.*marker6 \\(\\).*" \
452 "continue to marker6"
453 gdb_breakpoint [gdb_get_line_number "func2 breakpoint here"]
454 gdb_continue_to_breakpoint "func2 breakpoint here"
456 # Test a watch of a single stack-based variable, whose scope
457 # is the function we're now in. This should auto-delete when
458 # execution exits the scope of the watchpoint.
460 gdb_test "watch local_a" ".*\[Ww\]atchpoint \[0-9\]*: local_a" "set local watch"
461 gdb_test "cont" "\[Ww\]atchpoint.*local_a.*" "trigger local watch"
463 set test "self-delete local watch"
464 gdb_test_multiple "cont" $test {
465 -re "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*\r\n$gdb_prompt $" {
468 -re "can't compute CFA for this frame.*\r\n$gdb_prompt $" {
469 global compiler_info no_hw
471 # GCC < 4.5.0 does not get LOCATIONS_VALID set by dwarf2read.c.
472 # Therefore epilogue unwinder gets applied which is
473 # incompatible with dwarf2_frame_cfa.
474 verbose -log "compiler_info: $compiler_info"
475 if {$no_hw && ([test_compiler_info {gcc-[0-3]-*}]
476 || [test_compiler_info {gcc-4-[0-4]-*}])} {
477 xfail "$test (old GCC has broken watchpoints in epilogues)"
484 gdb_continue_to_breakpoint "func2 breakpoint here"
485 # We should be in "func2" again now. Test a watch of an
486 # expression which includes both a stack-based local and
487 # something whose scope is larger than this invocation
488 # of "func2". This should also auto-delete.
490 gdb_test "watch local_a + ival5" ".*\[Ww\]atchpoint \[0-9\]*: local_a . ival5" \
491 "set partially local watch"
492 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
493 "trigger1 partially local watch"
494 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
495 "trigger2 partially local watch"
496 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
497 "self-delete partially local watch"
499 # We should be in "func2" again now. Test a watch of a
500 # static (non-stack-based) local. Since this has scope
501 # across any invocations of "func2", it should not auto-
504 gdb_continue_to_breakpoint "func2 breakpoint here"
505 gdb_test "watch static_b" ".*\[Ww\]atchpoint \[0-9\]*: static_b" \
506 "set static local watch"
507 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: static_b.*" \
508 "trigger static local watch"
509 gdb_test "cont" "Continuing.*marker6 \\(\\).*" \
510 "continue after trigger static local watch"
511 gdb_test "info break" ".*watchpoint.*static_b.*" \
512 "static local watch did not self-delete"
514 # We should be in "recurser" now. Test a watch of a stack-
515 # based local. Symbols mentioned in a watchpoint are bound
516 # at watchpoint-creation. Thus, a watch of a stack-based
517 # local to a recursing function should be bound only to that
518 # one invocation, and should not trigger for other invocations.
520 gdb_test "tbreak recurser" ".*breakpoint.*"
521 gdb_test "cont" "Continuing.*recurser.*"
522 gdb_test "next" "if \\(x > 0.*" "next past local_x initialization"
523 gdb_test "watch local_x" ".*\[Ww\]atchpoint \[0-9\]*: local_x" \
524 "set local watch in recursive call"
525 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_x.*New value = 2.*" \
526 "trigger local watch in recursive call"
527 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
528 "self-delete local watch in recursive call"
530 # Repeat the preceding test, but this time use "recurser::local_x" as
531 # the variable to track.
532 gdb_test "cont" "Continuing.*marker6.*"
533 gdb_test "tbreak recurser" ".*breakpoint.*"
534 gdb_test "cont" "Continuing.*recurser.*"
535 gdb_test "next" "if \\(x > 0.*" "next past local_x initialization"
536 gdb_test "watch recurser::local_x" ".*\[Ww\]atchpoint \[0-9\]*: recurser::local_x" \
537 "set local watch in recursive call with explicit scope"
538 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: recurser::local_x.*New value = 2.*" \
539 "trigger local watch with explicit scope in recursive call"
540 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
541 "self-delete local watch with explicit scope in recursive call (2)"
543 # Disable everything so we can finish the program at full speed
544 gdb_test_no_output "disable" "disable in test_complex_watchpoint"
546 if [target_info exists gdb,noresults] { return }
548 gdb_continue_to_end "continue to exit in test_complex_watchpoint"
552 proc test_watchpoint_and_breakpoint {} {
555 # This is a test for PR gdb/38, which involves setting a
556 # watchpoint right after you've reached a breakpoint.
558 if [runto func3] then {
559 gdb_breakpoint [gdb_get_line_number "second x assignment"]
560 gdb_continue_to_breakpoint "second x assignment"
561 gdb_test "watch x" ".*atchpoint \[0-9\]+: x"
562 gdb_test_multiple "next" "next after watch x" {
563 -re ".*atchpoint \[0-9\]+: x\r\n\r\nOld value = 0\r\nNew value = 1\r\n.*$gdb_prompt $" {
564 pass "next after watch x"
566 -re "\[0-9\]+\[\t \]+y = 1;\r\n$gdb_prompt $" {
567 kfail "gdb/38" "next after watch x"
571 gdb_test_no_output "delete \$bpnum" "delete watch x"
575 proc test_constant_watchpoint {} {
576 gdb_test "watch 5" "Cannot watch constant value `5'." "number is constant"
577 gdb_test "watch (int *)5" "Cannot watch constant value `\\(int \\*\\)5'." \
578 "number with cast is constant"
579 gdb_test "watch marker1" "Cannot watch constant value `marker1'." \
580 "marker1 is constant"
581 gdb_test "watch count + 6" ".*atchpoint \[0-9\]+: count \\+ 6"
582 gdb_test_no_output "delete \$bpnum" "delete watchpoint `count + 6'"
583 gdb_test "watch 7 + count" ".*atchpoint \[0-9\]+: 7 \\+ count"
584 gdb_test_no_output "delete \$bpnum" "delete watchpoint `7 + count'"
587 proc test_disable_enable_software_watchpoint {} {
588 # This is regression test for a bug that caused `enable' to fail
589 # for software watchpoints.
591 # Watch something not memory to force a software watchpoint.
592 gdb_test {watch $pc} ".*atchpoint \[0-9\]+: .pc"
594 gdb_test_no_output "disable \$bpnum" "disable watchpoint `\$pc'"
595 gdb_test_no_output "enable \$bpnum" "reenable watchpoint `\$pc'"
597 gdb_test "info watchpoint \$bpnum" \
598 ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+.pc.*" \
599 "watchpoint `\$pc' is enabled"
601 gdb_test_no_output "delete \$bpnum" "delete watchpoint `\$pc'"
604 proc test_watch_location {} {
605 gdb_breakpoint [gdb_get_line_number "func5 breakpoint here"]
606 gdb_continue_to_breakpoint "func5 breakpoint here"
608 gdb_test "watch -location *x" "atchpoint .*: .*" "watch -location .x"
610 gdb_test "continue" \
611 "Continuing.*\[Ww\]atchpoint .*: .*New value = 27.*" \
612 "continue with watch -location"
614 gdb_test_no_output "delete \$bpnum" "delete watch -location"
617 # Tests watching areas larger than a word.
619 proc test_wide_location_1 {} {
623 # This test watches two words on most 32-bit ABIs, and one word on
626 # Platforms where the target can't watch such a large region
627 # should clear hw_expected below.
628 if { $no_hw || [target_info exists gdb,no_hardware_watchpoints]
629 || [istarget arm*-*-*]
630 || ([istarget powerpc*-*-*] && ![is_lp64_target])} {
636 gdb_breakpoint [gdb_get_line_number "func6 breakpoint here"]
637 gdb_continue_to_breakpoint "func6 breakpoint here"
639 if { $hw_expected } {
640 gdb_test "watch foo2" "Hardware watchpoint .*: .*" "watch foo2"
641 gdb_test "continue" \
642 "Continuing.*Hardware watchpoint .*: .*New value = \\\{val = \\\{0, 11\\\}\\\}.*" \
643 "continue with watch foo2"
645 gdb_test "watch foo2" "atchpoint .*: .*" "watch foo2"
646 set test "continue with watch foo2"
647 gdb_test_multiple "cont" $test {
648 -re "Continuing.*\[Ww\]atchpoint .*: .*New value = \\\{val = \\\{0, 11\\\}\\\}.*$gdb_prompt $" {
651 -re "Could not insert hardware breakpoints:.*You may have requested too many hardware breakpoints/watchpoints.*$gdb_prompt $" {
652 # This may happen with remote targets that support
653 # hardware watchpoints. We only find out the
654 # watchpoint was too large, for example, at insert
655 # time. If GDB is ever adjusted to downgrade the
656 # watchpoint automatically in this case, this match
663 gdb_test_no_output "delete \$bpnum" "delete watch foo2"
666 proc test_wide_location_2 {} {
670 # This test watches four words on most 32-bit ABIs, and two words
673 # Platforms where the target can't watch such a large region
674 # should clear hw_expected below.
675 if { $no_hw || [target_info exists gdb,no_hardware_watchpoints]
676 || [istarget arm*-*-*]
677 || [istarget powerpc*-*-*]} {
683 gdb_breakpoint [gdb_get_line_number "func7 breakpoint here"]
684 gdb_continue_to_breakpoint "func7 breakpoint here"
686 if { $hw_expected } {
687 gdb_test "watch foo4" "Hardware watchpoint .*: .*" "watch foo4"
688 gdb_test "continue" \
689 "Continuing.*Hardware watchpoint .*: .*New value = \\\{val = \\\{0, 0, 0, 33\\\}\\\}.*" \
690 "continue with watch foo4"
692 gdb_test "watch foo4" "atchpoint .*: .*" "watch foo4"
693 set test "continue with watch foo4"
694 gdb_test_multiple "cont" $test {
695 -re "Continuing.*\[Ww\]atchpoint .*: .*New value = \\\{val = \\\{0, 0, 0, 33\\\}\\\}.*$gdb_prompt $" {
698 -re "Could not insert hardware breakpoints:.*You may have requested too many hardware breakpoints/watchpoints.*$gdb_prompt $" {
699 # This may happen with remote targets that support
700 # hardware watchpoints. We only find out the
701 # watchpoint was too large, for example, at insert
702 # time. If GDB is ever adjusted to downgrade the
703 # watchpoint automatically in this case, this match
710 gdb_test_no_output "delete \$bpnum" "delete watch foo4"
713 proc test_inaccessible_watchpoint {} {
716 # This is a test for watchpoints on currently inaccessible (but later
719 if [runto func4] then {
720 # Make sure we only allow memory access errors.
721 set msg "watchpoint refused to insert on nonexistent struct member"
722 gdb_test_multiple "watch struct1.nosuchmember" $msg {
723 -re ".*atchpoint \[0-9\]+: struct1.nosuchmember.*$gdb_prompt $" {
724 # PR breakpoints/9681
727 -re "There is no member named nosuchmember\\..*$gdb_prompt $" {
732 # See whether a watchpoint on a normal variable is a hardware
733 # watchpoint or not. The watchpoints on NULL should be hardware
735 set watchpoint_msg "Watchpoint"
736 gdb_test_multiple "watch global_ptr" "watch global_ptr" {
737 -re "Watchpoint \[0-9\]+: global_ptr\r\n.*$gdb_prompt $" {
738 pass "watch global_ptr"
740 -re "Hardware watchpoint \[0-9\]+: global_ptr\r\n.*$gdb_prompt $" {
741 set watchpoint_msg "Hardware watchpoint"
742 pass "watch global_ptr"
747 # Make sure that we can watch a constant address, and correctly
748 # use a HW watchpoint if supported.
749 gdb_test "watch *(int *) 0" \
750 "$watchpoint_msg \[0-9\]+: \\*\\(int \\*\\) 0"
753 # The same, but using -location through an indirection.
754 gdb_test "watch -location *global_ptr" \
755 "$watchpoint_msg \[0-9\]+: \-location \\*global_ptr"
758 # This step requires two HW watchpoints. Since some platforms only
759 # have a single one, accept either SW or HW watchpoint in this case.
760 if {[skip_hw_watchpoint_multi_tests]} {
761 set watchpoint_msg "(Watchpoint|Hardware watchpoint)"
764 gdb_test "watch *global_ptr" "$watchpoint_msg \[0-9\]+: \\\*global_ptr"
765 gdb_test "set \$global_ptr_breakpoint_number = \$bpnum" ""
766 gdb_test "next" ".*global_ptr = buf.*" "global_ptr next"
767 gdb_test_multiple "next" "next over ptr init" {
768 -re ".*atchpoint \[0-9\]+: \\*global_ptr\r\n\r\nOld value = .*\r\nNew value = 3 .*\r\n.*$gdb_prompt $" {
769 # We can not test for <unknown> here because NULL may be readable.
770 # This test does rely on *NULL != 3.
771 pass "next over ptr init"
774 gdb_test_multiple "next" "next over buffer set" {
775 -re ".*atchpoint \[0-9\]+: \\*global_ptr\r\n\r\nOld value = 3 .*\r\nNew value = 7 .*\r\n.*$gdb_prompt $" {
776 pass "next over buffer set"
779 gdb_test "delete \$global_ptr_breakpoint_number" ""
780 gdb_test "watch **global_ptr_ptr" ".*atchpoint \[0-9\]+: \\*\\*global_ptr_ptr"
781 gdb_test "set \$global_ptr_ptr_breakpoint_number = \$bpnum" ""
782 gdb_test "next" ".*global_ptr_ptr = &global_ptr.*" "global_ptr_ptr next"
783 gdb_test "next" ".*atchpoint \[0-9\]+: \\*\\*global_ptr_ptr\[\r\n\]+Old value = .*\r\nNew value = 7 .*" "next over global_ptr_ptr init"
784 gdb_test "next" ".*atchpoint \[0-9\]+: \\*\\*global_ptr_ptr\[\r\n\]+Old value = 7 .*\r\nNew value = 9 .*" "next over global_ptr_ptr buffer set"
785 gdb_test "next" ".*atchpoint \[0-9\]+: \\*\\*global_ptr_ptr\[\r\n\]+Old value = 9 .*\r\nNew value = 5 .*" "next over global_ptr_ptr pointer advance"
786 gdb_test_no_output "delete \$global_ptr_ptr_breakpoint_number"
790 proc test_no_hw_watchpoints {} {
793 clean_restart $testfile
795 # Verify that a user can force GDB to use "slow" watchpoints.
796 # (This proves rather little on kernels that don't support
797 # fast watchpoints, but still...)
799 if ![runto_main] then { fail "watch tests suppressed" }
801 gdb_test_no_output "set can-use-hw-watchpoints 0" "disable fast watches"
803 gdb_test "show can-use-hw-watchpoints" \
804 "Debugger's willingness to use watchpoint hardware is 0." \
805 "show disable fast watches"
807 gdb_test "watch ival3 if count > 1" \
808 "Watchpoint \[0-9\]*: ival3.*" \
809 "set slow conditional watch"
811 gdb_test "continue" \
812 "Watchpoint \[0-9\]*: ival3.*Old value = 1.*New value = 2.*" \
813 "trigger slow conditional watch"
815 gdb_test_no_output "delete \$bpnum" "delete watch ival3"
817 # We've explicitly disabled hardware watches. Verify that GDB
818 # refrains from using them.
820 gdb_test "rwatch ival3" \
821 "Expression cannot be implemented with read/access watchpoint..*" \
822 "rwatch disallowed when can-set-hw-watchpoints cleared"
824 # Re-enable hardware watchpoints if necessary.
825 if ![target_info exists gdb,no_hardware_watchpoints] {
826 gdb_test_no_output "set can-use-hw-watchpoints 1" ""
830 proc test_watchpoint_in_big_blob {} {
833 # On native targets where we do hardware resource accounting, this
834 # may end up as a software watchpoint.
837 gdb_test_multiple "watch buf" $test {
838 -re "Hardware watchpoint \[0-9\]+: buf.*You may have requested too many hardware breakpoints/watchpoints.*$gdb_prompt $" {
839 # This may happen with remote targets (where we don't do
840 # resource accounting) that support hardware watchpoints,
841 # when breakpoint always-inserted is on. The watchpoint
842 # was too large, for example. If GDB is ever adjusted to
843 # downgrade the watchpoint automatically in this case,
844 # this match should be removed. Note the breakpoint has
845 # been created, and is in the list, so it needs deleting.
848 -re ".*atchpoint \[0-9\]+: buf.*$gdb_prompt $" {
855 set test "watchpoint on buf hit"
856 gdb_test_multiple "cont" $test {
857 -re "Continuing.*atchpoint \[0-9\]+: buf\r\n\r\nOld value = .*testte\".*$gdb_prompt $" {
860 -re "Could not insert hardware breakpoints:.*You may have requested too many hardware breakpoints/watchpoints.*$gdb_prompt $" {
861 # This may happen with remote targets that support
862 # hardware watchpoints. We only find out the
863 # watchpoint was too large, for example, at insert
864 # time. If GDB is ever adjusted to downgrade the
865 # watchpoint automatically in this case, this match
872 gdb_test_no_output "delete \$bpnum" "delete watch buf"
875 # Start with a fresh gdb.
877 set prev_timeout $timeout
879 verbose "Timeout now 600 sec.\n"
881 test_no_hw_watchpoints
887 clean_restart $testfile
889 if {$no_hw || [target_info exists gdb,no_hardware_watchpoints]} {
890 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
893 if [initialize] then {
895 test_simple_watchpoint
897 test_disabling_watchpoints
899 if ![target_info exists gdb,cannot_call_functions] {
904 # Tests below don't rely on the markers and watchpoint set by
905 # `initialize' anymore.
906 clean_restart $testfile
908 if {$no_hw || [target_info exists gdb,no_hardware_watchpoints]} {
909 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
912 # Only enabled for some targets merely because it has not been tested
914 # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4
915 # breakpoint before stopping for the watchpoint. I don't know why.
916 if {[istarget "hppa*-*-*"]} then {
917 test_watchpoint_triggered_in_syscall
920 test_complex_watchpoint
922 test_inaccessible_watchpoint
924 test_watchpoint_and_breakpoint
926 test_watchpoint_in_big_blob
928 test_constant_watchpoint
930 test_disable_enable_software_watchpoint
938 # On targets that can do hardware watchpoints, run the tests twice:
939 # once with hardware watchpoints enabled; another with hardware
940 # watchpoints force-disabled.
943 if ![target_info exists gdb,no_hardware_watchpoints] {
944 with_test_prefix "no-hw" {
950 # Restore old timeout
951 set timeout $prev_timeout
952 verbose "Timeout now $timeout sec.\n"