Hardware watchpoints turned off, inferior not yet started.
authorAndrew Burgess <aburgess@broadcom.com>
Fri, 18 Oct 2013 16:25:14 +0000 (16:25 +0000)
committerAndrew Burgess <aburgess@broadcom.com>
Fri, 18 Oct 2013 16:25:14 +0000 (16:25 +0000)
  https://sourceware.org/ml/gdb-patches/2013-10/msg00477.html

gdb/ChangeLog

* breakpoint.c (update_watchpoint): If hardware watchpoints are
forced off, downgrade them to software watchpoints if possible,
and error out if not possible.
(watch_command_1): Move watchpoint type selection closer to
watchpoint creation, and extend the comments.

gdb/testsuite/ChangeLog

* gdb.base/watchpoints.exp: Add test for setting software
watchpoints of different types before starting the inferior.

gdb/ChangeLog
gdb/breakpoint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/watchpoints.exp

index c3e3d210794c40f5e92b16dc43bd4c55418ff2e9..30829f5bf507965c5127239378784279a29db325 100644 (file)
@@ -1,3 +1,11 @@
+2013-10-18  Andrew Burgess  <aburgess@broadcom.com>
+
+       * breakpoint.c (update_watchpoint): If hardware watchpoints are
+       forced off, downgrade them to software watchpoints if possible,
+       and error out if not possible.
+       (watch_command_1): Move watchpoint type selection closer to
+       watchpoint creation, and extend the comments.
+
 2013-10-18  Pedro Alves  <palves@redhat.com>
 
        PR gdb/16062
index 5ce50defc11076d70f633e155427fd26db60ef09..c630b877e0c936d9d559e6a13699d2a71c8ed372 100644 (file)
@@ -1795,11 +1795,18 @@ update_watchpoint (struct watchpoint *b, int reparse)
      don't try to insert watchpoint.  We don't automatically delete
      such watchpoint, though, since failure to parse expression
      is different from out-of-scope watchpoint.  */
-  if ( !target_has_execution)
+  if (!target_has_execution)
     {
       /* Without execution, memory can't change.  No use to try and
         set watchpoint locations.  The watchpoint will be reset when
         the target gains execution, through breakpoint_re_set.  */
+      if (!can_use_hw_watchpoints)
+       {
+         if (b->base.ops->works_in_software_mode (&b->base))
+           b->base.type = bp_watchpoint;
+         else
+           error (_("Software read/access watchpoints not supported."));
+       }
     }
   else if (within_current_scope && b->exp)
     {
@@ -11081,13 +11088,6 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
   if (*tok)
     error (_("Junk at end of command."));
 
-  if (accessflag == hw_read)
-    bp_type = bp_read_watchpoint;
-  else if (accessflag == hw_access)
-    bp_type = bp_access_watchpoint;
-  else
-    bp_type = bp_hardware_watchpoint;
-
   frame = block_innermost_frame (exp_valid_block);
 
   /* If the expression is "local", then set up a "watchpoint scope"
@@ -11124,7 +11124,17 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
        }
     }
 
-  /* Now set up the breakpoint.  */
+  /* Now set up the breakpoint.  We create all watchpoints as hardware
+     watchpoints here even if hardware watchpoints are turned off, a call
+     to update_watchpoint later in this function will cause the type to
+     drop back to bp_watchpoint (software watchpoint) if required.  */
+
+  if (accessflag == hw_read)
+    bp_type = bp_read_watchpoint;
+  else if (accessflag == hw_access)
+    bp_type = bp_access_watchpoint;
+  else
+    bp_type = bp_hardware_watchpoint;
 
   w = XCNEW (struct watchpoint);
   b = &w->base;
index 8e057f6d9044524a3b79c8ec4103305c32bdb9a5..60c1295878067600f3d86807be45cf7cff2265c6 100644 (file)
@@ -1,3 +1,8 @@
+2013-10-18  Andrew Burgess  <aburgess@broadcom.com>
+
+       * gdb.base/watchpoints.exp: Add test for setting software
+       watchpoints of different types before starting the inferior.
+
 2013-10-18  Pedro Alves  <palves@redhat.com>
 
        PR gdb/16062
index 7c10d819daeac4dac44b969a6aa20304ddf1e684..b70e86cfa5b8032679adcbce86d62567215b1fb7 100644 (file)
@@ -29,6 +29,29 @@ if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
     return -1
 }
 
+with_test_prefix "before inferior start" {
+    # Ensure that if we turn off hardware watchpoints and set a watch point
+    # before starting the inferior the watchpoint created will not be a
+    # hardware watchpoint.
+    gdb_test_no_output "set can-use-hw-watchpoints 0" ""
+    gdb_test "watch ival1" "Watchpoint \[0-9\]+: ival1" \
+        "create watchpoint"
+
+    # The next tests are written to match the current state of gdb: access
+    # and read watchpoints require hardware watchpoint support, with this
+    # turned off these can't be created.
+    gdb_test "awatch ival1" \
+        "Software read/access watchpoints not supported." \
+        "create access watchpoint"
+    gdb_test "rwatch ival1" \
+        "Software read/access watchpoints not supported." \
+        "create read watchpoint"
+}
+
+    # This will turn hardware watchpoints back on and delete the watchpoint
+    # we just created.
+    clean_restart ${binfile}
+
     # Disable hardware watchpoints if necessary.
     if [target_info exists gdb,no_hardware_watchpoints] {
         gdb_test_no_output "set can-use-hw-watchpoints 0" ""