1 # Copyright (C) 1992, 1994, 1997, 1998 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 testfile "watchpoint"
30 set srcfile ${testfile}.c
31 set binfile ${objdir}/${subdir}/${testfile}
34 if [get_compiler_info ${binfile}] {
38 # if we are on HPUX and we are not compiled with gcc, then skip these tests.
40 if [istarget hppa*-*-hpux*] {
47 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
48 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
51 # Prepare for watchpoint tests by setting up two breakpoints and one
54 # We use breakpoints at marker functions to get past all the startup code,
55 # so we can get to the watchpoints in a reasonable amount of time from a
56 # known starting point.
58 # For simplicity, so we always know how to reference specific breakpoints or
59 # watchpoints by number, we expect a particular ordering and numbering of
60 # each in the combined breakpoint/watchpoint table, as follows:
63 # 1 Breakpoint marker1()
64 # 2 Breakpoint marker2()
73 if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] {
78 if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] {
83 if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] {
88 if [gdb_test "watch ival3" ".*\[Ww\]atchpoint 3: ival3" "set watchpoint on ival3" ] {
93 # "info watch" is the same as "info break"
95 if [gdb_test "info watch" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] {
100 # After installing the watchpoint, we disable it until we are ready
101 # to use it. This allows the test program to run at full speed until
102 # we get to the first marker function.
104 if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] {
113 # Test simple watchpoint.
116 proc test_simple_watchpoint {} {
121 # Ensure that the watchpoint is disabled when we startup.
123 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] {
128 # Run until we get to the first marker function.
133 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
134 pass "run to marker1 in test_simple_watchpoint"
136 -re ".*$gdb_prompt $" {
137 fail "run to marker1 in test_simple_watchpoint"
141 fail "run to marker1 in test_simple_watchpoint (timeout)"
146 # After reaching the marker function, enable the watchpoint.
148 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] {
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.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
164 pass "watchpoint hit, first time"
166 -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
167 setup_xfail "m68*-*-*" 2597
168 fail "thought it hit breakpoint at func1 twice"
169 gdb_test "delete \$func1_breakpoint_number" ""
170 gdb_test "continue" "\
171 Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
172 "watchpoint hit, first time"
174 -re ".*$gdb_prompt $" { fail "watchpoint hit, first time" ; return }
175 timeout { fail "watchpoint hit, first time (timeout)" ; return }
176 eof { fail "watchpoint hit, first time (eof)" ; return }
179 gdb_test "delete \$func1_breakpoint_number" ""
181 # Continue until the next change, from 0 to 1.
182 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time"
184 # Continue until the next change, from 1 to 2.
185 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time"
187 # Continue until the next change, from 2 to 3.
188 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time"
190 # Continue until the next change, from 3 to 4.
191 # Note that this one is outside the loop.
193 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time"
195 # Continue until we hit the finishing marker function.
196 # Make sure we hit no more watchpoints.
198 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \(\).*" \
199 "continue to marker2"
201 # Disable the watchpoint so we run at full speed until we exit.
203 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] {
208 # Run until process exits.
210 if [target_info exists gdb,noresults] { return }
212 gdb_continue_to_end "continue to exit in test_simple_watchpoint"
215 # Test disabling watchpoints.
217 proc test_disabling_watchpoints {} {
224 # Ensure that the watchpoint is disabled when we startup.
226 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] {
231 # Run until we get to the first marker function.
236 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
237 pass "run to marker1 in test_disabling_watchpoints"
239 -re ".*$gdb_prompt $" {
240 fail "run to marker1 in test_disabling_watchpoints"
244 fail "run to marker1 in test_disabling_watchpoints (timeout)"
249 # After reaching the marker function, enable the watchpoint.
251 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] {
256 # Continue until the first change, from -1 to 0
257 # Don't check the old value, because on VxWorks the variable value
258 # will not have been reinitialized.
259 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, first time"
261 # Continue until the next change, from 0 to 1.
262 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"
264 # Disable the watchpoint but leave breakpoints
266 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] {
271 # Check watchpoint list, looking for the entry that confirms the
272 # watchpoint is disabled.
273 gdb_test "info watchpoints" "3\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
275 # Continue until we hit the finishing marker function.
276 # Make sure we hit no more watchpoints.
277 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \
278 "disabled watchpoint skipped"
280 if [target_info exists gdb,noresults] { return }
282 gdb_continue_to_end "continue to exit in test_disabling_watchpoints"
285 # Test stepping and other mundane operations with watchpoints enabled
286 proc test_stepping {} {
289 if [runto marker1] then {
290 gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
292 # Well, let's not be too mundane. It should be a *bit* of a challenge
293 gdb_test "break func2 if 0" "Breakpoint.*at.*"
294 gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*"
296 # The HPPA has a problem here if it's not using hardware watchpoints
297 if {[ istarget "hppa*-*-*" ] && ![ istarget "hppa*-*-*bsd*" ]} then {
298 # Don't actually try doing the call, if we do we can't continue.
300 fail "calling function with watchpoint enabled"
302 # The problem is that GDB confuses stepping through the call
303 # dummy with hitting the breakpoint at the end of the call dummy.
304 # Will be fixed once all architectures define
305 # CALL_DUMMY_BREAKPOINT_OFFSET.
307 # This doesn't occur if the call dummy starts with a call,
308 # because we are out of the dummy by the first time the inferior
310 clear_xfail "d10v*-*-*"
311 clear_xfail "m68*-*-*"
312 clear_xfail "i*86*-*-*"
313 clear_xfail "vax-*-*"
314 # The following architectures define CALL_DUMMY_BREAKPOINT_OFFSET.
315 clear_xfail "alpha-*-*"
316 clear_xfail "mips*-*-*"
317 clear_xfail "sparc-*-*"
318 clear_xfail "hppa*-*-*bsd*"
319 # It works with the generic inferior function calling code too.
320 clear_xfail "mn10200*-*-*"
321 clear_xfail "mn10300*-*-*"
322 gdb_test "p func1 ()" "= 73" \
323 "calling function with watchpoint enabled"
327 # "finish" brings us back to main.
328 # On some targets (e.g. alpha) gdb will stop from the finish in midline
329 # of the marker1 call. This is due to register restoring code on
330 # the alpha and might be caused by stack adjustment instructions
331 # on other targets. In this case we will step once more.
336 -re "Run.*exit from.*marker1.* at" { }
337 default { fail "finish from marker1" ; return }
341 -re "marker1 \\(\\);.*$gdb_prompt $" {
345 -re "func1 \\(\\);.*$gdb_prompt $" {
346 pass "finish from marker1"
348 -re ".*$gdb_prompt $" {
349 fail "finish from marker1"
351 default { fail "finish from marker1" ; return }
354 gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp"
356 # Now test that "until" works. It's a bit tricky to test
357 # "until", because compilers don't always arrange the code
358 # exactly the same way, and we might get slightly different
359 # sequences of statements. But the following should be true
360 # (if not it is a compiler or a debugger bug): The user who
361 # does "until" at every statement of a loop should end up
362 # stepping through the loop once, and the debugger should not
363 # stop for any of the remaining iterations.
365 gdb_test "until" "ival1 = count.*" "until to ival1 assignment"
366 gdb_test "until" "ival3 = count.*" "until to ival3 assignment"
369 -re "(for \\(count = 0|\}).*$gdb_prompt $" {
370 gdb_test "until" "ival1 = count; /. Outside loop ./" \
373 -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
374 pass "until out of loop"
376 -re ".*$gdb_prompt $" {
377 fail "until out of loop"
379 default { fail "until out of loop" ; return }
382 gdb_test "step" "ival2 = count.*" "step to ival2 assignment"
386 # Test stepping and other mundane operations with watchpoints enabled
387 proc test_watchpoint_triggered_in_syscall {} {
390 if [target_info exists gdb,noinferiorio] {
391 verbose "Skipping test_watchpoint_triggered_in_syscall due to noinferiorio"
394 # Run until we get to the first marker function.
397 set testname "Watch buffer passed to read syscall"
398 if [runto marker2] then {
399 gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]"
400 gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]"
401 gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]"
402 gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]"
403 gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]"
404 gdb_test "break marker4" ".*Breakpoint.*"
406 gdb_test "set doread = 1" ""
408 # If we send_gdb "123\n" before gdb has switched the tty, then it goes
409 # to gdb, not the inferior, and we lose. So that is why we have
410 # watchpoint.c prompt us, so we can wait for that prompt.
411 send_gdb "continue\n";
413 -re "Continuing\\.\r\ntype stuff for buf now:" {
414 pass "continue to read"
417 fail "continue to read";
424 -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
425 -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
426 -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
427 -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
428 -re ".*$gdb_prompt $" { pass "sent 123" }
429 timeout { fail "sent 123 (timeout)" }
432 # Examine the values in buf to see how many watchpoints we
433 # should have printed.
434 send_gdb "print buf\[0\]\n"
436 -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[0\]"}
437 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[0\]"}
438 -re ".*$gdb_prompt $" { fail "print buf\[0\]"}
439 default { fail "print buf\[0\]"}
441 send_gdb "print buf\[1\]\n"
443 -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[1\]"}
444 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[1\]"}
445 -re ".*$gdb_prompt $" { fail "print buf\[1\]"}
446 default { fail "print buf\[1\]"}
448 send_gdb "print buf\[2\]\n"
450 -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[2\]"}
451 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[2\]"}
452 -re ".*$gdb_prompt $" { fail "print buf\[2\]"}
453 default { fail "print buf\[2\]"}
455 send_gdb "print buf\[3\]\n"
457 -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[3\]"}
458 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[3\]"}
459 -re ".*$gdb_prompt $" { fail "print buf\[3\]" }
460 default { fail "print buf\[3\]" }
463 # Did we find what we were looking for? If not, flunk it.
464 if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"}
466 # Continue until we hit the finishing marker function.
467 # Make sure we hit no more watchpoints.
468 gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \
469 "continue to marker4"
471 # Disable everything so we can finish the program at full speed
472 gdb_test "disable" "" "disable in test_watchpoint_triggered_in_syscall"
474 if [target_info exists gdb,noresults] { return }
476 gdb_continue_to_end "continue to exit in test_watchpoint_triggered_in_syscall"
480 # Do a simple test of of watching through a pointer when the pointer
481 # itself changes. Should add some more complicated stuff here.
483 proc test_complex_watchpoint {} {
486 if [runto marker4] then {
487 gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
488 gdb_test "break marker5" ".*Breakpoint.*"
490 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "Test complex watchpoint"
492 # Continue until we hit the marker5 function.
493 # Make sure we hit no more watchpoints.
495 gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \
496 "did not trigger wrong watchpoint"
498 # Disable everything so we can finish the program at full speed
499 gdb_test "disable" "" "disable in test_complex_watchpoint"
501 if [target_info exists gdb,noresults] { return }
504 gdb_continue_to_end "continue to exit in test_complex_watchpoint"
508 # Start with a fresh gdb.
511 gdb_reinitialize_dir $srcdir/$subdir
514 verbose "Timeout now 600 sec.\n"
516 if [initialize] then {
518 test_simple_watchpoint
520 # The IDT/sim monitor only has 8 (!) open files, of which it uses
521 # 4 (!). So we have to make sure one program exits before
522 # starting another one.
523 if [istarget "mips-idt-*"] then {
526 gdb_reinitialize_dir $srcdir/$subdir
531 test_disabling_watchpoints
534 if [istarget "mips-idt-*"] then {
537 gdb_reinitialize_dir $srcdir/$subdir
542 if ![target_info exists gdb,cannot_call_functions] {
546 if [istarget "mips-idt-*"] then {
549 gdb_reinitialize_dir $srcdir/$subdir
555 # Only enabled for some targets merely because it has not been tested
557 # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4
558 # breakpoint before stopping for the watchpoint. I don't know why.
559 if {[istarget "hppa*-*-*"]} then {
560 test_watchpoint_triggered_in_syscall
564 if [istarget "mips-idt-*"] then {
567 gdb_reinitialize_dir $srcdir/$subdir
572 # Only enabled for some targets merely because it has not been tested
574 if {[istarget "hppa*-*-*"] || \
575 [istarget "sparc*-*-sunos*"] || \
576 [istarget "m32r-*-*"]} then {
577 test_complex_watchpoint