1 # Copyright (C) 1992 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 2 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, write to the Free Software
15 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
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 binfile "watchpoint"
30 set srcfile $binfile.c
32 if ![file exists $objdir/$subdir/$binfile] then {
33 perror "$objdir/$subdir/$binfile does not exist."
38 # Prepare for watchpoint tests by setting up two breakpoints and one
41 # We use breakpoints at marker functions to get past all the startup code,
42 # so we can get to the watchpoints in a reasonable amount of time from a
43 # known starting point.
45 # For simplicity, so we always know how to reference specific breakpoints or
46 # watchpoints by number, we expect a particular ordering and numbering of
47 # each in the combined breakpoint/watchpoint table, as follows:
50 # 1 Breakpoint marker1()
51 # 2 Breakpoint marker2()
60 send "break marker1\n"
62 -re "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*$prompt $" {}
63 -re ".*$prompt $" { fail "set breakpoint at marker1" ; return 0 }
64 timeout { fail "set breakpoint at marker1 (timeout)" ; return 0 }
67 send "break marker2\n"
69 -re "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*$prompt $" {}
70 -re ".*$prompt $" { fail "set breakpoint at marker2" ; return 0 }
71 timeout { fail "set breakpoint at marker2 (timeout)" ; return 0 }
76 -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n$prompt $" { }
77 -re ".*$prompt $" { fail "breakpoints not setup right" ; return 0 }
78 timeout { fail "info break (timeout)" ; return 0 }
83 -re ".*\[Ww\]atchpoint 3: ival3\r\n$prompt $" { pass "set watchpoint" }
84 -re ".*$prompt $" { fail "set watchpoint on ival3" ; return 0 }
85 timeout { fail "set watchpoint on ival3 (timeout)" ; return 0 }
88 # "info watch" is the same as "info break"
92 -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3\r\n$prompt $" {
93 pass "watchpoint found in watchpoint/breakpoint table"
95 -re ".*$prompt $" { fail "watchpoint/breakpoint not set" ; return 0 }
96 timeout { fail "info break (timeout)" ; return 0 }
99 # After installing the watchpoint, we disable it until we are ready
100 # to use it. This allows the test program to run at full speed until
101 # we get to the first marker function.
105 -re "disable 3\r\n$prompt $" { pass "watchpoint disabled" }
106 -re ".*$prompt $" { fail "watchpoint not disabled" ; return 0 }
107 timeout { fail "watchpoint not disabled (timeout)" ; return 0 }
114 # Test simple watchpoint.
117 proc test_simple_watchpoint {} {
122 # Ensure that the watchpoint is disabled when we startup.
126 -re "disable 3\r\n$prompt $" { }
127 -re ".*$prompt $" { fail "watchpoint not disabled" ; return 0 }
128 timeout { fail "watchpoint not disabled (timeout)" ; return 0 }
131 # Run until we get to the first marker function.
135 -re "The program .* has been started already.* \(y or n\) $" {
139 -re "Starting program.*Breakpoint 1, marker1 .*$prompt $" {}
140 -re ".*$prompt $" { fail "run until marker1 function hit" ; return }
141 timeout { fail "run until marker1 function hit (timeout)" ; return }
144 # After reaching the marker function, enable the watchpoint.
148 -re "enable 3\r\n$prompt $" { pass "watchpoint enabled" }
149 -re ".*$prompt $" { fail "watchpoint not enabled" ; return }
150 timeout { fail "watchpoint not enabled (timeout)" ; return }
153 gdb_test "break func1" "Breakpoint.*at"
154 gdb_test "set \\\$func1_breakpoint_number = \\\$bpnum" ""
156 gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, func1" \
157 "continue to breakpoint at func1"
159 # Continue until the first change, from -1 to 0
163 -re "Continuing.*Watchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$prompt $" {
164 pass "watchpoint hit, first time"
166 -re "Continuing.*Watchpoint.*ival3.*Old value = -1.*New value = 0.*for .count = 0; count < 4; count\[+)\]+ \{.*$prompt $" {
167 # setup_xfail "m68*-*-sunos*" 1836
168 fail "missed first watchpoint"
171 -re "Continuing.*Breakpoint.*func1.*$prompt $" {
172 setup_xfail "m68*-*-*" 2597
173 fail "thought it hit breakpoint at func1 twice"
174 gdb_test "delete \\\$func1_breakpoint_number" ""
175 gdb_test "continue" "\
176 Continuing.*Watchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
177 "watchpoint hit, first time"
179 -re ".*$prompt $" { fail "missed first watchpoint" ; return }
180 timeout { fail "run to first watchpoint (timeout)" ; return }
181 eof { fail "run to first watchpoint (eof)" ; return }
184 gdb_test "delete \\\$func1_breakpoint_number" ""
186 # Continue until the next change, from 0 to 1.
190 -re "Continuing.*Watchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*$prompt $" {
191 pass "watchpoint hit, second time"
193 -re ".*$prompt $" { fail "missed second watchpoint" ; return }
194 timeout { fail "run to second watchpoint (timeout)" ; return }
197 # Continue until the next change, from 1 to 2.
201 -re "Continuing.*Watchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*$prompt $" {
202 pass "watchpoint hit, third time"
204 -re ".*$prompt $" { fail "missed third watchpoint" ; return }
205 timeout { fail "run to third watchpoint (timeout)" ; return }
208 # Continue until the next change, from 2 to 3.
212 -re "Continuing.*Watchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*$prompt $" {
213 pass "watchpoint hit, fourth time"
215 -re ".*$prompt $" { fail "missed fourth watchpoint" ; return }
216 timeout { fail "run to fourth watchpoint (timeout)" ; return }
219 # Continue until the next change, from 3 to 4.
220 # Note that this one is outside the loop.
224 -re "Continuing.*Watchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*$prompt $" {
225 pass "watchpoint hit, fifth time"
227 -re ".*$prompt $" { fail "missed fifth watchpoint" ; return }
228 timeout { fail "run to fifth watchpoint (timeout)" ; return }
231 # Continue until we hit the finishing marker function.
232 # Make sure we hit no more watchpoints.
234 # This used to fail for a29k-amd-udi (PR 2421), but has been fixed.
237 -re "Continuing.*Breakpoint.*marker2 \(\).*$prompt $" { }
238 -re "Continuing.*Watchpoint.*ival3.*$prompt $" {
239 fail "hit a disabled watchpoint" ; return
241 -re ".*$prompt $" { fail "marker2 function missed" ; return }
242 timeout { fail "run to marker2 function (timeout)" ; return }
245 # Disable the watchpoint so we run at full speed until we exit.
249 -re "disable 3\r\n$prompt $" { pass "watchpoint disabled" }
250 -re ".*$prompt $" { fail "watchpoint not disabled" ; return }
251 timeout { fail "watchpoint not disabled (timeout)" ; return }
254 # Run until process exits.
258 -re "Continuing.*Program exited normally.*$prompt $" { }
259 -re ".*$prompt $" { fail "watchpoints not removed" ; return }
260 timeout { fail "looking for process exit (timeout)" }
264 # Test disabling watchpoints.
266 proc test_disabling_watchpoints {} {
273 # Ensure that the watchpoint is disabled when we startup.
277 -re "disable 3\r\n$prompt $" { }
278 -re ".*$prompt $" { fail "watchpoint not disabled" ; return 0 }
279 timeout { fail "watchpoint not disabled (timeout)" ; return 0 }
282 # Run until we get to the first marker function.
286 -re "The program .* has been started already.* \(y or n\) $" {
290 -re "Starting program.*Breakpoint 1, marker1 .*$prompt $" {}
291 -re ".*$prompt $" { fail "run until marker1 function hit" ; return }
292 timeout { fail "run until marker1 function hit (timeout)" ; return }
295 # After reaching the marker function, enable the watchpoint.
299 -re "enable 3\r\n$prompt $" { pass "watchpoint enabled" }
300 -re ".*$prompt $" { fail "watchpoint not enabled" ; return }
301 timeout { fail "watchpoint not enabled (timeout)" ; return }
304 # Continue until the first change, from -1 to 0
305 # Don't check the old value, because on VxWorks the variable value
306 # will not have been reinitialized.
309 -re "Continuing.*Watchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*$prompt $" {
310 pass "watchpoint hit, first time"
312 -re "Continuing.*Watchpoint.*ival3.*Old value = .*New value = 0.*for .count = 0; count < 4; count\[+)]+ \{.*$prompt $" {
313 # setup_xfail "m68*-*-sunos*" 1836
314 fail "missed first watchpoint"
317 -re ".*$prompt $" { fail "missed first watchpoint" ; return }
318 timeout { fail "run to first watchpoint (timeout)" ; return }
321 # Continue until the next change, from 0 to 1.
325 -re "Continuing.*Watchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*$prompt $" {
326 pass "watchpoint hit, second time"
328 -re ".*$prompt $" { fail "missed second watchpoint" ; return }
329 timeout { fail "run to second watchpoint (timeout)" ; return }
332 # Disable the watchpoint but leave breakpoints
336 -re "disable 3\r\n$prompt $" { }
337 -re ".*$prompt $" { fail "watchpoint not disabled" ; return 0 }
338 timeout { fail "watchpoint not disabled (timeout)" ; return 0 }
341 # Check watchpoint list, looking for the entry that confirms the
342 # watchpoint is disabled.
344 send "info watchpoints\n"
346 -re "3\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*$prompt $" {
347 pass "watchpoint disabled in table"
350 fail "disabled watchpoint not found in table"
352 timeout { fail "info watchpoints (timeout)" }
355 # Continue until we hit the finishing marker function.
356 # Make sure we hit no more watchpoints.
360 -re "Continuing.*Breakpoint.*marker2 \[)(\]+.*$prompt $" {
361 pass "disabled watchpoint skipped"
363 -re "Continuing.*Watchpoint.*ival3.*$prompt $" {
364 fail "hit a disabled watchpoint" ; return
366 -re ".*$prompt $" { fail "marker2 function missed" ; return }
367 timeout { fail "run to marker2 function (timeout)" ; return }
372 -re "Continuing.*Program exited normally.*$prompt $" { }
373 -re ".*$prompt $" { fail "watchpoints not removed" ; return }
374 timeout { fail "looking for process exit (timeout)" }
378 # Test stepping and other mundane operations with watchpoints enabled
379 proc test_stepping {} {
382 if [runto marker1] then {
383 gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
385 # Well, let's not be too mundane. It should be a *bit* of a challenge
386 gdb_test "break func2 if 0" "Breakpoint.*at"
387 gdb_test "p \\\$func2_breakpoint_number = \\\$bpnum" "="
389 # The HPPA has a problem here.
390 if [ istarget "hppa*-*-*" ] then {
391 # Don't actually try doing the call, if we do we can't continue.
393 fail "calling function with watchpoint enabled"
395 # The problem is that GDB confuses stepping through the call
396 # dummy with hitting the breakpoint at the end of the call dummy.
397 # Will be fixed once all architectures define
398 # CALL_DUMMY_BREAKPOINT_OFFSET.
400 # This doesn't occur if the call dummy starts with a call,
401 # because we are out of the dummy by the first time the inferior
403 clear_xfail "m68*-*-*"
404 clear_xfail "i*86*-*-*"
405 clear_xfail "vax-*-*"
406 # The following architectures define CALL_DUMMY_BREAKPOINT_OFFSET.
407 clear_xfail "alpha-*-*"
408 clear_xfail "mips*-*-*"
409 clear_xfail "sparc-*-*"
410 gdb_test "p func1 ()" "= 73" \
411 "calling function with watchpoint enabled"
415 # "finish" brings us back to main.
416 # On some targets (e.g. alpha) gdb will stop from the finish in midline
417 # of the marker1 call. This is due to register restoring code on
418 # the alpha and might be caused by stack adjustment instructions
419 # on other targets. In this case we will step once more.
423 -re "Run.*exit from.*marker1.*main.* at" { }
424 default { fail "finish from marker1" ; return }
427 -re "marker1 \[)(\]+;.*$prompt $" {
431 -re "func1 \[)(\]+;.*$prompt $" {
432 pass "finish from marker1"
435 fail "finish from marker1"
437 default { fail "finish from marker1" ; return }
440 gdb_test "next" "for \[(\]+count = 0"
442 # Now test that "until" works. It's a bit tricky to test
443 # "until", because compilers don't always arrange the code
444 # exactly the same way, and we might get slightly different
445 # sequences of statements. But the following should be true
446 # (if not it is a compiler or a debugger bug): The user who
447 # does "until" at every statement of a loop should end up
448 # stepping through the loop once, and the debugger should not
449 # stop for any of the remaining iterations.
451 gdb_test "until" "ival1 = count"
452 gdb_test "until" "ival3 = count"
455 -re "(for \[(\]+count = 0|\}).*$prompt $" {
456 gdb_test "until" "ival1 = count; /. Outside loop ./"
458 -re "ival1 = count; /. Outside loop ./.*$prompt $" {
459 pass "until out of loop"
462 fail "until out of loop"
464 default { fail "until out of loop" ; return }
467 gdb_test "step" "ival2 = count"
471 # Test stepping and other mundane operations with watchpoints enabled
472 proc test_watchpoint_triggered_in_syscall {} {
476 set saved_timeout $timeout
478 # Run until we get to the first marker function.
481 set testname "Watch buffer passed to read syscall"
482 if [runto marker2] then {
483 gdb_test "watch buf\\\[0\\\]" ".*\[Ww\]atchpoint \[0-9\]*: buf"
484 gdb_test "watch buf\\\[1\\\]" ".*\[Ww\]atchpoint \[0-9\]*: buf"
485 gdb_test "watch buf\\\[2\\\]" ".*\[Ww\]atchpoint \[0-9\]*: buf"
486 gdb_test "watch buf\\\[3\\\]" ".*\[Ww\]atchpoint \[0-9\]*: buf"
487 gdb_test "watch buf\\\[4\\\]" ".*\[Ww\]atchpoint \[0-9\]*: buf"
488 gdb_test "break marker4" ".*Breakpoint.*"
490 send "set doread = 1\n"
492 -re ".*$prompt $" { }
493 timeout { fail "set doread" ; return }
496 # Sometimes our string never gets to GDB?!? dejagnu bug? Whatever
497 # the cause we'll set a reasonably short timeout and resend our
498 # string again if we timeout.
503 -re ".*Watchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
504 -re ".*Watchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
505 -re ".*Watchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
506 -re ".*Watchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
507 -re ".*$prompt $" { }
509 set timeout $saved_timeout
515 # Restore the timeout value.
516 set timeout $saved_timeout
518 # Examine the values in buf to see how many watchpoints we
519 # should have printed.
520 send "print buf\[0\]\n"
522 -re ".*= 49.*$prompt $" { set y [expr $y+1] }
524 default { fail "bogus value in buf[0]" }
525 timeout { fail "retrieving contents of buf variable (timeout) }
527 send "print buf\[1\]\n"
529 -re ".*= 50.*$prompt $" { set y [expr $y+1] }
531 default { fail "bogus value in buf[1]" }
532 timeout { fail "retrieving contents of buf variable (timeout) }
534 send "print buf\[2\]\n"
536 -re ".*= 51.*$prompt $" { set y [expr $y+1] }
538 default { fail "bogus value in buf[2]" }
539 timeout { fail "retrieving contents of buf variable (timeout) }
541 send "print buf\[3\]\n"
543 -re ".*= 10.*$prompt $" { set y [expr $y+1] }
545 default { fail "bogus value in buf[3]" }
546 timeout { fail "retrieving contents of buf variable (timeout) }
549 # Did we find what we were looking for? If not, flunk it.
550 if [expr $x==$y] then { pass $testname } else { fail "$testname: Only triggered $x watchpoints, expected $y."}
552 # Continue until we hit the finishing marker function.
553 # Make sure we hit no more watchpoints.
557 -re "Continuing.*Breakpoint.*marker4 \[)(\]+.*$prompt $" {
558 pass "disabled watchpoint skipped"
560 -re "Continuing.*Watchpoint.*$prompt $" {
561 fail "hit suprious watchpoint" ; return
563 -re ".*$prompt $" { fail "marker4 function missed" ; return }
564 timeout { fail "run to marker4 function (timeout)" ; return }
567 # Disable everything so we can finish the program at full speed
570 -re ".*$prompt $" { }
571 timeout { fail "disabling breakpoints (timeout)" }
576 -re "Continuing.*Program exited normally.*$prompt $" { }
577 -re ".*$prompt $" { fail "watchpoints not removed" ; return }
578 timeout { fail "looking for process exit (timeout)" }
583 # Do a simple test of of watching through a pointer when the pointer
584 # itself changes. Should add some more complicated stuff here.
586 proc test_complex_watchpoint {} {
589 set testname "Test complex watchpoint"
590 if [runto marker4] then {
591 gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
592 gdb_test "break marker5" ".*Breakpoint.*"
596 -re "Continuing.*Watchpoint.*ptr1->val.*Old value = 1.*New value = 2.*$prompt $" { pass $testname }
597 default { fail $testname ; return }
600 # Continue until we hit the marker5 function.
601 # Make sure we hit no more watchpoints.
605 -re "Continuing.*Breakpoint.*marker5 \[)(\]+.*$prompt $" {
606 pass "did not trigger wrong watchpoint"
608 -re "Continuing.*Watchpoint.*$prompt $" {
609 fail "hit wrong watchpoint" ; return
611 -re ".*$prompt $" { fail "marker5 function missed" ; return }
612 timeout { fail "run to marker5 function (timeout)" ; return }
615 # Disable everything so we can finish the program at full speed
618 -re ".*$prompt $" { }
619 timeout { fail "disabling breakpoints (timeout)" }
624 -re "Continuing.*Program exited normally.*$prompt $" { }
625 -re ".*$prompt $" { fail "watchpoints not removed" ; return }
626 timeout { fail "looking for process exit (timeout)" }
631 # Start with a fresh gdb.
635 gdb_reinitialize_dir $srcdir/$subdir
636 gdb_load $objdir/$subdir/$binfile
638 if [initialize] then {
640 # Preserve the old timeout, and set a new one that should be
641 # sufficient to step from marker1 to marker2 with watchpoints
644 set timeoutsave $timeout
647 test_simple_watchpoint
649 # The IDT/sim monitor only has 8 (!) open files, of which it uses
650 # 4 (!). So we have to make sure one program exits before
651 # starting another one.
652 if [istarget "mips-idt-*"] then {
655 gdb_reinitialize_dir $srcdir/$subdir
656 gdb_load $objdir/$subdir/$binfile
660 if [istarget "a29k-*-udi"] then {
661 # FIXME: If PR 2415 is fixed, this is not needed.
663 gdb_load $objdir/$subdir/$binfile
666 test_disabling_watchpoints
669 if [istarget "mips-idt-*"] then {
672 gdb_reinitialize_dir $srcdir/$subdir
673 gdb_load $objdir/$subdir/$binfile
680 if [istarget "mips-idt-*"] then {
683 gdb_reinitialize_dir $srcdir/$subdir
684 gdb_load $objdir/$subdir/$binfile
688 # This test hasn't been tested on anything but the PA.
689 if [istarget "hppa*-*-*"] then {
690 test_watchpoint_triggered_in_syscall
694 if [istarget "mips-idt-*"] then {
697 gdb_reinitialize_dir $srcdir/$subdir
698 gdb_load $objdir/$subdir/$binfile
702 # This test hasn't been tested on anything but the PA.
703 if [istarget "hppa*-*-*"] then {
704 test_complex_watchpoint
707 # Restore the preserved old timeout value.
709 set timeout $timeoutsave
712 if [istarget "a29k-*-udi"] then {
713 # FIXME: If PR 2415 is fixed, this is not needed.