gdb/testsuite: Run test with software and hardware watchpoints
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 10 Apr 2018 19:21:58 +0000 (20:21 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 10 Jul 2018 13:47:38 +0000 (14:47 +0100)
Expand the gdb.base/watchpoint-reuse-slot.exp test to be run twice,
once with hardware watchpoints disabled (this is new) and then with
hardware watchpoints enabled (the old way).

Running with hardware watchpoints enabled is skipped if the board file
says that hardware watchpoints are not supported on this target.

gdb/testsuite/ChangeLog:

* gdb.base/watchpoint-reuse-slot.exp: Test with hardware
watchpoints enabled and disabled.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/watchpoint-reuse-slot.exp

index 1ba373d62bcc6347b6c9b9af3390a3d92d58762f..d073eda401a48b452c04d7f3970142c5a336863f 100644 (file)
@@ -1,3 +1,8 @@
+2018-07-10  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.base/watchpoint-reuse-slot.exp: Test with hardware
+       watchpoints enabled and disabled.
+
 2018-07-09  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.base/examine-backward.exp: Still run tests around address
index f196b89eab7fdae6cf11d1e2f32145dcc55a80c9..e4ca94b05374f611c2c1a894ee8e391ad21646a0 100644 (file)
 # operation.  (Note that we don't have any of these watchpoints
 # trigger.)
 
-if [target_info exists gdb,no_hardware_watchpoints] {
-    unsupported "no target support"
-    return
-}
-
 standard_testfile
 
 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
@@ -85,54 +80,62 @@ proc stepi {} {
 
 gdb_breakpoint $srcline
 gdb_continue_to_breakpoint "stepi line"
+set cur_addr [get_pc]
 
 # The test tries various sequences of different types of watchpoints.
 # Probe for support first.
+proc build_cmds_list {} {
+    global gdb_prompt
+
+    # So we get an immediate warning/error if the target doesn't support a
+    # given watchpoint type.
+    gdb_test_no_output "set breakpoint always-inserted on" \
+       "Set breakpoints always inserted while building cmds list"
+
+    # The list of supported commands.  Below we'll probe for support and
+    # add elements to this list.
+    set cmds {}
+
+    foreach cmd {"watch" "awatch" "rwatch"} {
+       set test $cmd
+       gdb_test_multiple "$cmd buf.byte\[0\]" $test {
+           -re "You may have requested too many.*$gdb_prompt $" {
+               unsupported $test
+           }
+           -re "Target does not support.*$gdb_prompt $" {
+               unsupported $test
+           }
+           -re "Can't set read/access watchpoint when hardware watchpoints are disabled.*$gdb_prompt $" {
+               unsupported $test
+           }
+           -re "$gdb_prompt $" {
+               pass $test
+               lappend cmds $cmd
+           }
+       }
 
-# So we get an immediate warning/error if the target doesn't support a
-# given watchpoint type.
-gdb_test_no_output "set breakpoint always-inserted on"
-
-# The list of supported commands.  Below we'll probe for support and
-# add elements to this list.
-set cmds {}
+       delete_breakpoints
+    }
 
-foreach cmd {"watch" "awatch" "rwatch"} {
-    set test $cmd
-    gdb_test_multiple "$cmd buf.byte\[0\]" $test {
+    set test "hbreak"
+    gdb_test_multiple "hbreak main" $test {
        -re "You may have requested too many.*$gdb_prompt $" {
            unsupported $test
        }
-       -re "Target does not support.*$gdb_prompt $" {
+       -re "No hardware breakpoint support.*$gdb_prompt $" {
            unsupported $test
        }
        -re "$gdb_prompt $" {
            pass $test
-           lappend cmds $cmd
+           lappend cmds "hbreak"
        }
     }
 
-   delete_breakpoints
-}
+    delete_breakpoints
 
-set test "hbreak"
-gdb_test_multiple "hbreak main" $test {
-    -re "You may have requested too many.*$gdb_prompt $" {
-       unsupported $test
-    }
-    -re "No hardware breakpoint support.*$gdb_prompt $" {
-       unsupported $test
-    }
-    -re "$gdb_prompt $" {
-       pass $test
-       lappend cmds "hbreak"
-    }
+    return $cmds
 }
 
-delete_breakpoints
-
-set cur_addr [get_pc]
-
 # Return true if the memory range [buf.byte + OFFSET, +WIDTH] can be
 # monitored by CMD, otherwise return false.
 
@@ -184,8 +187,10 @@ proc valid_addr_p {cmd offset width} {
 
 # Watch WIDTH bytes at BASE + OFFSET.  CMD specifices the specific
 # type of watchpoint to use.  If CMD is "hbreak", WIDTH is ignored.
+# The HW_WP_P flag tells us if hardware watchpoints are enabled or
+# not.
 
-proc watch_command {cmd base offset width} {
+proc watch_command {cmd base offset width hw_wp_p} {
     global srcfile srcline hex
 
     if {$cmd == "hbreak"} {
@@ -193,8 +198,15 @@ proc watch_command {cmd base offset width} {
        gdb_test "hbreak $expr" "Hardware assisted breakpoint \[0-9\]+ at $hex"
     } elseif {$cmd == "watch"} {
        set expr "*(buf.byte + $base + $offset)@$width"
+
+       if { ! $hw_wp_p } {
+           set wp_prefix "Watchpoint"
+       } else {
+           set wp_prefix "Hardware watchpoint"
+       }
+
        gdb_test "$cmd $expr" \
-           "Hardware watchpoint \[0-9\]+: [string_to_regexp $expr]"
+           "${wp_prefix} \[0-9\]+: [string_to_regexp $expr]"
     } elseif {$cmd == "awatch"} {
        set expr "*(buf.byte + $base + $offset)@$width"
        gdb_test "$cmd $expr" \
@@ -206,42 +218,48 @@ proc watch_command {cmd base offset width} {
     }
 }
 
-# Run test proper.  See intro for description.
+# Run the watchpoint tests (see the description at the top for details), the
+# HW_WP_P flag tells us if hardware watchpoints are enabled or not.
+proc run_watchpoints_tests {hw_wp_p} {
 
-foreach always_inserted {"off" "on" } {
-    gdb_test_no_output "set breakpoint always-inserted $always_inserted"
-    foreach cmd1 $cmds {
-       foreach cmd2 $cmds {
-           for {set width 1} {$width < 4} {incr width} {
+    set cmds [build_cmds_list]
 
-               if {$cmd1 == "hbreak" && $cmd2 == "hbreak" && $width > 1} {
-                   # hbreak ignores WIDTH, no use testing more than
-                   # once.
-                   continue
-               }
+    foreach always_inserted {"off" "on" } {
+       gdb_test_no_output "set breakpoint always-inserted $always_inserted"
+       foreach cmd1 $cmds {
+           foreach cmd2 $cmds {
+               for {set width 1} {$width < 4} {incr width} {
 
-               for {set x 0} {$x < 4} {incr x} {
-
-                   if { ![valid_addr_p $cmd1 $x $width]
-                        || ![valid_addr_p $cmd2 $x+1 $width] } {
-                       # Skip tests if requested address or length
-                       # of breakpoint or watchpoint don't meet
-                       # target or kernel requirements.
+                   if {$cmd1 == "hbreak" && $cmd2 == "hbreak" \
+                           && $width > 1} {
+                       # hbreak ignores WIDTH, no use testing more than
+                       # once.
                        continue
                    }
 
-                   set prefix "always-inserted $always_inserted: "
-                   append prefix "$cmd1 x $cmd2: "
-                   with_test_prefix "$prefix: width $width, iter $x" {
-                       with_test_prefix "base + 0" {
-                           watch_command $cmd1 $x 0 $width
-                           stepi
-                           gdb_test_no_output "delete \$bpnum"
+                   for {set x 0} {$x < 4} {incr x} {
+
+                       if { ![valid_addr_p $cmd1 $x $width]
+                            || ![valid_addr_p $cmd2 $x+1 $width] } {
+                           # Skip tests if requested address or length
+                           # of breakpoint or watchpoint don't meet
+                           # target or kernel requirements.
+                           continue
                        }
-                       with_test_prefix "base + 1" {
-                           watch_command $cmd2 $x 1 $width
-                           stepi
-                           gdb_test_no_output "delete \$bpnum"
+
+                       set prefix "always-inserted $always_inserted: "
+                       append prefix "$cmd1 x $cmd2: "
+                       with_test_prefix "$prefix: width $width, iter $x" {
+                           with_test_prefix "base + 0" {
+                               watch_command $cmd1 $x 0 $width $hw_wp_p
+                               stepi
+                               gdb_test_no_output "delete \$bpnum"
+                           }
+                           with_test_prefix "base + 1" {
+                               watch_command $cmd2 $x 1 $width $hw_wp_p
+                               stepi
+                               gdb_test_no_output "delete \$bpnum"
+                           }
                        }
                    }
                }
@@ -249,3 +267,29 @@ foreach always_inserted {"off" "on" } {
        }
     }
 }
+
+# Based on HW_WP_P set whether hardware watchpoints can be used or
+# not, then call RUN_WATCHPOINTS_TESTS.
+proc setup_and_run_watchpoints_tests { hw_wp_p } {
+    if {$hw_wp_p} {
+       set prefix "hw-watch"
+    } else {
+       set prefix "sw-watch"
+    }
+
+    with_test_prefix $prefix {
+       gdb_test_no_output "set can-use-hw-watchpoints ${hw_wp_p}"
+
+       run_watchpoints_tests $hw_wp_p
+    }
+}
+
+# Run tests with hardware watchpoints disabled, then again with them
+# enabled (if this target supports hardware watchpoints).
+if { ![target_info exists gdb,no_hardware_watchpoints]} {
+    # Run test with H/W enabled.
+    setup_and_run_watchpoints_tests 1
+}
+
+# Run test with H/W disabled
+setup_and_run_watchpoints_tests 0