1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000
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 2 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, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # This file was written by Fred Fish. (fnf@cygnus.com)
30 set testfile "watchpoint"
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/${testfile}
36 if [get_compiler_info ${binfile}] {
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
41 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
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 # The problem is that GDB confuses stepping through the call
378 # dummy with hitting the breakpoint at the end of the call dummy.
379 # Will be fixed once all architectures define
380 # CALL_DUMMY_BREAKPOINT_OFFSET.
382 # This doesn't occur if the call dummy starts with a call,
383 # because we are out of the dummy by the first time the inferior
385 clear_xfail "arm*-*-*"
386 clear_xfail "xscale*-*-*"
387 clear_xfail "d10v*-*-*"
388 clear_xfail "m68*-*-*"
389 clear_xfail "i*86*-*-*"
390 clear_xfail "vax-*-*"
391 # The following architectures define CALL_DUMMY_BREAKPOINT_OFFSET.
392 clear_xfail "alpha-*-*"
393 clear_xfail "mips*-*-*"
394 clear_xfail "sparc-*-*"
395 clear_xfail "hppa*-*-*bsd*"
396 # It works with the generic inferior function calling code too.
397 clear_xfail "mn10200*-*-*"
398 clear_xfail "mn10300*-*-*"
399 # The following architectures define CALL_DUMMY_HAS_COMPLETED.
400 clear_xfail "hppa*-*-*hpux*"
401 gdb_test "p func1 ()" "= 73" \
402 "calling function with watchpoint enabled"
405 # "finish" brings us back to main.
406 # On some targets (e.g. alpha) gdb will stop from the finish in midline
407 # of the marker1 call. This is due to register restoring code on
408 # the alpha and might be caused by stack adjustment instructions
409 # on other targets. In this case we will step once more.
414 -re "Run.*exit from.*marker1.* at" {
415 pass "finish from marker1"
417 default { fail "finish from marker1 (timeout)" ; return }
421 -re "marker1 \\(\\);.*$gdb_prompt $" {
425 -re "func1 \\(\\);.*$gdb_prompt $" {
426 pass "back at main from marker1"
428 -re ".*$gdb_prompt $" {
429 fail "back at main from marker1"
431 default { fail "back at main from marker1 (timeout)" ; return }
434 gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp"
436 # Now test that "until" works. It's a bit tricky to test
437 # "until", because compilers don't always arrange the code
438 # exactly the same way, and we might get slightly different
439 # sequences of statements. But the following should be true
440 # (if not it is a compiler or a debugger bug): The user who
441 # does "until" at every statement of a loop should end up
442 # stepping through the loop once, and the debugger should not
443 # stop for any of the remaining iterations.
445 gdb_test "until" "ival1 = count.*" "until to ival1 assignment"
446 gdb_test "until" "ival3 = count.*" "until to ival3 assignment"
449 -re "(for \\(count = 0|\}).*$gdb_prompt $" {
450 gdb_test "until" "ival1 = count; /. Outside loop ./" \
453 -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
454 pass "until out of loop"
456 -re ".*$gdb_prompt $" {
457 fail "until out of loop"
459 default { fail "until out of loop (timeout)" ; return }
462 gdb_test "step" "ival2 = count.*" "step to ival2 assignment"
466 # Test stepping and other mundane operations with watchpoints enabled
467 proc test_watchpoint_triggered_in_syscall {} {
470 # These tests won't work without printf support.
471 if [gdb_skip_stdio_test "watchpoints triggered in syscall"] {
474 # Run until we get to the first marker function.
477 set testname "Watch buffer passed to read syscall"
478 if [runto marker2] then {
479 gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]"
480 gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]"
481 gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]"
482 gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]"
483 gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]"
484 gdb_test "break marker4" ".*Breakpoint.*"
486 gdb_test "set doread = 1" ""
488 # If we send_gdb "123\n" before gdb has switched the tty, then it goes
489 # to gdb, not the inferior, and we lose. So that is why we have
490 # watchpoint.c prompt us, so we can wait for that prompt.
491 send_gdb "continue\n";
493 -re "Continuing\\.\r\ntype stuff for buf now:" {
494 pass "continue to read"
497 fail "continue to read";
504 -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
505 -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
506 -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
507 -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
508 -re ".*$gdb_prompt $" { pass "sent 123" }
509 timeout { fail "sent 123 (timeout)" }
512 # Examine the values in buf to see how many watchpoints we
513 # should have printed.
514 send_gdb "print buf\[0\]\n"
516 -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[0\]"}
517 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[0\]"}
518 -re ".*$gdb_prompt $" { fail "print buf\[0\]"}
519 default { fail "print buf\[0\]"}
521 send_gdb "print buf\[1\]\n"
523 -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[1\]"}
524 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[1\]"}
525 -re ".*$gdb_prompt $" { fail "print buf\[1\]"}
526 default { fail "print buf\[1\]"}
528 send_gdb "print buf\[2\]\n"
530 -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[2\]"}
531 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[2\]"}
532 -re ".*$gdb_prompt $" { fail "print buf\[2\]"}
533 default { fail "print buf\[2\]"}
535 send_gdb "print buf\[3\]\n"
537 -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[3\]"}
538 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[3\]"}
539 -re ".*$gdb_prompt $" { fail "print buf\[3\]" }
540 default { fail "print buf\[3\]" }
543 # Did we find what we were looking for? If not, flunk it.
544 if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"}
546 # Continue until we hit the finishing marker function.
547 # Make sure we hit no more watchpoints.
548 gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \
549 "continue to marker4"
551 # Disable everything so we can finish the program at full speed
552 gdb_test "disable" "" "disable in test_watchpoint_triggered_in_syscall"
554 if [target_info exists gdb,noresults] { return }
556 gdb_continue_to_end "continue to exit in test_watchpoint_triggered_in_syscall"
560 # Do a simple test of of watching through a pointer when the pointer
561 # itself changes. Should add some more complicated stuff here.
563 proc test_complex_watchpoint {} {
566 if [runto marker4] then {
567 gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
568 gdb_test "break marker5" ".*Breakpoint.*"
570 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "Test complex watchpoint"
572 # Continue until we hit the marker5 function.
573 # Make sure we hit no more watchpoints.
575 gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \
576 "did not trigger wrong watchpoint"
578 # Test watches of things declared locally in a function.
579 # In particular, test that a watch of stack-based things
580 # is deleted when the stack-based things go out of scope.
582 gdb_test "disable" "" "disable in test_complex_watchpoint"
583 gdb_test "break marker6" ".*Breakpoint.*"
584 gdb_test "cont" "Continuing.*Breakpoint.*marker6 \\(\\).*" \
585 "continue to marker6"
586 gdb_test "break func2" ".*Breakpoint.*"
587 gdb_test "cont" "Continuing.*func2.*"
589 # Test a watch of a single stack-based variable, whose scope
590 # is the function we're now in. This should auto-delete when
591 # execution exits the scope of the watchpoint.
593 gdb_test "watch local_a" ".*\[Ww\]atchpoint \[0-9\]*: local_a" "set local watch"
594 gdb_test "cont" "\[Ww\]atchpoint.*local_a.*" "trigger local watch"
595 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" "self-delete local watch"
597 gdb_test "cont" "Continuing.*func2.*"
598 # We should be in "func2" again now. Test a watch of an
599 # expression which includes both a stack-based local and
600 # something whose scope is larger than this invocation
601 # of "func2". This should also auto-delete.
603 gdb_test "watch local_a + ival5" ".*\[Ww\]atchpoint \[0-9\]*: local_a . ival5" \
604 "set partially local watch"
605 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
606 "trigger1 partially local watch"
607 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
608 "trigger2 partially local watch"
609 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
610 "self-delete partially local watch"
612 # We should be in "func2" again now. Test a watch of a
613 # static (non-stack-based) local. Since this has scope
614 # across any invocations of "func2", it should not auto-
617 gdb_test "cont" "Continuing.*func2.*"
618 gdb_test "watch static_b" ".*\[Ww\]atchpoint \[0-9\]*: static_b" \
619 "set static local watch"
620 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: static_b.*" \
621 "trigger static local watch"
622 gdb_test "cont" "Continuing.*marker6 \\(\\).*" \
623 "continue after trigger static local watch"
624 gdb_test "info break" ".*watchpoint.*static_b.*" \
625 "static local watch did not self-delete"
627 # We should be in "recurser" now. Test a watch of a stack-
628 # based local. Symbols mentioned in a watchpoint are bound
629 # at watchpoint-creation. Thus, a watch of a stack-based
630 # local to a recursing function should be bound only to that
631 # one invocation, and should not trigger for other invocations.
633 gdb_test "tbreak recurser" ".*Breakpoint.*"
634 gdb_test "cont" "Continuing.*recurser.*"
635 gdb_test "watch local_x" ".*\[Ww\]atchpoint \[0-9\]*: local_x" \
636 "set local watch in recursive call"
637 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_x.*New value = 2.*" \
638 "trigger local watch in recursive call"
639 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
640 "self-delete local watch in recursive call"
642 # Disable everything so we can finish the program at full speed
643 gdb_test "disable" "" "disable in test_complex_watchpoint"
645 if [target_info exists gdb,noresults] { return }
647 gdb_continue_to_end "continue to exit in test_complex_watchpoint"
651 # Start with a fresh gdb.
655 gdb_reinitialize_dir $srcdir/$subdir
657 set prev_timeout $timeout
659 verbose "Timeout now 600 sec.\n"
661 if [initialize] then {
663 test_simple_watchpoint
665 # The IDT/sim monitor only has 8 (!) open files, of which it uses
666 # 4 (!). So we have to make sure one program exits before
667 # starting another one.
668 if [istarget "mips-idt-*"] then {
671 gdb_reinitialize_dir $srcdir/$subdir
676 test_disabling_watchpoints
679 if [istarget "mips-idt-*"] then {
682 gdb_reinitialize_dir $srcdir/$subdir
687 if ![target_info exists gdb,cannot_call_functions] {
691 if [istarget "mips-idt-*"] then {
694 gdb_reinitialize_dir $srcdir/$subdir
700 # Only enabled for some targets merely because it has not been tested
702 # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4
703 # breakpoint before stopping for the watchpoint. I don't know why.
704 if {[istarget "hppa*-*-*"]} then {
705 test_watchpoint_triggered_in_syscall
709 if [istarget "mips-idt-*"] then {
712 gdb_reinitialize_dir $srcdir/$subdir
717 # Only enabled for some targets merely because it has not been tested
719 if {[istarget "hppa*-*-*"] || \
720 [istarget "sparc*-*-sunos*"] || \
721 [istarget "m32r-*-*"]} then {
722 test_complex_watchpoint
725 # Verify that a user can force GDB to use "slow" watchpoints.
726 # (This proves rather little on kernels that don't support
727 # fast watchpoints, but still...)
729 if ![runto_main] then { fail "watch tests suppressed" }
731 send_gdb "set can-use-hw-watchpoints 0\n"
734 {pass "disable fast watches"}
735 timeout {fail "(timeout) disable fast watches"}
737 send_gdb "show can-use-hw-watchpoints\n"
739 -re "Debugger's willingness to use watchpoint hardware is 0.*$gdb_prompt $"\
740 {pass "show disable fast watches"}
742 {fail "show disable fast watches"}
743 timeout {fail "(timeout) show disable fast watches"}
745 send_gdb "watch ival3 if count > 1\n"
747 -re "Watchpoint \[0-9\]*: ival3.*$gdb_prompt $"\
748 {pass "set slow conditional watch"}
750 {fail "set slow conditional watch"}
751 timeout {fail "(timeout) set slow conditional watch"}
753 send_gdb "continue\n"
755 -re "Watchpoint \[0-9\]*: ival3.*Old value = 1.*New value = 2.*$gdb_prompt $"\
756 {pass "trigger slow conditional watch"}
758 {fail "trigger slow conditional watch"}
759 timeout {fail "(timeout) trigger slow conditional watch"}
762 # We've explicitly disabled hardware watches. Verify that GDB
765 send_gdb "rwatch ival3\n"
767 -re "Expression cannot be implemented with read/access watchpoint..*$gdb_prompt $"\
768 {pass "rwatch disallowed when can-set-hw-watchpoints cleared"}
770 {fail "rwatch disallowed when can-set-hw-watchpoints cleared"}
771 timeout {fail "(timeout) rwatch disallowed when can-use-hw-watchpoints cleared"}
774 # Read- and access watchpoints are unsupported on HP-UX. Verify
775 # that GDB gracefully responds to requests to create them.
777 if [istarget "hppa*-*-hpux*"] then {
778 send_gdb "set can-use-hw-watchpoints 1\n"
781 {pass "enable fast watches"}
782 timeout {fail "(timeout) enable fast watches"}
784 send_gdb "rwatch ival3\n"
786 -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
787 {pass "read watches disallowed"}
789 {fail "read watches disallowed"}
790 timeout {fail "(timeout) read watches disallowed"}
793 send_gdb "awatch ival3\n"
795 -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
796 {pass "access watches disallowed"}
798 {fail "access watches disallowed"}
799 timeout {fail "(timeout) access watches disallowed"}
804 # Restore old timeout
805 set timeout $prev_timeout
806 verbose "Timeout now $timeout sec.\n"