Fill out implementation of Enable/DisableWatchpoint() for ProcessGDBRemote class (Not Tested Yet).
Also update the signature of WatchpointLocation::SetEnable() to take a bool as input arg.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@139198 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 0c02ff6..5c04c36 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -1882,6 +1882,24 @@
     return error;
 }
 
+// Pre-requisite: wp != NULL.
+static GDBStoppointType
+GetGDBStoppointType (WatchpointLocation *wp)
+{
+    assert(wp);
+    bool watch_read = wp->WatchpointRead();
+    bool watch_write = wp->WatchpointWrite();
+
+    // watch_read and watch_write cannot both be false.
+    assert(watch_read || watch_write);
+    if (watch_read && watch_write)
+        return eWatchpointReadWrite;
+    if (watch_read)
+        return eWatchpointRead;
+    if (watch_write)
+        return eWatchpointWrite;
+}
+
 Error
 ProcessGDBRemote::EnableWatchpoint (WatchpointLocation *wp)
 {
@@ -1899,11 +1917,21 @@
                 log->Printf("ProcessGDBRemote::EnableWatchpoint(watchID = %d) addr = 0x%8.8llx: watchpoint already enabled.", watchID, (uint64_t)addr);
             return error;
         }
-        else
+
+        GDBStoppointType type = GetGDBStoppointType(wp);
+        // Pass down an appropriate z/Z packet...
+        if (m_gdb_comm.SupportsGDBStoppointPacket (type))
         {
-            // Pass down an appropriate z/Z packet...
-            error.SetErrorString("watchpoints not supported");
+            if (m_gdb_comm.SendGDBStoppointTypePacket(type, true, addr, wp->GetByteSize()) == 0)
+            {
+                wp->SetEnabled(true);
+                return error;
+            }
+            else
+                error.SetErrorString("sending gdb watchpoint packet failed");
         }
+        else
+            error.SetErrorString("watchpoints not supported");
     }
     else
     {
@@ -1928,10 +1956,24 @@
         if (log)
             log->Printf ("ProcessGDBRemote::DisableWatchpoint (watchID = %d) addr = 0x%8.8llx", watchID, (uint64_t)addr);
 
+        if (!wp->IsEnabled())
+        {
+            if (log)
+                log->Printf ("ProcessGDBRemote::DisableWatchpoint (watchID = %d) addr = 0x%8.8llx -- SUCCESS (already disabled)", watchID, (uint64_t)addr);
+            return error;
+        }
+        
         if (wp->IsHardware())
         {
+            GDBStoppointType type = GetGDBStoppointType(wp);
             // Pass down an appropriate z/Z packet...
-            error.SetErrorString("watchpoints not supported");
+            if (m_gdb_comm.SendGDBStoppointTypePacket(type, false, addr, wp->GetByteSize()) == 0)
+            {
+                wp->SetEnabled(false);
+                return error;
+            }
+            else
+                error.SetErrorString("sending gdb watchpoint packet failed"); 
         }
         // TODO: clear software watchpoints if we implement them
     }