1 # Copyright (C) 1992, 1994 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:
29 set testfile "watchpoint"
30 set srcfile ${testfile}.c
31 set binfile ${objdir}/${subdir}/${testfile}
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
33 perror "Couldn't compile ${srcfile}"
37 # Prepare for watchpoint tests by setting up two breakpoints and one
40 # We use breakpoints at marker functions to get past all the startup code,
41 # so we can get to the watchpoints in a reasonable amount of time from a
42 # known starting point.
44 # For simplicity, so we always know how to reference specific breakpoints or
45 # watchpoints by number, we expect a particular ordering and numbering of
46 # each in the combined breakpoint/watchpoint table, as follows:
49 # 1 Breakpoint marker1()
50 # 2 Breakpoint marker2()
59 if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] {
64 if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] {
69 if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] {
74 if [gdb_test "watch ival3" ".*\[Ww\]atchpoint 3: ival3" "set watchpoint on ival3" ] {
79 # "info watch" is the same as "info break"
81 if [gdb_test "info watch" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] {
86 # After installing the watchpoint, we disable it until we are ready
87 # to use it. This allows the test program to run at full speed until
88 # we get to the first marker function.
90 if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] {
99 # Test simple watchpoint.
102 proc test_simple_watchpoint {} {
108 # Ensure that the watchpoint is disabled when we startup.
110 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] {
115 # Run until we get to the first marker function.
120 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
121 pass "run to marker1 in test_simple_watchpoint"
123 -re ".*$gdb_prompt $" {
124 fail "run to marker1 in test_simple_watchpoint"
128 fail "run to marker1 in test_simple_watchpoint (timeout)"
133 # After reaching the marker function, enable the watchpoint.
135 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] {
140 gdb_test "break func1" "Breakpoint.*at.*"
141 gdb_test "set \$func1_breakpoint_number = \$bpnum" ""
143 gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, func1.*" \
144 "continue to breakpoint at func1"
146 # Continue until the first change, from -1 to 0
150 -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
151 pass "watchpoint hit, first time"
153 -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
154 setup_xfail "m68*-*-*" 2597
155 fail "thought it hit breakpoint at func1 twice"
156 gdb_test "delete \$func1_breakpoint_number" ""
157 gdb_test "continue" "\
158 Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
159 "watchpoint hit, first time"
161 -re ".*$gdb_prompt $" { fail "watchpoint hit, first time" ; return }
162 timeout { fail "watchpoint hit, first time (timeout)" ; return }
163 eof { fail "watchpoint hit, first time (eof)" ; return }
166 gdb_test "delete \$func1_breakpoint_number" ""
168 # Continue until the next change, from 0 to 1.
169 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time"
171 # Continue until the next change, from 1 to 2.
172 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time"
174 # Continue until the next change, from 2 to 3.
175 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time"
177 # Continue until the next change, from 3 to 4.
178 # Note that this one is outside the loop.
180 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time"
182 # Continue until we hit the finishing marker function.
183 # Make sure we hit no more watchpoints.
185 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \(\).*" \
186 "continue to marker2"
188 # Disable the watchpoint so we run at full speed until we exit.
190 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] {
195 # Run until process exits.
197 if $noresults==1 then { return }
199 gdb_test "cont" "Continuing.*Program exited normally.*" \
200 "continue to exit in test_simple_watchpoint"
203 # Test disabling watchpoints.
205 proc test_disabling_watchpoints {} {
213 # Ensure that the watchpoint is disabled when we startup.
215 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] {
220 # Run until we get to the first marker function.
225 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
226 pass "run to marker1 in test_disabling_watchpoints"
228 -re ".*$gdb_prompt $" {
229 fail "run to marker1 in test_disabling_watchpoints"
233 fail "run to marker1 in test_disabling_watchpoints (timeout)"
238 # After reaching the marker function, enable the watchpoint.
240 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] {
245 # Continue until the first change, from -1 to 0
246 # Don't check the old value, because on VxWorks the variable value
247 # will not have been reinitialized.
248 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, first time"
250 # Continue until the next change, from 0 to 1.
251 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"
253 # Disable the watchpoint but leave breakpoints
255 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] {
260 # Check watchpoint list, looking for the entry that confirms the
261 # watchpoint is disabled.
262 gdb_test "info watchpoints" "3\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
264 # Continue until we hit the finishing marker function.
265 # Make sure we hit no more watchpoints.
266 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \
267 "disabled watchpoint skipped"
269 if $noresults==1 then { return }
271 gdb_test "cont" "Continuing.*Program exited normally.*" \
272 "continue to exit in test_disabling_watchpoints"
275 # Test stepping and other mundane operations with watchpoints enabled
276 proc test_stepping {} {
279 if [runto marker1] then {
280 gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
282 # Well, let's not be too mundane. It should be a *bit* of a challenge
283 gdb_test "break func2 if 0" "Breakpoint.*at.*"
284 gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*"
286 # The HPPA has a problem here if it's not using hardware watchpoints
287 if {[ istarget "hppa*-*-*" ] && ![ istarget "hppa*-*-*bsd*" ]} then {
288 # Don't actually try doing the call, if we do we can't continue.
290 fail "calling function with watchpoint enabled"
292 # The problem is that GDB confuses stepping through the call
293 # dummy with hitting the breakpoint at the end of the call dummy.
294 # Will be fixed once all architectures define
295 # CALL_DUMMY_BREAKPOINT_OFFSET.
297 # This doesn't occur if the call dummy starts with a call,
298 # because we are out of the dummy by the first time the inferior
300 clear_xfail "m68*-*-*"
301 clear_xfail "i*86*-*-*"
302 clear_xfail "vax-*-*"
303 # The following architectures define CALL_DUMMY_BREAKPOINT_OFFSET.
304 clear_xfail "alpha-*-*"
305 clear_xfail "mips*-*-*"
306 clear_xfail "sparc-*-*"
307 clear_xfail "hppa*-*-*bsd*"
308 gdb_test "p func1 ()" "= 73" \
309 "calling function with watchpoint enabled"
313 # "finish" brings us back to main.
314 # On some targets (e.g. alpha) gdb will stop from the finish in midline
315 # of the marker1 call. This is due to register restoring code on
316 # the alpha and might be caused by stack adjustment instructions
317 # on other targets. In this case we will step once more.
322 -re "Run.*exit from.*marker1.* at" { }
323 default { fail "finish from marker1" ; return }
327 -re "marker1 \\(\\);.*$gdb_prompt $" {
331 -re "func1 \\(\\);.*$gdb_prompt $" {
332 pass "finish from marker1"
334 -re ".*$gdb_prompt $" {
335 fail "finish from marker1"
337 default { fail "finish from marker1" ; return }
340 gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp"
342 # Now test that "until" works. It's a bit tricky to test
343 # "until", because compilers don't always arrange the code
344 # exactly the same way, and we might get slightly different
345 # sequences of statements. But the following should be true
346 # (if not it is a compiler or a debugger bug): The user who
347 # does "until" at every statement of a loop should end up
348 # stepping through the loop once, and the debugger should not
349 # stop for any of the remaining iterations.
351 gdb_test "until" "ival1 = count.*" "until to ival1 assignment"
352 gdb_test "until" "ival3 = count.*" "until to ival3 assignment"
355 -re "(for \\(count = 0|\}).*$gdb_prompt $" {
356 gdb_test "until" "ival1 = count; /. Outside loop ./" \
359 -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
360 pass "until out of loop"
362 -re ".*$gdb_prompt $" {
363 fail "until out of loop"
365 default { fail "until out of loop" ; return }
368 gdb_test "step" "ival2 = count.*" "step to ival2 assignment"
372 # Test stepping and other mundane operations with watchpoints enabled
373 proc test_watchpoint_triggered_in_syscall {} {
379 verbose "Skipping test_watchpoint_triggered_in_syscall due to noinferiorio"
382 # Run until we get to the first marker function.
385 set testname "Watch buffer passed to read syscall"
386 if [runto marker2] then {
387 gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]"
388 gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]"
389 gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]"
390 gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]"
391 gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]"
392 gdb_test "break marker4" ".*Breakpoint.*"
394 gdb_test "set doread = 1" ""
396 # If we send_gdb "123\n" before gdb has switched the tty, then it goes
397 # to gdb, not the inferior, and we lose. So that is why we have
398 # watchpoint.c prompt us, so we can wait for that prompt.
399 if [gdb_test "continue" "Continuing\\.\r\ntype stuff for buf now:" "continue to read" ] {
405 -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
406 -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
407 -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
408 -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
409 -re ".*$gdb_prompt $" { pass "sent 123" }
410 timeout { fail "sent 123 (timeout)" }
413 # Examine the values in buf to see how many watchpoints we
414 # should have printed.
415 send_gdb "print buf\[0\]\n"
417 -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[0\]"}
418 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[0\]"}
419 -re ".*$gdb_prompt $" { fail "print buf\[0\]"}
420 default { fail "print buf\[0\]"}
422 send_gdb "print buf\[1\]\n"
424 -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[1\]"}
425 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[1\]"}
426 -re ".*$gdb_prompt $" { fail "print buf\[1\]"}
427 default { fail "print buf\[1\]"}
429 send_gdb "print buf\[2\]\n"
431 -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[2\]"}
432 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[2\]"}
433 -re ".*$gdb_prompt $" { fail "print buf\[2\]"}
434 default { fail "print buf\[2\]"}
436 send_gdb "print buf\[3\]\n"
438 -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[3\]"}
439 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[3\]"}
440 -re ".*$gdb_prompt $" { fail "print buf\[3\]" }
441 default { fail "print buf\[3\]" }
444 # Did we find what we were looking for? If not, flunk it.
445 if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"}
447 # Continue until we hit the finishing marker function.
448 # Make sure we hit no more watchpoints.
449 gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \
450 "continue to marker4"
452 # Disable everything so we can finish the program at full speed
453 gdb_test "disable" "" "disable in test_watchpoint_triggered_in_syscall"
455 if $noresults==1 then { return }
457 gdb_test "cont" "Continuing.*Program exited normally.*" \
458 "continue to exit in test_watchpoint_triggered_in_syscall"
462 # Do a simple test of of watching through a pointer when the pointer
463 # itself changes. Should add some more complicated stuff here.
465 proc test_complex_watchpoint {} {
469 if [runto marker4] then {
470 gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
471 gdb_test "break marker5" ".*Breakpoint.*"
473 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "Test complex watchpoint"
475 # Continue until we hit the marker5 function.
476 # Make sure we hit no more watchpoints.
478 gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \
479 "did not trigger wrong watchpoint"
481 # Disable everything so we can finish the program at full speed
482 gdb_test "disable" "" "disable in test_complex_watchpoint"
484 if $noresults==1 then { return }
486 gdb_test "cont" "Continuing.*Program exited normally.*" \
487 "continue to exit in test_complex_watchpoint"
491 # Start with a fresh gdb.
494 gdb_reinitialize_dir $srcdir/$subdir
497 verbose "Timeout now 600 sec.\n"
499 if [initialize] then {
501 test_simple_watchpoint
503 # The IDT/sim monitor only has 8 (!) open files, of which it uses
504 # 4 (!). So we have to make sure one program exits before
505 # starting another one.
506 if [istarget "mips-idt-*"] then {
509 gdb_reinitialize_dir $srcdir/$subdir
514 test_disabling_watchpoints
517 if [istarget "mips-idt-*"] then {
520 gdb_reinitialize_dir $srcdir/$subdir
528 if [istarget "mips-idt-*"] then {
531 gdb_reinitialize_dir $srcdir/$subdir
536 # Only enabled for some targets merely because it has not been tested
538 # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4
539 # breakpoint before stopping for the watchpoint. I don't know why.
540 if {[istarget "hppa*-*-*"]} then {
541 test_watchpoint_triggered_in_syscall
545 if [istarget "mips-idt-*"] then {
548 gdb_reinitialize_dir $srcdir/$subdir
553 # Only enabled for some targets merely because it has not been tested
555 if {[istarget "hppa*-*-*"] || [istarget "sparc*-*-sunos*"]} then {
556 test_complex_watchpoint