import gdb-1999-12-13 snapshot
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / watchpoint.exp
index 616fb63f417afc6da5a19b5e9f712a4937fd1958..39c388e287e5fb1ffbfb8a3a9a72668f74331446 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 1992, 1994 Free Software Foundation, Inc.
+# Copyright (C) 1992, 1994, 1997, 1998 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -12,7 +12,7 @@
 # 
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
 
 # Please email any bugs, comments, and/or additions to this file to:
 # bug-gdb@prep.ai.mit.edu
@@ -29,11 +29,17 @@ set bug_id 0
 set testfile "watchpoint"
 set srcfile ${testfile}.c
 set binfile ${objdir}/${subdir}/${testfile}
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
-    perror "Couldn't compile ${srcfile}"
+
+set wp_set 1
+
+if [get_compiler_info ${binfile}] {
     return -1
 }
 
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
 # Prepare for watchpoint tests by setting up two breakpoints and one
 # watchpoint.
 #
@@ -51,71 +57,64 @@ if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
 #      3               Watchpoint      ival3
 
 proc initialize {} {
-    global prompt
+    global gdb_prompt
     global hex
     global decimal
     global srcfile
+    global wp_set
 
-    send_gdb "break marker1\n"
-    expect {
-       -re "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*$prompt $" {
-           pass "set breakpoint at marker1"
-       }
-       -re ".*$prompt $" { fail "set breakpoint at marker1" ; return 0 }
-       timeout { fail "set breakpoint at marker1 (timeout)" ; return 0 }
+    if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] { 
+      return 0; 
     }
 
-    send_gdb "break marker2\n"
-    expect {
-       -re "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*$prompt $" {
-           pass "set breakpoint at marker2"
-       }
-       -re ".*$prompt $" { fail "set breakpoint at marker2" ; return 0 }
-       timeout { fail "set breakpoint at marker2 (timeout)" ; return 0 }
+
+    if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] { 
+      return 0; 
     }
 
-    send_gdb "info break\n"
-    expect {
-       -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n$prompt $" { pass "info break in watchpoint.exp" }
-       -re ".*$prompt $" { fail "info break in watchpoint.exp" ; return 0 }
-       timeout { fail "info break in watchpoint.exp (timeout)" ; return 0 }
+
+    if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] { 
+      return 0; 
     }
 
+
+    # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
+    # before running can cause the inferior to croak on HP-UX 11.0 for
+    # reasons yet unknown, we've disabled the ability to set watches
+    # without a running inferior.  Verify the restriction. 
+    #
     send_gdb "watch ival3\n"
-    expect {
-       -re ".*\[Ww\]atchpoint 3: ival3\r\n$prompt $" { 
-           pass "set watchpoint on ival3"
-       }
-       -re ".*$prompt $" { fail "set watchpoint on ival3" ; return 0 }
-       timeout { fail "set watchpoint on ival3 (timeout)" ; return 0 }
+    gdb_expect {
+        -re ".*\[Ww\]atchpoint 3: ival3.*$gdb_prompt $" {
+            pass "set watchpoint on ival3"
+        }
+        -re "warning: can't do that without a running program; try \"break main\", \"run\" first.*$gdb_prompt $" {
+            pass "set watchpoint on ival3"
+            set wp_set 0
+            return 1
+        }
+        timeout {
+            fail "(timeout) set watchpoint on ival3"
+            return 0
+        }
     }
 
     # "info watch" is the same as "info break"
 
-    send_gdb "info watch\n"
-    expect {
-       -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3\r\n$prompt $" {
-           pass "watchpoint found in watchpoint/breakpoint table"
-       }
-       -re ".*$prompt $" {
-           fail "watchpoint found in watchpoint/breakpoint table" ; return 0
-       }
-       timeout {
-          fail "watchpoint found in watchpoint/breakpoint table (timeout)" ; return 0
-       }
+    if [gdb_test "info watch" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] { 
+      return 0; 
     }
 
+
     # After installing the watchpoint, we disable it until we are ready
     # to use it.  This allows the test program to run at full speed until
     # we get to the first marker function.
 
-    send_gdb "disable 3\n"
-    expect {
-       -re "disable 3\[\r\n\]+$prompt $" { pass "disable watchpoint" }
-       -re ".*$prompt $" { fail "disable watchpoint" ; return 0 }
-       timeout { fail "disable watchpoint (timeout)" ; return 0 }
+    if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] { 
+      return 0; 
     }
 
+
     return 1
 }
 
@@ -124,37 +123,29 @@ proc initialize {} {
 #
 
 proc test_simple_watchpoint {} {
-    global prompt
+    global gdb_prompt
     global hex
     global decimal
-    global noresults
+    global wp_set
 
     # Ensure that the watchpoint is disabled when we startup.
 
-    send_gdb "disable 3\n"
-    expect {
-       -re "^disable 3\[\r\n\]+$prompt $" {
-           pass "disable watchpoint in test_simple_watchpoint"
-       }
-       -re ".*$prompt $" {
-           fail "disable watchpoint in test_simple_watchpoint"
-           return 0
-       }
-       timeout {
-           fail "disable watchpoint in test_simple_watchpoint (timeout)"
-           return 0
+    if { $wp_set } {
+        if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] { 
+           return 0; 
        }
     }
 
+
     # Run until we get to the first marker function.
 
     gdb_run_cmd
     set timeout 600
-    expect {
-       -re "Breakpoint 1, marker1 .*$prompt $" {
+    gdb_expect {
+       -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
            pass "run to marker1 in test_simple_watchpoint"
        }
-       -re ".*$prompt $" {
+       -re ".*$gdb_prompt $" {
            fail "run to marker1 in test_simple_watchpoint"
            return
        }
@@ -164,15 +155,58 @@ proc test_simple_watchpoint {} {
        }
     }
 
+    if { !$wp_set } {
+       # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
+       # before running can cause the inferior to croak on HP-UX 11.0
+       # for reasons yet unknown, we've disabled the ability to set 
+       # watches without a running inferior.  The following testpoints used
+       # to be in [initialize].
+       #
+       send_gdb "watch ival3\n"
+       gdb_expect {
+           -re ".*\[Ww\]atchpoint 3: ival3\r\n$gdb_prompt $" { 
+               pass "set watchpoint on ival3"
+           }
+           -re ".*$gdb_prompt $" { fail "set watchpoint on ival3"  }
+           timeout { fail "set watchpoint on ival3 (timeout)"  }
+       }
+
+        set wp_set 1
+
+       # "info watch" is the same as "info break"
+
+       send_gdb "info watch\n"
+       gdb_expect {
+           -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3\r\n$gdb_prompt $" {
+               pass "watchpoint found in watchpoint/breakpoint table"
+           }
+           -re ".*$gdb_prompt $" {
+               fail "watchpoint found in watchpoint/breakpoint table"
+           }
+           timeout {
+              fail "watchpoint found in watchpoint/breakpoint table"
+           }
+       }
+
+       # After installing the watchpoint, we disable it until we are ready
+       # to use it.  This allows the test program to run at full speed until
+       # we get to the first marker function.
+
+       send_gdb "disable 3\n"
+       gdb_expect {
+           -re "disable 3\[\r\n\]+$gdb_prompt $" { pass "disable watchpoint" }
+           -re ".*$gdb_prompt $" { fail "disable watchpoint"  }
+           timeout { fail "disable watchpoint (timeout)"  }
+       }
+    }
+
     # After reaching the marker function, enable the watchpoint.
 
-    send_gdb "enable 3\n"
-    expect {
-       -re "^enable 3\[\r\n\]+$prompt $" { pass "enable watchpoint" }
-       -re ".*$prompt $" { fail "enable watchpoint" ; return }
-       timeout { fail "enable watchpoint (timeout)" ; return }
+    if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] { 
+      return ; 
     }
 
+
     gdb_test "break func1" "Breakpoint.*at.*"
     gdb_test "set \$func1_breakpoint_number = \$bpnum" ""
 
@@ -182,11 +216,11 @@ proc test_simple_watchpoint {} {
     # Continue until the first change, from -1 to 0
 
     send_gdb "cont\n"
-    expect {
-       -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$prompt $" {
+    gdb_expect {
+       -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
            pass "watchpoint hit, first time"
        }
-       -re "Continuing.*Breakpoint.*func1.*$prompt $" {
+       -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
            setup_xfail "m68*-*-*" 2597
            fail "thought it hit breakpoint at func1 twice"
            gdb_test "delete \$func1_breakpoint_number" ""
@@ -194,27 +228,42 @@ proc test_simple_watchpoint {} {
 Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
                "watchpoint hit, first time"
        }
-       -re ".*$prompt $" { fail "watchpoint hit, first time" ; return }
+       -re ".*$gdb_prompt $" { fail "watchpoint hit, first time" ; return }
        timeout { fail "watchpoint hit, first time (timeout)" ; return }
        eof { fail "watchpoint hit, first time (eof)" ; return }
     }
 
+    # Check that the hit count is reported correctly
+    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 1 time.*" "Watchpoint hit count is 1"
+
     gdb_test "delete \$func1_breakpoint_number" ""
 
     # Continue until the next change, from 0 to 1.
     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time"
 
+    # Check that the hit count is reported correctly
+    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 2 times.*" "Watchpoint hit count is 2"
+
     # Continue until the next change, from 1 to 2.
     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time"
+
+    # Check that the hit count is reported correctly
+    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 3 times.*" "Watchpoint hit count is 3"
     
     # Continue until the next change, from 2 to 3.
     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time"
 
+    # Check that the hit count is reported correctly
+    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 4 times.*" "Watchpoint hit count is 4"
+
     # Continue until the next change, from 3 to 4.
     # Note that this one is outside the loop.
 
     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time"
 
+    # Check that the hit count is reported correctly
+    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 5 times.*" "Watchpoint hit count is 5"
+
     # Continue until we hit the finishing marker function.
     # Make sure we hit no more watchpoints.
 
@@ -223,57 +272,46 @@ Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count
 
     # Disable the watchpoint so we run at full speed until we exit.
 
-    send_gdb "disable 3\n"
-    expect {
-       -re "^disable 3\[\r\n\]+$prompt $" { pass "watchpoint disabled" }
-       -re ".*$prompt $" { fail "watchpoint disabled" ; return }
-       timeout { fail "watchpoint disabled (timeout)" ; return }
+    if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] { 
+      return ; 
     }
 
+
     # Run until process exits.
 
-    if $noresults==1 then { return }
+    if [target_info exists gdb,noresults] { return }
 
-    gdb_test "cont" "Continuing.*Program exited normally.*" \
-       "continue to exit in test_simple_watchpoint"
+    gdb_continue_to_end "continue to exit in test_simple_watchpoint"
 }
 
 # Test disabling watchpoints.
 
 proc test_disabling_watchpoints {} {
-    global prompt
+    global gdb_prompt
     global binfile
     global srcfile
     global decimal
     global hex
-    global noresults
+
+    # "info watch" is the same as "info break"
+    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"
 
     # Ensure that the watchpoint is disabled when we startup.
 
-    send_gdb "disable 3\n"
-    expect {
-       -re "^disable 3\[\r\n\]+$prompt $" {
-           pass "disable watchpoint in test_disabling_watchpoints"
-       }
-       -re ".*$prompt $" {
-           fail "disable watchpoint in test_disabling_watchpoints"
-           return 0
-       }
-       timeout {
-           fail "disable watchpoint in test_disabling_watchpoints (timeout)"
-           return 0
-       }
+    if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] { 
+      return 0; 
     }
 
+
     # Run until we get to the first marker function.
 
     gdb_run_cmd
     set timeout 600
-    expect {
-       -re "Breakpoint 1, marker1 .*$prompt $" {
+    gdb_expect {
+       -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
            pass "run to marker1 in test_disabling_watchpoints"
        }
-       -re ".*$prompt $" {
+       -re ".*$gdb_prompt $" {
            fail "run to marker1 in test_disabling_watchpoints"
            return
        }
@@ -285,13 +323,11 @@ proc test_disabling_watchpoints {} {
 
     # After reaching the marker function, enable the watchpoint.
 
-    send_gdb "enable 3\n"
-    expect {
-       -re "^enable 3\[\r\n\]+$prompt $" { pass "watchpoint enabled" }
-       -re ".*$prompt $" { fail "watchpoint enabled" ; return }
-       timeout { fail "watchpoint enabled (timeout)" ; return }
+    if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] { 
+      return ; 
     }
 
+
     # Continue until the first change, from -1 to 0
     # Don't check the old value, because on VxWorks the variable value
     # will not have been reinitialized.
@@ -302,39 +338,28 @@ proc test_disabling_watchpoints {} {
     
     # Disable the watchpoint but leave breakpoints
 
-    send_gdb "disable 3\n"
-    expect {
-       -re "^disable 3\[\r\n\]+$prompt $" {
-           pass "disable watchpoint #2 in test_disabling_watchpoints"
-       }
-       -re ".*$prompt $" {
-           "disable watchpoint #2 in test_disabling_watchpoints"
-           return 0
-       }
-       timeout {
-           "disable watchpoint #2 in test_disabling_watchpoints (timeout)"
-           return 0
-       }
+    if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] { 
+      return 0; 
     }
 
+
     # Check watchpoint list, looking for the entry that confirms the
     # watchpoint is disabled.
-    gdb_test "info watchpoints" "3\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
+    gdb_test "info watchpoints" "\[0-9]+\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
 
     # Continue until we hit the finishing marker function.
     # Make sure we hit no more watchpoints.
     gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \
        "disabled watchpoint skipped"
     
-    if $noresults==1 then { return }
+    if [target_info exists gdb,noresults] { return }
 
-    gdb_test "cont" "Continuing.*Program exited normally.*" \
-       "continue to exit in test_disabling_watchpoints"
+    gdb_continue_to_end "continue to exit in test_disabling_watchpoints"
 }
 
 # Test stepping and other mundane operations with watchpoints enabled
 proc test_stepping {} {
-    global prompt
+    global gdb_prompt
 
     if [runto marker1] then {
        gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
@@ -343,31 +368,30 @@ proc test_stepping {} {
        gdb_test "break func2 if 0" "Breakpoint.*at.*"
        gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*"
 
-       # The HPPA has a problem here if it's not using hardware watchpoints
-       if {[ istarget "hppa*-*-*" ] && ![ istarget "hppa*-*-*bsd*" ]} then {
-           # Don't actually try doing the call, if we do we can't continue.
-           setup_xfail "*-*-*"
-           fail "calling function with watchpoint enabled"
-       } else {
-           # The problem is that GDB confuses stepping through the call
-           # dummy with hitting the breakpoint at the end of the call dummy.
-           # Will be fixed once all architectures define 
-           # CALL_DUMMY_BREAKPOINT_OFFSET.
-           setup_xfail "*-*-*"
-           # This doesn't occur if the call dummy starts with a call,
-           # because we are out of the dummy by the first time the inferior
-           # stops.
-           clear_xfail "m68*-*-*"
-           clear_xfail "i*86*-*-*"
-           clear_xfail "vax-*-*"
-           # The following architectures define CALL_DUMMY_BREAKPOINT_OFFSET.
-           clear_xfail "alpha-*-*"
-           clear_xfail "mips*-*-*"
-           clear_xfail "sparc-*-*"
-           clear_xfail "hppa*-*-*bsd*"
-           gdb_test "p func1 ()" "= 73" \
-               "calling function with watchpoint enabled"
-       }
+       # The problem is that GDB confuses stepping through the call
+       # dummy with hitting the breakpoint at the end of the call dummy.
+       # Will be fixed once all architectures define 
+       # CALL_DUMMY_BREAKPOINT_OFFSET.
+       setup_xfail "*-*-*"
+       # This doesn't occur if the call dummy starts with a call,
+       # because we are out of the dummy by the first time the inferior
+       # stops.
+       clear_xfail "d10v*-*-*"
+       clear_xfail "m68*-*-*"
+       clear_xfail "i*86*-*-*"
+       clear_xfail "vax-*-*"
+       # The following architectures define CALL_DUMMY_BREAKPOINT_OFFSET.
+       clear_xfail "alpha-*-*"
+       clear_xfail "mips*-*-*"
+       clear_xfail "sparc-*-*"
+       clear_xfail "hppa*-*-*bsd*"
+       # It works with the generic inferior function calling code too.
+       clear_xfail "mn10200*-*-*"
+       clear_xfail "mn10300*-*-*"
+       # The following architectures define CALL_DUMMY_HAS_COMPLETED.
+       clear_xfail "hppa*-*-*hpux*"
+       gdb_test "p func1 ()" "= 73" \
+       "calling function with watchpoint enabled"
 
        # 
        # "finish" brings us back to main.
@@ -378,22 +402,25 @@ proc test_stepping {} {
        #
 
        send_gdb "finish\n"
-       expect {
-           -re "Run.*exit from.*marker1.* at" { }
+       gdb_expect {
+           -re "Run.*exit from.*marker1.* at" {
+               pass "finish from marker1"
+           }
            default { fail "finish from marker1" ; return }
        }
-       expect {
-           -re "marker1 \\(\\);.*$prompt $" {
+
+       gdb_expect {
+           -re "marker1 \\(\\);.*$gdb_prompt $" {
                send_gdb "step\n"
                exp_continue
            }
-           -re "func1 \\(\\);.*$prompt $" {
+           -re "func1 \\(\\);.*$gdb_prompt $" {
                pass "finish from marker1"
            }
-           -re ".*$prompt $" {
+           -re ".*$gdb_prompt $" {
                fail "finish from marker1"
            }
-           default { fail "finish from marker1" ; return }
+           default { fail "finish from marker1 (timeout)" ; return }
        }
 
        gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp"
@@ -410,18 +437,18 @@ proc test_stepping {} {
        gdb_test "until" "ival1 = count.*" "until to ival1 assignment"
        gdb_test "until" "ival3 = count.*" "until to ival3 assignment"
        send_gdb "until\n"
-       expect {
-           -re "(for \\(count = 0|\}).*$prompt $" {
+       gdb_expect {
+           -re "(for \\(count = 0|\}).*$gdb_prompt $" {
                gdb_test "until" "ival1 = count; /. Outside loop ./" \
                    "until out of loop"
            }
-           -re "ival1 = count; /. Outside loop ./.*$prompt $" {
+           -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
                pass "until out of loop"
            }
-           -re ".*$prompt $" {
+           -re ".*$gdb_prompt $" {
                fail "until out of loop"
            }
-           default { fail "until out of loop" ; return }
+           default { fail "until out of loop (timeout)" ; return }
        }
 
        gdb_test "step" "ival2 = count.*" "step to ival2 assignment"
@@ -430,11 +457,9 @@ proc test_stepping {} {
 
 # Test stepping and other mundane operations with watchpoints enabled
 proc test_watchpoint_triggered_in_syscall {} {
-    global prompt
-    global noinferiorio
-    global noresults
+    global gdb_prompt
 
-    if $noinferiorio {
+    if [target_info exists gdb,noinferiorio] {
        verbose "Skipping test_watchpoint_triggered_in_syscall due to noinferiorio"
        return
     }
@@ -455,51 +480,55 @@ proc test_watchpoint_triggered_in_syscall {} {
        # If we send_gdb "123\n" before gdb has switched the tty, then it goes
        # to gdb, not the inferior, and we lose.  So that is why we have
        # watchpoint.c prompt us, so we can wait for that prompt.
-       send_gdb "continue\n"
-       expect {
+       send_gdb "continue\n";
+       gdb_expect {
            -re "Continuing\\.\r\ntype stuff for buf now:" {
                pass "continue to read"
            }
-           default { fail "continue to read"; return }
+           default {
+               fail "continue to read";
+               return ;
+           }
        }
+
        send_gdb "123\n"
-       expect {
+       gdb_expect {
            -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
            -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
            -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
            -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
-           -re ".*$prompt $" { pass "sent 123" }
+           -re ".*$gdb_prompt $" { pass "sent 123" }
            timeout { fail "sent 123 (timeout)" }
        }
 
        # Examine the values in buf to see how many watchpoints we
        # should have printed.
        send_gdb "print buf\[0\]\n"
-       expect {
-           -re ".*= 49.*$prompt $" { set y [expr $y+1]; pass "print buf\[0\]"}
-           -re ".*= 0.*$prompt $" { pass "print buf\[0\]"}
-           -re ".*$prompt $" { fail "print buf\[0\]"}
+       gdb_expect {
+           -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[0\]"}
+           -re ".*= 0.*$gdb_prompt $" { pass "print buf\[0\]"}
+           -re ".*$gdb_prompt $" { fail "print buf\[0\]"}
            default { fail "print buf\[0\]"}
        }
        send_gdb "print buf\[1\]\n"
-       expect {
-           -re ".*= 50.*$prompt $" { set y [expr $y+1]; pass "print buf\[1\]"}
-           -re ".*= 0.*$prompt $" { pass "print buf\[1\]"}
-           -re ".*$prompt $" { fail "print buf\[1\]"}
+       gdb_expect {
+           -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[1\]"}
+           -re ".*= 0.*$gdb_prompt $" { pass "print buf\[1\]"}
+           -re ".*$gdb_prompt $" { fail "print buf\[1\]"}
            default { fail "print buf\[1\]"}
        }
        send_gdb "print buf\[2\]\n"
-       expect {
-           -re ".*= 51.*$prompt $" { set y [expr $y+1]; pass "print buf\[2\]"}
-           -re ".*= 0.*$prompt $" { pass "print buf\[2\]"}
-           -re ".*$prompt $" { fail "print buf\[2\]"}
+       gdb_expect {
+           -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[2\]"}
+           -re ".*= 0.*$gdb_prompt $" { pass "print buf\[2\]"}
+           -re ".*$gdb_prompt $" { fail "print buf\[2\]"}
            default { fail "print buf\[2\]"}
        }
        send_gdb "print buf\[3\]\n"
-       expect {
-           -re ".*= 10.*$prompt $" { set y [expr $y+1]; pass "print buf\[3\]"}
-           -re ".*= 0.*$prompt $" { pass "print buf\[3\]"}
-           -re ".*$prompt $" { fail "print buf\[3\]" }
+       gdb_expect {
+           -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[3\]"}
+           -re ".*= 0.*$gdb_prompt $" { pass "print buf\[3\]"}
+           -re ".*$gdb_prompt $" { fail "print buf\[3\]" }
            default { fail "print buf\[3\]" }
        }
 
@@ -514,10 +543,9 @@ proc test_watchpoint_triggered_in_syscall {} {
        # Disable everything so we can finish the program at full speed
        gdb_test "disable" "" "disable in test_watchpoint_triggered_in_syscall"
 
-        if $noresults==1 then { return }
+       if [target_info exists gdb,noresults] { return }
 
-       gdb_test "cont" "Continuing.*Program exited normally.*" \
-           "continue to exit in test_watchpoint_triggered_in_syscall"
+       gdb_continue_to_end "continue to exit in test_watchpoint_triggered_in_syscall"
     }
 }
 
@@ -525,8 +553,7 @@ proc test_watchpoint_triggered_in_syscall {} {
 # itself changes.  Should add some more complicated stuff here.
 
 proc test_complex_watchpoint {} {
-    global prompt
-    global noresults
+    global gdb_prompt
 
     if [runto marker4] then {
        gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
@@ -540,13 +567,76 @@ proc test_complex_watchpoint {} {
        gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \
            "did not trigger wrong watchpoint"
 
+        # Test watches of things declared locally in a function.
+        # In particular, test that a watch of stack-based things
+        # is deleted when the stack-based things go out of scope.
+        #
+       gdb_test "disable" "" "disable in test_complex_watchpoint"
+        gdb_test "break marker6" ".*Breakpoint.*"
+        gdb_test "cont" "Continuing.*Breakpoint.*marker6 \\(\\).*" \
+            "continue to marker6"
+        gdb_test "break func2" ".*Breakpoint.*"
+        gdb_test "cont" "Continuing.*func2.*"
+
+        # Test a watch of a single stack-based variable, whose scope
+        # is the function we're now in.  This should auto-delete when
+        # execution exits the scope of the watchpoint.
+        #
+        gdb_test "watch local_a" ".*\[Ww\]atchpoint \[0-9\]*: local_a" "set local watch"
+        gdb_test "cont" "\[Ww\]atchpoint.*local_a.*" "trigger local watch"
+        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" "self-delete local watch"
+
+        gdb_test "cont" "Continuing.*func2.*"
+        # We should be in "func2" again now.  Test a watch of an
+        # expression which includes both a stack-based local and
+        # something whose scope is larger than this invocation
+        # of "func2".  This should also auto-delete.
+        #
+        gdb_test "watch local_a + ival5" ".*\[Ww\]atchpoint \[0-9\]*: local_a . ival5" \
+                 "set partially local watch"
+        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
+                 "trigger1 partially local watch"
+        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
+                 "trigger2 partially local watch"
+        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
+                 "self-delete partially local watch"
+
+        # We should be in "func2" again now.  Test a watch of a
+        # static (non-stack-based) local.  Since this has scope
+        # across any invocations of "func2", it should not auto-
+        # delete.
+        #
+        gdb_test "cont" "Continuing.*func2.*"
+        gdb_test "watch static_b" ".*\[Ww\]atchpoint \[0-9\]*: static_b" \
+                 "set static local watch"
+        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: static_b.*" \
+                 "trigger static local watch"
+        gdb_test "cont" "Continuing.*marker6 \\(\\).*" \
+                 "continue after trigger static local watch"
+        gdb_test "info break" ".*watchpoint.*static_b.*" \
+                 "static local watch did not self-delete"
+
+        # We should be in "recurser" now.  Test a watch of a stack-
+        # based local.  Symbols mentioned in a watchpoint are bound
+        # at watchpoint-creation.  Thus, a watch of a stack-based
+        # local to a recursing function should be bound only to that
+        # one invocation, and should not trigger for other invocations.
+        #
+        gdb_test "tbreak recurser" ".*Breakpoint.*"
+        gdb_test "cont" "Continuing.*recurser.*"
+        gdb_test "watch local_x" ".*\[Ww\]atchpoint \[0-9\]*: local_x" \
+                 "set local watch in recursive call"
+        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_x.*New value = 2.*" \
+                 "trigger local watch in recursive call"
+        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
+                 "self-delete local watch in recursive call"
+
        # Disable everything so we can finish the program at full speed
        gdb_test "disable" "" "disable in test_complex_watchpoint"
 
-        if $noresults==1 then { return }
+       if [target_info exists gdb,noresults] { return }
 
-       gdb_test "cont" "Continuing.*Program exited normally.*" \
-           "continue to exit in test_complex_watchpoint"
+       gdb_continue_to_end "continue to exit in test_complex_watchpoint"
     }
 }
 
@@ -585,15 +675,17 @@ if [initialize] then {
        initialize
     }
 
-    test_stepping
+    if ![target_info exists gdb,cannot_call_functions] {
+       test_stepping
 
-    # See above.
-    if [istarget "mips-idt-*"] then {
-       gdb_exit
-       gdb_start
-       gdb_reinitialize_dir $srcdir/$subdir
-       gdb_load $binfile
-       initialize
+       # See above.
+       if [istarget "mips-idt-*"] then {
+           gdb_exit
+           gdb_start
+           gdb_reinitialize_dir $srcdir/$subdir
+           gdb_load $binfile
+           initialize
+       }
     }
 
     # Only enabled for some targets merely because it has not been tested 
@@ -615,7 +707,87 @@ if [initialize] then {
 
     # Only enabled for some targets merely because it has not been tested 
     # elsewhere.
-    if {[istarget "hppa*-*-*"] || [istarget "sparc*-*-sunos*"]} then {
+    if {[istarget "hppa*-*-*"] || \
+           [istarget "sparc*-*-sunos*"] || \
+           [istarget "m32r-*-*"]} then {
        test_complex_watchpoint
     }
+
+    # Verify that a user can force GDB to use "slow" watchpoints.
+    # (This proves rather little on kernels that don't support
+    # fast watchpoints, but still...)
+    #
+    if ![runto_main] then { fail "watch tests suppressed" }
+
+    send_gdb "set can-use-hw-watchpoints 0\n"
+    gdb_expect {
+      -re "$gdb_prompt $"\
+              {pass "disable fast watches"}
+      timeout {fail "(timeout) disable fast watches"}
+    }
+    send_gdb "show can-use-hw-watchpoints\n"
+    gdb_expect {
+      -re "Debugger's willingness to use watchpoint hardware is 0.*$gdb_prompt $"\
+              {pass "show disable fast watches"}
+      -re "$gdb_prompt $"\
+              {fail "show disable fast watches"}
+      timeout {fail "(timeout) show disable fast watches"}
+    }
+    send_gdb "watch ival3 if  count > 1\n"
+    gdb_expect {
+      -re "Watchpoint \[0-9\]*: ival3.*$gdb_prompt $"\
+              {pass "set slow conditional watch"}
+      -re "$gdb_prompt $"\
+              {fail "set slow conditional watch"}
+      timeout {fail "(timeout) set slow conditional watch"}
+    }
+    send_gdb "continue\n"
+    gdb_expect {
+      -re "Watchpoint \[0-9\]*: ival3.*Old value = 1.*New value = 2.*$gdb_prompt $"\
+              {pass "trigger slow conditional watch"}
+      -re "$gdb_prompt $"\
+              {fail "trigger slow conditional watch"}
+      timeout {fail "(timeout) trigger slow conditional watch"}
+    }
+
+    # We've explicitly disabled hardware watches.  Verify that GDB
+    # 
+    #
+    send_gdb "rwatch ival3\n"
+    gdb_expect {
+      -re "Expression cannot be implemented with read/access watchpoint..*$gdb_prompt $"\
+              {pass "rwatch disallowed when can-set-hw-watchpoints cleared"}
+      -re "$gdb_prompt $"\
+              {fail "rwatch disallowed when can-set-hw-watchpoints cleared"}
+      timeout {fail "(timeout) rwatch disallowed when can-use-hw-watchpoints cleared"}
+    }
+
+    # Read- and access watchpoints are unsupported on HP-UX.  Verify
+    # that GDB gracefully responds to requests to create them.
+    #
+    if [istarget "hppa*-*-hpux*"] then {
+      send_gdb "set can-use-hw-watchpoints 1\n"
+      gdb_expect {
+        -re "$gdb_prompt $"\
+                {pass "enable fast watches"}
+        timeout {fail "(timeout) enable fast watches"}
+      }
+      send_gdb "rwatch ival3\n"
+      gdb_expect {
+        -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
+                {pass "read watches disallowed"}
+        -re "$gdb_prompt $"\
+                {fail "read watches disallowed"}
+        timeout {fail "(timeout) read watches disallowed"}
+      }
+
+      send_gdb "awatch ival3\n"
+      gdb_expect {
+        -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
+                {pass "access watches disallowed"}
+        -re "$gdb_prompt $"\
+                {fail "access watches disallowed"}
+        timeout {fail "(timeout) access watches disallowed"}
+      }
+    }
 }
This page took 0.034908 seconds and 4 git commands to generate.