Watchpoint WIP:

o WatchpointLocationList:
  Add a GetListMutex() method.
o WatchpointLocation:
  Fix Dump() method where there was an extra % in the format string.
o Target.cpp:
  Add implementation to CreateWatchpointLocation() to create and enable a watchpoint.

o DNBArchImplX86_64.cpp:
  Fix bugs in SetWatchpoint()/ClearWatchpoint() where '==' was used, instead of '=',
  to assign/reset the data break address to a debug register.

  Also fix bugs where a by reference debug_state should have been used, not by value.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@139666 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index 7b6dcf7..1a4a7b0 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -341,7 +341,27 @@
     if (size == 0)
         return wp_loc_sp;
 
-    // FIXME: Add implmenetation.
+    WatchpointLocationSP matched_sp = m_watchpoint_location_list.FindByAddress(addr);
+    if (matched_sp)
+    {
+        size_t old_size = wp_loc_sp->GetByteSize();
+        uint32_t old_type =
+            (wp_loc_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
+            (wp_loc_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
+        // Return an empty watchpoint location if the same one exists already.
+        if (size == old_size && type == old_type)
+            return wp_loc_sp;
+
+        // Nil the matched watchpoint location; we will be creating a new one.
+        m_process_sp->DisableWatchpoint(matched_sp.get());
+        m_watchpoint_location_list.Remove(matched_sp->GetID());
+    }
+
+    WatchpointLocation *new_loc = new WatchpointLocation(addr, size);
+    new_loc->SetWatchpointType(type);
+    wp_loc_sp.reset(new_loc);
+    m_watchpoint_location_list.Add(wp_loc_sp);
+    m_process_sp->EnableWatchpoint(wp_loc_sp.get());
     return wp_loc_sp;
 }