[Lldb-commits] [lldb] 9902c8e - [lldb/debugserver] Unify the breakpoint/watchpoint interface (NFCI)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Jan 24 15:07:42 PST 2020


Author: Jonas Devlieghere
Date: 2020-01-24T15:07:31-08:00
New Revision: 9902c8e3c6615185a8a00325fa4671c63b61d535

URL: https://github.com/llvm/llvm-project/commit/9902c8e3c6615185a8a00325fa4671c63b61d535
DIFF: https://github.com/llvm/llvm-project/commit/9902c8e3c6615185a8a00325fa4671c63b61d535.diff

LOG: [lldb/debugserver] Unify the breakpoint/watchpoint interface (NFCI)

Unify the interface for enabling and disabling breakpoints with their
watchpoint counterpart. This allows both to go through
DoHardwareBreakpointAction.

Differential revision: https://reviews.llvm.org/D72981

Added: 
    

Modified: 
    lldb/tools/debugserver/source/DNBArch.h
    lldb/tools/debugserver/source/MacOSX/MachThread.cpp
    lldb/tools/debugserver/source/MacOSX/MachThread.h
    lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp
    lldb/tools/debugserver/source/MacOSX/MachThreadList.h

Removed: 
    


################################################################################
diff  --git a/lldb/tools/debugserver/source/DNBArch.h b/lldb/tools/debugserver/source/DNBArch.h
index 03b6b60ed86d..d46aa673a362 100644
--- a/lldb/tools/debugserver/source/DNBArch.h
+++ b/lldb/tools/debugserver/source/DNBArch.h
@@ -78,7 +78,8 @@ class DNBArchProtocol {
   virtual bool NotifyException(MachException::Data &exc) { return false; }
   virtual uint32_t NumSupportedHardwareBreakpoints() { return 0; }
   virtual uint32_t NumSupportedHardwareWatchpoints() { return 0; }
-  virtual uint32_t EnableHardwareBreakpoint(nub_addr_t addr, nub_size_t size) {
+  virtual uint32_t EnableHardwareBreakpoint(nub_addr_t addr, nub_size_t size,
+                                            bool also_set_on_task) {
     return INVALID_NUB_HW_INDEX;
   }
   virtual uint32_t EnableHardwareWatchpoint(nub_addr_t addr, nub_size_t size,
@@ -86,7 +87,10 @@ class DNBArchProtocol {
                                             bool also_set_on_task) {
     return INVALID_NUB_HW_INDEX;
   }
-  virtual bool DisableHardwareBreakpoint(uint32_t hw_index) { return false; }
+  virtual bool DisableHardwareBreakpoint(uint32_t hw_index,
+                                         bool also_set_on_task) {
+    return false;
+  }
   virtual bool DisableHardwareWatchpoint(uint32_t hw_index,
                                          bool also_set_on_task) {
     return false;

diff  --git a/lldb/tools/debugserver/source/MacOSX/MachThread.cpp b/lldb/tools/debugserver/source/MacOSX/MachThread.cpp
index 80d6042caa59..d2423a5decaa 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachThread.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/MachThread.cpp
@@ -534,9 +534,12 @@ bool MachThread::RestoreRegisterState(uint32_t save_id) {
   return m_arch_up->RestoreRegisterState(save_id);
 }
 
-uint32_t MachThread::EnableHardwareBreakpoint(const DNBBreakpoint *bp) {
-  if (bp != NULL && bp->IsBreakpoint())
-    return m_arch_up->EnableHardwareBreakpoint(bp->Address(), bp->ByteSize());
+uint32_t MachThread::EnableHardwareBreakpoint(const DNBBreakpoint *bp,
+                                              bool also_set_on_task) {
+  if (bp != NULL && bp->IsBreakpoint()) {
+    return m_arch_up->EnableHardwareBreakpoint(bp->Address(), bp->ByteSize(),
+                                               also_set_on_task);
+  }
   return INVALID_NUB_HW_INDEX;
 }
 
@@ -555,9 +558,12 @@ bool MachThread::RollbackTransForHWP() {
 
 bool MachThread::FinishTransForHWP() { return m_arch_up->FinishTransForHWP(); }
 
-bool MachThread::DisableHardwareBreakpoint(const DNBBreakpoint *bp) {
-  if (bp != NULL && bp->IsHardware())
-    return m_arch_up->DisableHardwareBreakpoint(bp->GetHardwareIndex());
+bool MachThread::DisableHardwareBreakpoint(const DNBBreakpoint *bp,
+                                           bool also_set_on_task) {
+  if (bp != NULL && bp->IsHardware()) {
+    return m_arch_up->DisableHardwareBreakpoint(bp->GetHardwareIndex(),
+                                                also_set_on_task);
+  }
   return false;
 }
 

diff  --git a/lldb/tools/debugserver/source/MacOSX/MachThread.h b/lldb/tools/debugserver/source/MacOSX/MachThread.h
index 1634522fde49..cbcd94ea5765 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachThread.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachThread.h
@@ -66,10 +66,12 @@ class MachThread {
   uint64_t GetSP(uint64_t failValue = INVALID_NUB_ADDRESS); // Get stack pointer
 
   DNBBreakpoint *CurrentBreakpoint();
-  uint32_t EnableHardwareBreakpoint(const DNBBreakpoint *breakpoint);
+  uint32_t EnableHardwareBreakpoint(const DNBBreakpoint *breakpoint,
+                                    bool also_set_on_task);
   uint32_t EnableHardwareWatchpoint(const DNBBreakpoint *watchpoint,
                                     bool also_set_on_task);
-  bool DisableHardwareBreakpoint(const DNBBreakpoint *breakpoint);
+  bool DisableHardwareBreakpoint(const DNBBreakpoint *breakpoint,
+                                 bool also_set_on_task);
   bool DisableHardwareWatchpoint(const DNBBreakpoint *watchpoint,
                                  bool also_set_on_task);
   uint32_t NumSupportedHardwareWatchpoints() const;

diff  --git a/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp b/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp
index a086de6ab405..ce63b0fd6344 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp
@@ -483,28 +483,9 @@ void MachThreadList::NotifyBreakpointChanged(const DNBBreakpoint *bp) {
   }
 }
 
-uint32_t
-MachThreadList::EnableHardwareBreakpoint(const DNBBreakpoint *bp) const {
-  if (bp != NULL) {
-    const size_t num_threads = m_threads.size();
-    for (uint32_t idx = 0; idx < num_threads; ++idx)
-      m_threads[idx]->EnableHardwareBreakpoint(bp);
-  }
-  return INVALID_NUB_HW_INDEX;
-}
-
-bool MachThreadList::DisableHardwareBreakpoint(const DNBBreakpoint *bp) const {
-  if (bp != NULL) {
-    const size_t num_threads = m_threads.size();
-    for (uint32_t idx = 0; idx < num_threads; ++idx)
-      m_threads[idx]->DisableHardwareBreakpoint(bp);
-  }
-  return false;
-}
-
 uint32_t MachThreadList::DoHardwareBreakpointAction(
-    const DNBBreakpoint *wp, HardwareBreakpointAction action) const {
-  if (wp == NULL)
+    const DNBBreakpoint *bp, HardwareBreakpointAction action) const {
+  if (bp == NULL)
     return INVALID_NUB_HW_INDEX;
 
   uint32_t hw_index = INVALID_NUB_HW_INDEX;
@@ -517,11 +498,18 @@ uint32_t MachThreadList::DoHardwareBreakpointAction(
   for (uint32_t idx = 0; idx < num_threads; ++idx) {
     switch (action) {
     case HardwareBreakpointAction::EnableWatchpoint:
-      hw_index = m_threads[idx]->EnableHardwareWatchpoint(wp, also_set_on_task);
+      hw_index = m_threads[idx]->EnableHardwareWatchpoint(bp, also_set_on_task);
       break;
     case HardwareBreakpointAction::DisableWatchpoint:
       hw_index =
-          m_threads[idx]->DisableHardwareWatchpoint(wp, also_set_on_task);
+          m_threads[idx]->DisableHardwareWatchpoint(bp, also_set_on_task);
+      break;
+    case HardwareBreakpointAction::EnableBreakpoint:
+      hw_index = m_threads[idx]->EnableHardwareBreakpoint(bp, also_set_on_task);
+      break;
+    case HardwareBreakpointAction::DisableBreakpoint:
+      hw_index =
+          m_threads[idx]->DisableHardwareBreakpoint(bp, also_set_on_task);
       break;
     }
     if (hw_index == INVALID_NUB_HW_INDEX) {
@@ -554,6 +542,18 @@ bool MachThreadList::DisableHardwareWatchpoint(const DNBBreakpoint *wp) const {
          INVALID_NUB_HW_INDEX;
 }
 
+uint32_t
+MachThreadList::EnableHardwareBreakpoint(const DNBBreakpoint *bp) const {
+  return DoHardwareBreakpointAction(bp,
+                                    HardwareBreakpointAction::EnableBreakpoint);
+}
+
+bool MachThreadList::DisableHardwareBreakpoint(const DNBBreakpoint *bp) const {
+  return DoHardwareBreakpointAction(
+             bp, HardwareBreakpointAction::DisableBreakpoint) !=
+         INVALID_NUB_HW_INDEX;
+}
+
 uint32_t MachThreadList::NumSupportedHardwareWatchpoints() const {
   PTHREAD_MUTEX_LOCKER(locker, m_threads_mutex);
   const size_t num_threads = m_threads.size();

diff  --git a/lldb/tools/debugserver/source/MacOSX/MachThreadList.h b/lldb/tools/debugserver/source/MacOSX/MachThreadList.h
index 96ca19b043ce..aeec61d6e051 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachThreadList.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachThreadList.h
@@ -86,9 +86,11 @@ class MachThreadList {
   enum class HardwareBreakpointAction {
     EnableWatchpoint,
     DisableWatchpoint,
+    EnableBreakpoint,
+    DisableBreakpoint,
   };
 
-  uint32_t DoHardwareBreakpointAction(const DNBBreakpoint *wp,
+  uint32_t DoHardwareBreakpointAction(const DNBBreakpoint *bp,
                                       HardwareBreakpointAction action) const;
 
   uint32_t UpdateThreadList(MachProcess *process, bool update,


        


More information about the lldb-commits mailing list