[Lldb-commits] [lldb] 2981ece - [debugserver] Share code between Enable/DisableHardwareWatchpoint (NFC)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Sat Jan 18 11:38:28 PST 2020
Author: Jonas Devlieghere
Date: 2020-01-18T11:36:56-08:00
New Revision: 2981eceec337c26befe5f5d1b1031b254240e21d
URL: https://github.com/llvm/llvm-project/commit/2981eceec337c26befe5f5d1b1031b254240e21d
DIFF: https://github.com/llvm/llvm-project/commit/2981eceec337c26befe5f5d1b1031b254240e21d.diff
LOG: [debugserver] Share code between Enable/DisableHardwareWatchpoint (NFC)
This extract the common functionality of enabling and disabling hardware
watchpoints into a single function.
Differential revision: https://reviews.llvm.org/D72971
Added:
Modified:
lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp
lldb/tools/debugserver/source/MacOSX/MachThreadList.h
Removed:
################################################################################
diff --git a/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp b/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp
index d2aae9da0c4d..a086de6ab405 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp
@@ -502,65 +502,56 @@ bool MachThreadList::DisableHardwareBreakpoint(const DNBBreakpoint *bp) const {
return false;
}
+uint32_t MachThreadList::DoHardwareBreakpointAction(
+ const DNBBreakpoint *wp, HardwareBreakpointAction action) const {
+ if (wp == NULL)
+ return INVALID_NUB_HW_INDEX;
+
+ uint32_t hw_index = INVALID_NUB_HW_INDEX;
+ PTHREAD_MUTEX_LOCKER(locker, m_threads_mutex);
+ const size_t num_threads = m_threads.size();
+ // On Mac OS X we have to prime the control registers for new threads. We do
+ // this using the control register data for the first thread, for lack of a
+ // better way of choosing.
+ bool also_set_on_task = true;
+ 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);
+ break;
+ case HardwareBreakpointAction::DisableWatchpoint:
+ hw_index =
+ m_threads[idx]->DisableHardwareWatchpoint(wp, also_set_on_task);
+ break;
+ }
+ if (hw_index == INVALID_NUB_HW_INDEX) {
+ // We know that idx failed for some reason. Let's rollback the
+ // transaction for [0, idx).
+ for (uint32_t i = 0; i < idx; ++i)
+ m_threads[i]->RollbackTransForHWP();
+ return INVALID_NUB_HW_INDEX;
+ }
+ also_set_on_task = false;
+ }
+ // Notify each thread to commit the pending transaction.
+ for (uint32_t idx = 0; idx < num_threads; ++idx)
+ m_threads[idx]->FinishTransForHWP();
+ return hw_index;
+}
+
// DNBWatchpointSet() -> MachProcess::CreateWatchpoint() ->
// MachProcess::EnableWatchpoint()
// -> MachThreadList::EnableHardwareWatchpoint().
uint32_t
MachThreadList::EnableHardwareWatchpoint(const DNBBreakpoint *wp) const {
- uint32_t hw_index = INVALID_NUB_HW_INDEX;
- if (wp != NULL) {
- PTHREAD_MUTEX_LOCKER(locker, m_threads_mutex);
- const size_t num_threads = m_threads.size();
- // On Mac OS X we have to prime the control registers for new threads. We
- // do this
- // using the control register data for the first thread, for lack of a
- // better way of choosing.
- bool also_set_on_task = true;
- for (uint32_t idx = 0; idx < num_threads; ++idx) {
- if ((hw_index = m_threads[idx]->EnableHardwareWatchpoint(
- wp, also_set_on_task)) == INVALID_NUB_HW_INDEX) {
- // We know that idx failed for some reason. Let's rollback the
- // transaction for [0, idx).
- for (uint32_t i = 0; i < idx; ++i)
- m_threads[i]->RollbackTransForHWP();
- return INVALID_NUB_HW_INDEX;
- }
- also_set_on_task = false;
- }
- // Notify each thread to commit the pending transaction.
- for (uint32_t idx = 0; idx < num_threads; ++idx)
- m_threads[idx]->FinishTransForHWP();
- }
- return hw_index;
+ return DoHardwareBreakpointAction(wp,
+ HardwareBreakpointAction::EnableWatchpoint);
}
bool MachThreadList::DisableHardwareWatchpoint(const DNBBreakpoint *wp) const {
- if (wp != NULL) {
- PTHREAD_MUTEX_LOCKER(locker, m_threads_mutex);
- const size_t num_threads = m_threads.size();
-
- // On Mac OS X we have to prime the control registers for new threads. We
- // do this
- // using the control register data for the first thread, for lack of a
- // better way of choosing.
- bool also_set_on_task = true;
- for (uint32_t idx = 0; idx < num_threads; ++idx) {
- if (!m_threads[idx]->DisableHardwareWatchpoint(wp, also_set_on_task)) {
- // We know that idx failed for some reason. Let's rollback the
- // transaction for [0, idx).
- for (uint32_t i = 0; i < idx; ++i)
- m_threads[i]->RollbackTransForHWP();
- return false;
- }
- also_set_on_task = false;
- }
- // Notify each thread to commit the pending transaction.
- for (uint32_t idx = 0; idx < num_threads; ++idx)
- m_threads[idx]->FinishTransForHWP();
-
- return true;
- }
- return false;
+ return DoHardwareBreakpointAction(
+ wp, HardwareBreakpointAction::DisableWatchpoint) !=
+ INVALID_NUB_HW_INDEX;
}
uint32_t MachThreadList::NumSupportedHardwareWatchpoints() const {
diff --git a/lldb/tools/debugserver/source/MacOSX/MachThreadList.h b/lldb/tools/debugserver/source/MacOSX/MachThreadList.h
index b9b7aa8c4c92..96ca19b043ce 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachThreadList.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachThreadList.h
@@ -83,6 +83,14 @@ class MachThreadList {
typedef collection::iterator iterator;
typedef collection::const_iterator const_iterator;
+ enum class HardwareBreakpointAction {
+ EnableWatchpoint,
+ DisableWatchpoint,
+ };
+
+ uint32_t DoHardwareBreakpointAction(const DNBBreakpoint *wp,
+ HardwareBreakpointAction action) const;
+
uint32_t UpdateThreadList(MachProcess *process, bool update,
collection *num_threads = NULL);
// const_iterator FindThreadByID (thread_t tid) const;
More information about the lldb-commits
mailing list