2012-02-21 Pedro Alves <palves@redhat.com>
[binutils-gdb.git] / gdb / testsuite / gdb.base / watchpoint.exp
index 331b18165b3582e0e4dda65ecdfb9a74e3e2be27..7a252bb865809862b3d5d06f428b722de7e3ed8f 100644 (file)
@@ -1,5 +1,4 @@
-# Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2007, 2008, 2009,
-# 2010, 2011 Free Software Foundation, Inc.
+# Copyright 1992, 1994-2000, 2007-2012 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
 
 # This file was written by Fred Fish. (fnf@cygnus.com)
 
-if $tracelevel then {
-    strace $tracelevel
-}
-
 
 set testfile "watchpoint"
 set srcfile ${testfile}.c
 set binfile ${objdir}/${subdir}/${testfile}
 
-set wp_set 1
-
 if [get_compiler_info ${binfile}] {
     return -1
 }
@@ -36,6 +29,9 @@ if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
      return -1
 }
 
+# True if we're forcing no hardware watchpoints.
+set no_hw 0
+
 # Prepare for watchpoint tests by setting up two breakpoints and one
 # watchpoint.
 #
@@ -57,7 +53,6 @@ proc initialize {} {
     global hex
     global decimal
     global srcfile
-    global wp_set
 
     # Disable hardware watchpoints if necessary.
     if [target_info exists gdb,no_hardware_watchpoints] {
@@ -78,27 +73,7 @@ proc initialize {} {
       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"
-    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
-        }
-    }
+    gdb_test "watch ival3" ".*\[Ww\]atchpoint 3: ival3.*" "set watchpoint on ival3"
 
     if [gdb_test "info watch" "3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] { 
       return 0; 
@@ -125,57 +100,26 @@ proc test_simple_watchpoint {} {
     global gdb_prompt
     global hex
     global decimal
-    global wp_set
 
     # Ensure that the watchpoint is disabled when we startup.
 
-    if { $wp_set } {
-        if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] { 
-           return 0; 
-       }
+    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
-    gdb_expect {
+    set test "run to marker1 in test_simple_watchpoint"
+    set retcode [gdb_test_multiple "" $test {
        -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
-           pass "run to marker1 in test_simple_watchpoint"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "run to marker1 in test_simple_watchpoint"
-           return
-       }
-       timeout {
-           fail "run to marker1 in test_simple_watchpoint (timeout)"
-           return
+           pass $test
        }
-    }
-
-    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].
-       #
-       gdb_test "watch ival3" \
-           "\[Ww\]atchpoint 3: ival3" \
-           "set watchpoint on ival3"
+    }]
 
-        set wp_set 1
-
-       gdb_test "info watch" \
-           "3\[ \]*.*watchpoint.*ival3" \
-           "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.
-
-       gdb_test "disable 3" "disable 3" "disable watchpoint"
+    if { $retcode != 0 } {
+       return
     }
 
     # After reaching the marker function, enable the watchpoint.
@@ -193,10 +137,10 @@ proc test_simple_watchpoint {} {
 
     # Continue until the first change, from -1 to 0
 
-    send_gdb "cont\n"
-    gdb_expect {
+    set test "watchpoint hit, first time"
+    gdb_test_multiple "cont" $test {
        -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
-           pass "watchpoint hit, first time"
+           pass $test
        }
        -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
            setup_xfail "m68*-*-*" 2597
@@ -204,11 +148,8 @@ proc test_simple_watchpoint {} {
            gdb_test_no_output "delete \$func1_breakpoint_number"
            gdb_test "continue" "\
 Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
-               "watchpoint hit, first time"
+               $test
        }
-       -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
@@ -271,8 +212,7 @@ proc test_disabling_watchpoints {} {
     global decimal
     global hex
 
-    # "info watch" is the same as "info break"
-    gdb_test "info watch" "\[0-9]+\[ \]*.*watchpoint.*ival3\r\n\.*\[0-9\]+ times.*" "watchpoints found in watchpoint/breakpoint table"
+    gdb_test "info watch" "\[0-9]+\[ \]*.*watchpoint.*ival3.*" "watchpoints found in watchpoint/breakpoint table"
 
     # Ensure that the watchpoint is disabled when we startup.
 
@@ -285,18 +225,15 @@ proc test_disabling_watchpoints {} {
 
     gdb_run_cmd
     set timeout 600
-    gdb_expect {
+    set test "run to marker1 in test_disabling_watchpoints"
+    set retcode [gdb_test_multiple "" $test {
        -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
-           pass "run to marker1 in test_disabling_watchpoints"
-       }
-       -re ".*$gdb_prompt $" {
-           fail "run to marker1 in test_disabling_watchpoints"
-           return
-       }
-       timeout {
-           fail "run to marker1 in test_disabling_watchpoints (timeout)"
-           return
+           pass $test
        }
+    }]
+
+    if { $retcode != 0 } {
+       return
     }
 
     # After reaching the marker function, enable the watchpoint.
@@ -392,19 +329,14 @@ 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"
-       gdb_expect {
+       set test "until out of loop"
+       gdb_test_multiple "until" $test {
            -re "(for \\(count = 0|\}).*$gdb_prompt $" {
-               gdb_test "until" "ival1 = count; /. Outside loop ./" \
-                   "until out of loop"
+               gdb_test "until" "ival1 = count; /. Outside loop ./" $test
            }
            -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
-               pass "until out of loop"
+               pass $test
            }
-           -re ".*$gdb_prompt $" {
-               fail "until out of loop"
-           }
-           default { fail "until out of loop (timeout)" ; return }
        }
 
        gdb_test "step" "ival2 = count.*" "step to ival2 assignment"
@@ -433,7 +365,7 @@ proc test_watchpoint_triggered_in_syscall {} {
 
        gdb_test_no_output "set doread = 1"
 
-       # If we send_gdb "123\n" before gdb has switched the tty, then it goes
+       # 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.
 
@@ -448,45 +380,36 @@ proc test_watchpoint_triggered_in_syscall {} {
            }
        }
 
-       send_gdb "123\n"
-       gdb_expect {
+       set test "sent 123"
+       gdb_test_multiple "123" $test {
            -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 ".*$gdb_prompt $" { pass "sent 123" }
-           timeout { fail "sent 123 (timeout)" }
+           -re ".*$gdb_prompt $" { pass $test }
        }
 
        # Examine the values in buf to see how many watchpoints we
        # should have printed.
-       send_gdb "print buf\[0\]\n"
-       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\]"}
+       set test "print buf\[0\]"
+       gdb_test_multiple $test $test {
+           -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass $test }
+           -re ".*= 0.*$gdb_prompt $" { $test }
        }
-       send_gdb "print buf\[1\]\n"
-       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\]"}
+       set test "print buf\[1\]"
+       gdb_test_multiple $test $test {
+           -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass $test }
+           -re ".*= 0.*$gdb_prompt $" { pass $test }
        }
-       send_gdb "print buf\[2\]\n"
-       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\]"}
+       set test "print buf\[2\]"
+       gdb_test_multiple $test $test {
+           -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass $test }
+           -re ".*= 0.*$gdb_prompt $" { pass $test }
        }
-       send_gdb "print buf\[3\]\n"
-       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\]" }
+       set test "print buf\[3\]"
+       gdb_test_multiple $test $test {
+           -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass $test }
+           -re ".*= 0.*$gdb_prompt $" { pass $test }
        }
 
        # Did we find what we were looking for?  If not, flunk it.
@@ -581,6 +504,7 @@ proc test_complex_watchpoint {} {
         #
         gdb_test "tbreak recurser" ".*breakpoint.*"
         gdb_test "cont" "Continuing.*recurser.*"
+        gdb_test "next" "if \\(x > 0.*" "next past local_x initialization"
         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.*" \
@@ -588,6 +512,19 @@ proc test_complex_watchpoint {} {
         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"
 
+        # Repeat the preceding test, but this time use "recurser::local_x" as
+        # the variable to track.
+        gdb_test "cont" "Continuing.*marker6.*"
+        gdb_test "tbreak recurser" ".*breakpoint.*"
+        gdb_test "cont" "Continuing.*recurser.*"
+        gdb_test "next" "if \\(x > 0.*" "next past local_x initialization"
+        gdb_test "watch recurser::local_x" ".*\[Ww\]atchpoint \[0-9\]*: recurser::local_x" \
+                 "set local watch in recursive call with explicit scope"
+        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: recurser::local_x.*New value = 2.*" \
+                 "trigger local watch with explicit scope 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 with explicit scope in recursive call (2)"
+
        # Disable everything so we can finish the program at full speed
        gdb_test_no_output "disable" "disable in test_complex_watchpoint"
 
@@ -660,6 +597,72 @@ proc test_watch_location {} {
     gdb_test_no_output "delete \$bpnum" "delete watch -location"
 }
 
+# Tests watching areas larger than a word.
+
+proc test_wide_location_1 {} {
+    global no_hw
+
+    # This test watches two words on most 32-bit ABIs, and one word on
+    # most 64-bit ABIs.
+
+    # Platforms where the target can't watch such a large region
+    # should clear hw_expected below.
+    if { $no_hw || [target_info exists gdb,no_hardware_watchpoints] } {
+       set hw_expected 0
+    } else {
+       set hw_expected 1
+    }
+
+    gdb_breakpoint [gdb_get_line_number "func6 breakpoint here"]
+    gdb_continue_to_breakpoint "func6 breakpoint here"
+
+    if { $hw_expected } {
+       gdb_test "watch foo2" "Hardware watchpoint .*: .*" "watch foo2"
+       gdb_test "continue" \
+           "Continuing.*Hardware watchpoint .*: .*New value = \\\{val = \\\{0, 11\\\}\\\}.*" \
+           "continue with watch foo2"
+    } else {
+       gdb_test "watch foo2" "atchpoint .*: .*" "watch foo2"
+       gdb_test "continue" \
+           "Continuing.*\[Ww\]atchpoint .*: .*New value = \\\{val = \\\{0, 11\\\}\\\}.*" \
+           "continue with watch foo2"
+    }
+
+    gdb_test_no_output "delete \$bpnum" "delete watch foo2"
+}
+
+proc test_wide_location_2 {} {
+    global no_hw
+
+    # This test watches four words on most 32-bit ABIs, and two words
+    # on 64-bit ABIs.
+
+    # Platforms where the target can't watch such a large region
+    # should clear hw_expected below.
+    if { $no_hw || [target_info exists gdb,no_hardware_watchpoints] } {
+       set hw_expected 0
+    } else {
+       set hw_expected 1
+    }
+
+    gdb_breakpoint [gdb_get_line_number "func7 breakpoint here"]
+    gdb_continue_to_breakpoint "func7 breakpoint here"
+
+    if { $hw_expected } {
+       gdb_test "watch foo4" "Hardware watchpoint .*: .*" "watch foo4"
+       gdb_test "continue" \
+           "Continuing.*Hardware watchpoint .*: .*New value = \\\{val = \\\{0, 0, 0, 33\\\}\\\}.*" \
+           "continue with watch foo4"
+    } else {
+       gdb_test "watch foo4" "atchpoint .*: .*" "watch foo4"
+       gdb_test "continue" \
+           "Continuing.*\[Ww\]atchpoint .*: .*New value = \\\{val = \\\{0, 0, 0, 33\\\}\\\}.*" \
+           "continue with watch foo4"
+    }
+
+    gdb_test_no_output "delete \$bpnum" "delete watch foo4"
+}
+
 proc test_inaccessible_watchpoint {} {
     global gdb_prompt
 
@@ -729,72 +732,136 @@ proc test_inaccessible_watchpoint {} {
        gdb_test "delete \$global_ptr_breakpoint_number" ""
        gdb_test "watch **global_ptr_ptr" ".*atchpoint \[0-9\]+: \\*\\*global_ptr_ptr"
        gdb_test "set \$global_ptr_ptr_breakpoint_number = \$bpnum" ""
-       gdb_test "next" ".*global_ptr_ptr = &global_ptr.*" "gloabl_ptr_ptr next"
+       gdb_test "next" ".*global_ptr_ptr = &global_ptr.*" "global_ptr_ptr next"
        gdb_test "next" ".*atchpoint \[0-9\]+: \\*\\*global_ptr_ptr\[\r\n\]+Old value = .*\r\nNew value = 7 .*" "next over global_ptr_ptr init"
        gdb_test "next" ".*atchpoint \[0-9\]+: \\*\\*global_ptr_ptr\[\r\n\]+Old value = 7 .*\r\nNew value = 9 .*" "next over global_ptr_ptr buffer set"
        gdb_test "next" ".*atchpoint \[0-9\]+: \\*\\*global_ptr_ptr\[\r\n\]+Old value = 9 .*\r\nNew value = 5 .*" "next over global_ptr_ptr pointer advance"
        gdb_test_no_output "delete \$global_ptr_ptr_breakpoint_number"
     }
 }
-    
+
+proc test_no_hw_watchpoints {} {
+    global testfile
+
+    clean_restart $testfile
+
+    # 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" }
+
+    gdb_test_no_output "set can-use-hw-watchpoints 0" "disable fast watches"
+
+    gdb_test "show can-use-hw-watchpoints" \
+       "Debugger's willingness to use watchpoint hardware is 0." \
+       "show disable fast watches"
+
+    gdb_test "watch ival3 if  count > 1" \
+       "Watchpoint \[0-9\]*: ival3.*" \
+       "set slow conditional watch"
+
+    gdb_test "continue" \
+       "Watchpoint \[0-9\]*: ival3.*Old value = 1.*New value = 2.*" \
+       "trigger slow conditional watch"
+
+    gdb_test_no_output "delete \$bpnum" "delete watch ival3"
+
+    # We've explicitly disabled hardware watches.  Verify that GDB
+    # refrains from using them.
+    #
+    gdb_test "rwatch ival3" \
+       "Expression cannot be implemented with read/access watchpoint..*" \
+       "rwatch disallowed when can-set-hw-watchpoints cleared"
+
+    # Re-enable hardware watchpoints if necessary.
+    if ![target_info exists gdb,no_hardware_watchpoints] {
+        gdb_test_no_output "set can-use-hw-watchpoints 1" ""
+    }
+}
+
 proc test_watchpoint_in_big_blob {} {
     global gdb_prompt
 
-    gdb_test "watch buf" ".*atchpoint \[0-9\]+: buf"
-    gdb_test "cont" "Continuing.*atchpoint \[0-9\]+: buf\r\n\r\nOld value = .*testte\".*" "watchpoint on buf hit"
+    # On native targets where we do hardware resource accounting, this
+    # may end up as a software watchpoint.
+    set ok 0
+    set test "watch buf"
+    gdb_test_multiple "watch buf" $test {
+       -re "Hardware watchpoint \[0-9\]+: buf.*You may have requested too many hardware breakpoints/watchpoints.*$gdb_prompt $" {
+           # This may happen with remote targets (where we don't do
+           # resource accounting) that support hardware watchpoints,
+           # when breakpoint always-inserted is on.  The watchpoint
+           # was too large, for example.  If GDB is ever adjusted to
+           # downgrade the watchpoint automatically in this case,
+           # this match should be removed.  Note the breakpoint has
+           # been created, and is in the list, so it needs deleting.
+           pass $test
+       }
+       -re ".*atchpoint \[0-9\]+: buf.*$gdb_prompt $" {
+           pass $test
+           set ok 1
+       }
+    }
+
+    if { $ok } {
+       set test "watchpoint on buf hit"
+       gdb_test_multiple "cont" $test {
+           -re "Continuing.*atchpoint \[0-9\]+: buf\r\n\r\nOld value = .*testte\".*$gdb_prompt $" {
+               pass $test
+           }
+           -re "Could not insert hardware breakpoints:.*You may have requested too many hardware breakpoints/watchpoints.*$gdb_prompt $" {
+               # This may happen with remote targets that support
+               # hardware watchpoints.  We only find out the
+               # watchpoint was too large, for example, at insert
+               # time.  If GDB is ever adjusted to downgrade the
+               # watchpoint automatically in this case, this match
+               # should be removed.
+               pass $test
+           }
+       }
+    }
 
     gdb_test_no_output "delete \$bpnum" "delete watch buf"
 }
 
 # Start with a fresh gdb.
 
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load $binfile
 set prev_timeout $timeout
 set timeout 600        
 verbose "Timeout now 600 sec.\n"
 
-if [initialize] then {
+test_no_hw_watchpoints
+
+proc do_tests {} {
+    global testfile
+    global no_hw
 
-    test_simple_watchpoint
+    clean_restart $testfile
 
-    # The IDT/sim monitor only has 8 (!) open files, of which it uses
-    # 4 (!).  So we have to make sure one program exits before
-    # starting another one.
-    if [istarget "mips-idt-*"] then {
-       gdb_exit
-       gdb_start
-       gdb_reinitialize_dir $srcdir/$subdir
-       gdb_load $binfile
-       initialize
+    if {$no_hw} {
+       gdb_test_no_output "set can-use-hw-watchpoints 0" ""
     }
 
-    test_disabling_watchpoints
+    if [initialize] then {
 
-    # See above.
-    if [istarget "mips-idt-*"] then {
-       gdb_exit
-       gdb_start
-       gdb_reinitialize_dir $srcdir/$subdir
-       gdb_load $binfile
-       initialize
-    }
+       test_simple_watchpoint
 
-    if ![target_info exists gdb,cannot_call_functions] {
-       test_stepping
+       test_disabling_watchpoints
 
-       # See above.
-       if [istarget "mips-idt-*"] then {
-           gdb_exit
-           gdb_start
-           gdb_reinitialize_dir $srcdir/$subdir
-           gdb_load $binfile
-           initialize
+       if ![target_info exists gdb,cannot_call_functions] {
+           test_stepping
        }
     }
 
+    # Tests below don't rely on the markers and watchpoint set by
+    # `initialize' anymore.
+    clean_restart $testfile
+
+    if {$no_hw} {
+       gdb_test_no_output "set can-use-hw-watchpoints 0" ""
+    }
+
     # Only enabled for some targets merely because it has not been tested 
     # elsewhere.
     # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4 
@@ -803,126 +870,34 @@ if [initialize] then {
        test_watchpoint_triggered_in_syscall
     }
 
-    # 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 
-    # elsewhere.
-    if {[istarget "hppa*-*-*"] || \
-           [istarget "sparc*-*-sunos*"] || \
-           [istarget "m32r-*-*"]} then {
-       test_complex_watchpoint
-    }
+    test_complex_watchpoint
 
     test_inaccessible_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
-    # refrains from using them.
-    #
-    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"}
-      }
-    }
-
-    # See above.
-    if [istarget "mips-idt-*"] then {
-       gdb_exit
-       gdb_start
-       gdb_reinitialize_dir $srcdir/$subdir
-       gdb_load $binfile
-       initialize
-    }
-
     test_watchpoint_and_breakpoint
 
     test_watchpoint_in_big_blob
 
-    # See above.
-    if [istarget "mips-idt-*"] then {
-       clean_restart
-    }
-
     test_constant_watchpoint
 
     test_disable_enable_software_watchpoint
 
     test_watch_location
+
+    test_wide_location_1
+    test_wide_location_2
+}
+
+# On targets that can do hardware watchpoints, run the tests twice:
+# once with hardware watchpoints enabled; another with hardware
+# watchpoints force-disabled.
+
+do_tests
+if ![target_info exists gdb,no_hardware_watchpoints] {
+    with_test_prefix " no-hw:" {
+       set no_hw 1
+       do_tests
+    }
 }
 
 # Restore old timeout