1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2007, 2008
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Fred Fish. (fnf@cygnus.com)
29 set testfile "watchpoint"
30 set srcfile ${testfile}.c
31 set binfile ${objdir}/${subdir}/${testfile}
35 if [get_compiler_info ${binfile}] {
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40 untested watchpoint.exp
44 # Prepare for watchpoint tests by setting up two breakpoints and one
47 # We use breakpoints at marker functions to get past all the startup code,
48 # so we can get to the watchpoints in a reasonable amount of time from a
49 # known starting point.
51 # For simplicity, so we always know how to reference specific breakpoints or
52 # watchpoints by number, we expect a particular ordering and numbering of
53 # each in the combined breakpoint/watchpoint table, as follows:
56 # 1 Breakpoint marker1()
57 # 2 Breakpoint marker2()
67 # Disable hardware watchpoints if necessary.
68 if [target_info exists gdb,no_hardware_watchpoints] {
69 gdb_test "set can-use-hw-watchpoints 0" "" ""
72 if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] {
77 if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] {
82 if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] {
87 # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
88 # before running can cause the inferior to croak on HP-UX 11.0 for
89 # reasons yet unknown, we've disabled the ability to set watches
90 # without a running inferior. Verify the restriction.
92 send_gdb "watch ival3\n"
94 -re ".*\[Ww\]atchpoint 3: ival3.*$gdb_prompt $" {
95 pass "set watchpoint on ival3"
97 -re "warning: can't do that without a running program; try \"break main\", \"run\" first.*$gdb_prompt $" {
98 pass "set watchpoint on ival3"
103 fail "(timeout) set watchpoint on ival3"
108 # "info watch" is the same as "info break"
110 if [gdb_test "info watch" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] {
115 # After installing the watchpoint, we disable it until we are ready
116 # to use it. This allows the test program to run at full speed until
117 # we get to the first marker function.
119 if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] {
128 # Test simple watchpoint.
131 proc test_simple_watchpoint {} {
137 # Ensure that the watchpoint is disabled when we startup.
140 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] {
146 # Run until we get to the first marker function.
151 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
152 pass "run to marker1 in test_simple_watchpoint"
154 -re ".*$gdb_prompt $" {
155 fail "run to marker1 in test_simple_watchpoint"
159 fail "run to marker1 in test_simple_watchpoint (timeout)"
165 # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
166 # before running can cause the inferior to croak on HP-UX 11.0
167 # for reasons yet unknown, we've disabled the ability to set
168 # watches without a running inferior. The following testpoints used
169 # to be in [initialize].
171 send_gdb "watch ival3\n"
173 -re ".*\[Ww\]atchpoint 3: ival3\r\n$gdb_prompt $" {
174 pass "set watchpoint on ival3"
176 -re ".*$gdb_prompt $" { fail "set watchpoint on ival3" }
177 timeout { fail "set watchpoint on ival3 (timeout)" }
182 # "info watch" is the same as "info break"
184 send_gdb "info watch\n"
186 -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3\r\n$gdb_prompt $" {
187 pass "watchpoint found in watchpoint/breakpoint table"
189 -re ".*$gdb_prompt $" {
190 fail "watchpoint found in watchpoint/breakpoint table"
193 fail "watchpoint found in watchpoint/breakpoint table"
197 # After installing the watchpoint, we disable it until we are ready
198 # to use it. This allows the test program to run at full speed until
199 # we get to the first marker function.
201 send_gdb "disable 3\n"
203 -re "disable 3\[\r\n\]+$gdb_prompt $" { pass "disable watchpoint" }
204 -re ".*$gdb_prompt $" { fail "disable watchpoint" }
205 timeout { fail "disable watchpoint (timeout)" }
209 # After reaching the marker function, enable the watchpoint.
211 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] {
216 gdb_test "break func1" "Breakpoint.*at.*"
217 gdb_test "set \$func1_breakpoint_number = \$bpnum" ""
219 gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, func1.*" \
220 "continue to breakpoint at func1"
222 # Continue until the first change, from -1 to 0
226 -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
227 pass "watchpoint hit, first time"
229 -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
230 setup_xfail "m68*-*-*" 2597
231 fail "thought it hit breakpoint at func1 twice"
232 gdb_test "delete \$func1_breakpoint_number" ""
233 gdb_test "continue" "\
234 Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
235 "watchpoint hit, first time"
237 -re ".*$gdb_prompt $" { fail "watchpoint hit, first time" ; return }
238 timeout { fail "watchpoint hit, first time (timeout)" ; return }
239 eof { fail "watchpoint hit, first time (eof)" ; return }
242 # Check that the hit count is reported correctly
243 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 1 time.*" "Watchpoint hit count is 1"
245 gdb_test "delete \$func1_breakpoint_number" ""
247 # Continue until the next change, from 0 to 1.
248 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time"
250 # Check that the hit count is reported correctly
251 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 2 times.*" "Watchpoint hit count is 2"
253 # Continue until the next change, from 1 to 2.
254 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time"
256 # Check that the hit count is reported correctly
257 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 3 times.*" "Watchpoint hit count is 3"
259 # Continue until the next change, from 2 to 3.
260 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time"
262 # Check that the hit count is reported correctly
263 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 4 times.*" "Watchpoint hit count is 4"
265 # Continue until the next change, from 3 to 4.
266 # Note that this one is outside the loop.
268 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time"
270 # Check that the hit count is reported correctly
271 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 5 times.*" "Watchpoint hit count is 5"
273 # Continue until we hit the finishing marker function.
274 # Make sure we hit no more watchpoints.
276 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \(\).*" \
277 "continue to marker2"
279 # Disable the watchpoint so we run at full speed until we exit.
281 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] {
286 # Run until process exits.
288 if [target_info exists gdb,noresults] { return }
290 gdb_continue_to_end "continue to exit in test_simple_watchpoint"
293 # Test disabling watchpoints.
295 proc test_disabling_watchpoints {} {
302 # "info watch" is the same as "info break"
303 gdb_test "info watch" "\[0-9\]+\[ \]*breakpoint.*marker1.*\r\n\[0-9\]+\[ \]*breakpoint.*marker2.*\r\n\[0-9]+\[ \]*.*watchpoint.*ival3\r\n\.*\[0-9\]+ times.*" "watchpoints found in watchpoint/breakpoint table"
305 # Ensure that the watchpoint is disabled when we startup.
307 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] {
312 # Run until we get to the first marker function.
317 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
318 pass "run to marker1 in test_disabling_watchpoints"
320 -re ".*$gdb_prompt $" {
321 fail "run to marker1 in test_disabling_watchpoints"
325 fail "run to marker1 in test_disabling_watchpoints (timeout)"
330 # After reaching the marker function, enable the watchpoint.
332 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] {
337 # Continue until the first change, from -1 to 0
338 # Don't check the old value, because on VxWorks the variable value
339 # will not have been reinitialized.
340 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, first time"
342 # Continue until the next change, from 0 to 1.
343 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"
345 # Disable the watchpoint but leave breakpoints
347 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] {
352 # Check watchpoint list, looking for the entry that confirms the
353 # watchpoint is disabled.
354 gdb_test "info watchpoints" "\[0-9]+\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
356 # Continue until we hit the finishing marker function.
357 # Make sure we hit no more watchpoints.
358 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \
359 "disabled watchpoint skipped"
361 if [target_info exists gdb,noresults] { return }
363 gdb_continue_to_end "continue to exit in test_disabling_watchpoints"
366 # Test stepping and other mundane operations with watchpoints enabled
367 proc test_stepping {} {
370 if [runto marker1] then {
371 gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
373 # Well, let's not be too mundane. It should be a *bit* of a challenge
374 gdb_test "break func2 if 0" "Breakpoint.*at.*"
375 gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*"
377 gdb_test "p func1 ()" "= 73" \
378 "calling function with watchpoint enabled"
381 # "finish" brings us back to main.
382 # On some targets (e.g. alpha) gdb will stop from the finish in midline
383 # of the marker1 call. This is due to register restoring code on
384 # the alpha and might be caused by stack adjustment instructions
385 # on other targets. In this case we will step once more.
390 -re "Run.*exit from.*marker1.* at" {
391 pass "finish from marker1"
393 default { fail "finish from marker1 (timeout)" ; return }
397 -re "marker1 \\(\\);.*$gdb_prompt $" {
401 -re "func1 \\(\\);.*$gdb_prompt $" {
402 pass "back at main from marker1"
404 -re ".*$gdb_prompt $" {
405 fail "back at main from marker1"
407 default { fail "back at main from marker1 (timeout)" ; return }
410 gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp"
412 # Now test that "until" works. It's a bit tricky to test
413 # "until", because compilers don't always arrange the code
414 # exactly the same way, and we might get slightly different
415 # sequences of statements. But the following should be true
416 # (if not it is a compiler or a debugger bug): The user who
417 # does "until" at every statement of a loop should end up
418 # stepping through the loop once, and the debugger should not
419 # stop for any of the remaining iterations.
421 gdb_test "until" "ival1 = count.*" "until to ival1 assignment"
422 gdb_test "until" "ival3 = count.*" "until to ival3 assignment"
425 -re "(for \\(count = 0|\}).*$gdb_prompt $" {
426 gdb_test "until" "ival1 = count; /. Outside loop ./" \
429 -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
430 pass "until out of loop"
432 -re ".*$gdb_prompt $" {
433 fail "until out of loop"
435 default { fail "until out of loop (timeout)" ; return }
438 gdb_test "step" "ival2 = count.*" "step to ival2 assignment"
442 # Test stepping and other mundane operations with watchpoints enabled
443 proc test_watchpoint_triggered_in_syscall {} {
446 # These tests won't work without printf support.
447 if [gdb_skip_stdio_test "watchpoints triggered in syscall"] {
450 # Run until we get to the first marker function.
453 set testname "Watch buffer passed to read syscall"
454 if [runto marker2] then {
455 gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]"
456 gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]"
457 gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]"
458 gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]"
459 gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]"
460 gdb_test "break marker4" ".*Breakpoint.*"
462 gdb_test "set doread = 1" ""
464 # If we send_gdb "123\n" before gdb has switched the tty, then it goes
465 # to gdb, not the inferior, and we lose. So that is why we have
466 # watchpoint.c prompt us, so we can wait for that prompt.
467 send_gdb "continue\n";
469 -re "Continuing\\.\r\ntype stuff for buf now:" {
470 pass "continue to read"
473 fail "continue to read";
480 -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
481 -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
482 -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
483 -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
484 -re ".*$gdb_prompt $" { pass "sent 123" }
485 timeout { fail "sent 123 (timeout)" }
488 # Examine the values in buf to see how many watchpoints we
489 # should have printed.
490 send_gdb "print buf\[0\]\n"
492 -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[0\]"}
493 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[0\]"}
494 -re ".*$gdb_prompt $" { fail "print buf\[0\]"}
495 default { fail "print buf\[0\]"}
497 send_gdb "print buf\[1\]\n"
499 -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[1\]"}
500 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[1\]"}
501 -re ".*$gdb_prompt $" { fail "print buf\[1\]"}
502 default { fail "print buf\[1\]"}
504 send_gdb "print buf\[2\]\n"
506 -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[2\]"}
507 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[2\]"}
508 -re ".*$gdb_prompt $" { fail "print buf\[2\]"}
509 default { fail "print buf\[2\]"}
511 send_gdb "print buf\[3\]\n"
513 -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[3\]"}
514 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[3\]"}
515 -re ".*$gdb_prompt $" { fail "print buf\[3\]" }
516 default { fail "print buf\[3\]" }
519 # Did we find what we were looking for? If not, flunk it.
520 if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"}
522 # Continue until we hit the finishing marker function.
523 # Make sure we hit no more watchpoints.
524 gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \
525 "continue to marker4"
527 # Disable everything so we can finish the program at full speed
528 gdb_test "disable" "" "disable in test_watchpoint_triggered_in_syscall"
530 if [target_info exists gdb,noresults] { return }
532 gdb_continue_to_end "continue to exit in test_watchpoint_triggered_in_syscall"
536 # Do a simple test of of watching through a pointer when the pointer
537 # itself changes. Should add some more complicated stuff here.
539 proc test_complex_watchpoint {} {
542 if [runto marker4] then {
543 gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
544 gdb_test "break marker5" ".*Breakpoint.*"
546 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "Test complex watchpoint"
548 # Continue until we hit the marker5 function.
549 # Make sure we hit no more watchpoints.
551 gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \
552 "did not trigger wrong watchpoint"
554 # Test watches of things declared locally in a function.
555 # In particular, test that a watch of stack-based things
556 # is deleted when the stack-based things go out of scope.
558 gdb_test "disable" "" "disable in test_complex_watchpoint"
559 gdb_test "break marker6" ".*Breakpoint.*"
560 gdb_test "cont" "Continuing.*Breakpoint.*marker6 \\(\\).*" \
561 "continue to marker6"
562 gdb_test "break func2" ".*Breakpoint.*"
563 gdb_test "cont" "Continuing.*func2.*"
565 # Test a watch of a single stack-based variable, whose scope
566 # is the function we're now in. This should auto-delete when
567 # execution exits the scope of the watchpoint.
569 gdb_test "watch local_a" ".*\[Ww\]atchpoint \[0-9\]*: local_a" "set local watch"
570 gdb_test "cont" "\[Ww\]atchpoint.*local_a.*" "trigger local watch"
571 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" "self-delete local watch"
573 gdb_test "cont" "Continuing.*func2.*"
574 # We should be in "func2" again now. Test a watch of an
575 # expression which includes both a stack-based local and
576 # something whose scope is larger than this invocation
577 # of "func2". This should also auto-delete.
579 gdb_test "watch local_a + ival5" ".*\[Ww\]atchpoint \[0-9\]*: local_a . ival5" \
580 "set partially local watch"
581 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
582 "trigger1 partially local watch"
583 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
584 "trigger2 partially local watch"
585 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
586 "self-delete partially local watch"
588 # We should be in "func2" again now. Test a watch of a
589 # static (non-stack-based) local. Since this has scope
590 # across any invocations of "func2", it should not auto-
593 gdb_test "cont" "Continuing.*func2.*"
594 gdb_test "watch static_b" ".*\[Ww\]atchpoint \[0-9\]*: static_b" \
595 "set static local watch"
596 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: static_b.*" \
597 "trigger static local watch"
598 gdb_test "cont" "Continuing.*marker6 \\(\\).*" \
599 "continue after trigger static local watch"
600 gdb_test "info break" ".*watchpoint.*static_b.*" \
601 "static local watch did not self-delete"
603 # We should be in "recurser" now. Test a watch of a stack-
604 # based local. Symbols mentioned in a watchpoint are bound
605 # at watchpoint-creation. Thus, a watch of a stack-based
606 # local to a recursing function should be bound only to that
607 # one invocation, and should not trigger for other invocations.
609 gdb_test "tbreak recurser" ".*Breakpoint.*"
610 gdb_test "cont" "Continuing.*recurser.*"
611 gdb_test "watch local_x" ".*\[Ww\]atchpoint \[0-9\]*: local_x" \
612 "set local watch in recursive call"
613 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_x.*New value = 2.*" \
614 "trigger local watch in recursive call"
615 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
616 "self-delete local watch in recursive call"
618 # Disable everything so we can finish the program at full speed
619 gdb_test "disable" "" "disable in test_complex_watchpoint"
621 if [target_info exists gdb,noresults] { return }
623 gdb_continue_to_end "continue to exit in test_complex_watchpoint"
627 proc test_watchpoint_and_breakpoint {} {
630 # This is a test for PR gdb/38, which involves setting a
631 # watchpoint right after you've reached a breakpoint.
633 if [runto func3] then {
634 gdb_breakpoint [gdb_get_line_number "second x assignment"]
635 gdb_continue_to_breakpoint "second x assignment"
636 gdb_test "watch x" ".*atchpoint \[0-9\]+: x"
637 gdb_test_multiple "next" "next after watch x" {
638 -re ".*atchpoint \[0-9\]+: x\r\n\r\nOld value = 0\r\nNew value = 1\r\n.*$gdb_prompt $" {
639 pass "next after watch x"
641 -re "\[0-9\]+\[\t \]+y = 1;\r\n$gdb_prompt $" {
642 kfail "gdb/38" "next after watch x"
648 proc test_inaccessible_watchpoint {} {
651 # This is a test for watchpoints on currently inaccessible (but later
654 if [runto func4] then {
655 gdb_test "watch *global_ptr" ".*atchpoint \[0-9\]+: \\*global_ptr"
656 gdb_test "next" ".*global_ptr = buf.*"
657 gdb_test_multiple "next" "next over ptr init" {
658 -re ".*atchpoint \[0-9\]+: \\*global_ptr\r\n\r\nOld value = .*\r\nNew value = 3 .*\r\n.*$gdb_prompt $" {
659 # We can not test for <unknown> here because NULL may be readable.
660 # This test does rely on *NULL != 3.
661 pass "next over ptr init"
664 gdb_test_multiple "next" "next over buffer set" {
665 -re ".*atchpoint \[0-9\]+: \\*global_ptr\r\n\r\nOld value = 3 .*\r\nNew value = 7 .*\r\n.*$gdb_prompt $" {
666 pass "next over buffer set"
672 # Start with a fresh gdb.
676 gdb_reinitialize_dir $srcdir/$subdir
678 set prev_timeout $timeout
680 verbose "Timeout now 600 sec.\n"
682 if [initialize] then {
684 test_simple_watchpoint
686 # The IDT/sim monitor only has 8 (!) open files, of which it uses
687 # 4 (!). So we have to make sure one program exits before
688 # starting another one.
689 if [istarget "mips-idt-*"] then {
692 gdb_reinitialize_dir $srcdir/$subdir
697 test_disabling_watchpoints
700 if [istarget "mips-idt-*"] then {
703 gdb_reinitialize_dir $srcdir/$subdir
708 if ![target_info exists gdb,cannot_call_functions] {
712 if [istarget "mips-idt-*"] then {
715 gdb_reinitialize_dir $srcdir/$subdir
721 # Only enabled for some targets merely because it has not been tested
723 # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4
724 # breakpoint before stopping for the watchpoint. I don't know why.
725 if {[istarget "hppa*-*-*"]} then {
726 test_watchpoint_triggered_in_syscall
730 if [istarget "mips-idt-*"] then {
733 gdb_reinitialize_dir $srcdir/$subdir
738 # Only enabled for some targets merely because it has not been tested
740 if {[istarget "hppa*-*-*"] || \
741 [istarget "sparc*-*-sunos*"] || \
742 [istarget "m32r-*-*"]} then {
743 test_complex_watchpoint
746 # Verify that a user can force GDB to use "slow" watchpoints.
747 # (This proves rather little on kernels that don't support
748 # fast watchpoints, but still...)
750 if ![runto_main] then { fail "watch tests suppressed" }
752 send_gdb "set can-use-hw-watchpoints 0\n"
755 {pass "disable fast watches"}
756 timeout {fail "(timeout) disable fast watches"}
758 send_gdb "show can-use-hw-watchpoints\n"
760 -re "Debugger's willingness to use watchpoint hardware is 0.*$gdb_prompt $"\
761 {pass "show disable fast watches"}
763 {fail "show disable fast watches"}
764 timeout {fail "(timeout) show disable fast watches"}
766 send_gdb "watch ival3 if count > 1\n"
768 -re "Watchpoint \[0-9\]*: ival3.*$gdb_prompt $"\
769 {pass "set slow conditional watch"}
771 {fail "set slow conditional watch"}
772 timeout {fail "(timeout) set slow conditional watch"}
774 send_gdb "continue\n"
776 -re "Watchpoint \[0-9\]*: ival3.*Old value = 1.*New value = 2.*$gdb_prompt $"\
777 {pass "trigger slow conditional watch"}
779 {fail "trigger slow conditional watch"}
780 timeout {fail "(timeout) trigger slow conditional watch"}
783 # We've explicitly disabled hardware watches. Verify that GDB
784 # refrains from using them.
786 send_gdb "rwatch ival3\n"
788 -re "Expression cannot be implemented with read/access watchpoint..*$gdb_prompt $"\
789 {pass "rwatch disallowed when can-set-hw-watchpoints cleared"}
791 {fail "rwatch disallowed when can-set-hw-watchpoints cleared"}
792 timeout {fail "(timeout) rwatch disallowed when can-use-hw-watchpoints cleared"}
795 # Read- and access watchpoints are unsupported on HP-UX. Verify
796 # that GDB gracefully responds to requests to create them.
798 if [istarget "hppa*-*-hpux*"] then {
799 send_gdb "set can-use-hw-watchpoints 1\n"
802 {pass "enable fast watches"}
803 timeout {fail "(timeout) enable fast watches"}
805 send_gdb "rwatch ival3\n"
807 -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
808 {pass "read watches disallowed"}
810 {fail "read watches disallowed"}
811 timeout {fail "(timeout) read watches disallowed"}
814 send_gdb "awatch ival3\n"
816 -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
817 {pass "access watches disallowed"}
819 {fail "access watches disallowed"}
820 timeout {fail "(timeout) access watches disallowed"}
824 test_inaccessible_watchpoint
827 if [istarget "mips-idt-*"] then {
830 gdb_reinitialize_dir $srcdir/$subdir
835 test_watchpoint_and_breakpoint
838 # Restore old timeout
839 set timeout $prev_timeout
840 verbose "Timeout now $timeout sec.\n"