Commit 9902c8e3 authored by Jonas Devlieghere's avatar Jonas Devlieghere
Browse files

[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
parent e1440f59
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -78,7 +78,8 @@ public:
  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 @@ public:
                                            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;
+12 −6
Original line number Diff line number Diff line
@@ -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;
}

+4 −2
Original line number Diff line number Diff line
@@ -66,10 +66,12 @@ public:
  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;
+23 −23
Original line number Diff line number Diff line
@@ -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();
+3 −1
Original line number Diff line number Diff line
@@ -86,9 +86,11 @@ protected:
  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,