Author: Michał Górny Date: 2021-07-20T07:47:48+02:00 New Revision: 7b54b1cdafbcaa5721bcf8ae78e8390a74d580bf
URL: https://github.com/llvm/llvm-project/commit/7b54b1cdafbcaa5721bcf8ae78e8390a74d580bf DIFF: https://github.com/llvm/llvm-project/commit/7b54b1cdafbcaa5721bcf8ae78e8390a74d580bf.diff LOG: [lldb] Make WatchpointList iterable Based on de448c0a9e5088979526e2e67152fe547ae4ccf0. Differential Revision: https://reviews.llvm.org/D106263 Added: Modified: lldb/include/lldb/Breakpoint/WatchpointList.h lldb/source/Commands/CommandCompletions.cpp lldb/source/Target/Target.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Breakpoint/WatchpointList.h b/lldb/include/lldb/Breakpoint/WatchpointList.h index 6f224b641396c..bf87495d79dba 100644 --- a/lldb/include/lldb/Breakpoint/WatchpointList.h +++ b/lldb/include/lldb/Breakpoint/WatchpointList.h @@ -14,6 +14,7 @@ #include <vector> #include "lldb/Core/Address.h" +#include "lldb/Utility/Iterable.h" #include "lldb/lldb-private.h" namespace lldb_private { @@ -37,6 +38,11 @@ class WatchpointList { /// Destructor, currently does nothing. ~WatchpointList(); + typedef std::list<lldb::WatchpointSP> wp_collection; + typedef LockingAdaptedIterable<wp_collection, lldb::WatchpointSP, + vector_adapter, std::recursive_mutex> + WatchpointIterable; + /// Add a Watchpoint to the list. /// /// \param[in] wp_sp @@ -184,8 +190,11 @@ class WatchpointList { /// The locker object that is set. void GetListMutex(std::unique_lock<std::recursive_mutex> &lock); + WatchpointIterable Watchpoints() const { + return WatchpointIterable(m_watchpoints, m_mutex); + } + protected: - typedef std::list<lldb::WatchpointSP> wp_collection; typedef std::vector<lldb::watch_id_t> id_vector; id_vector GetWatchpointIDs() const; diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp index 857b2a05b91c1..55018cef57d4e 100644 --- a/lldb/source/Commands/CommandCompletions.cpp +++ b/lldb/source/Commands/CommandCompletions.cpp @@ -774,9 +774,7 @@ void CommandCompletions::WatchPointIDs(CommandInterpreter &interpreter, return; const WatchpointList &wp_list = exe_ctx.GetTargetPtr()->GetWatchpointList(); - const size_t wp_num = wp_list.GetSize(); - for (size_t idx = 0; idx < wp_num; ++idx) { - const lldb::WatchpointSP wp_sp = wp_list.GetByIndex(idx); + for (lldb::WatchpointSP wp_sp : wp_list.Watchpoints()) { StreamString strm; wp_sp->Dump(&strm); request.TryCompleteCurrentArg(std::to_string(wp_sp->GetID()), diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 6cb7a9942a5c7..2a0dcaa4ce6bd 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1159,9 +1159,7 @@ bool Target::RemoveAllWatchpoints(bool end_to_end) { if (!ProcessIsValid()) return false; - size_t num_watchpoints = m_watchpoint_list.GetSize(); - for (size_t i = 0; i < num_watchpoints; ++i) { - WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); + for (WatchpointSP wp_sp : m_watchpoint_list.Watchpoints()) { if (!wp_sp) return false; @@ -1191,8 +1189,7 @@ bool Target::DisableAllWatchpoints(bool end_to_end) { return false; size_t num_watchpoints = m_watchpoint_list.GetSize(); - for (size_t i = 0; i < num_watchpoints; ++i) { - WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); + for (WatchpointSP wp_sp : m_watchpoint_list.Watchpoints()) { if (!wp_sp) return false; @@ -1219,9 +1216,7 @@ bool Target::EnableAllWatchpoints(bool end_to_end) { if (!ProcessIsValid()) return false; - size_t num_watchpoints = m_watchpoint_list.GetSize(); - for (size_t i = 0; i < num_watchpoints; ++i) { - WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); + for (WatchpointSP wp_sp : m_watchpoint_list.Watchpoints()) { if (!wp_sp) return false; @@ -1237,9 +1232,7 @@ bool Target::ClearAllWatchpointHitCounts() { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); LLDB_LOGF(log, "Target::%s\n", __FUNCTION__); - size_t num_watchpoints = m_watchpoint_list.GetSize(); - for (size_t i = 0; i < num_watchpoints; ++i) { - WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); + for (WatchpointSP wp_sp : m_watchpoint_list.Watchpoints()) { if (!wp_sp) return false; @@ -1253,9 +1246,7 @@ bool Target::ClearAllWatchpointHistoricValues() { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); LLDB_LOGF(log, "Target::%s\n", __FUNCTION__); - size_t num_watchpoints = m_watchpoint_list.GetSize(); - for (size_t i = 0; i < num_watchpoints; ++i) { - WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); + for (WatchpointSP wp_sp : m_watchpoint_list.Watchpoints()) { if (!wp_sp) return false; @@ -1273,9 +1264,7 @@ bool Target::IgnoreAllWatchpoints(uint32_t ignore_count) { if (!ProcessIsValid()) return false; - size_t num_watchpoints = m_watchpoint_list.GetSize(); - for (size_t i = 0; i < num_watchpoints; ++i) { - WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); + for (WatchpointSP wp_sp : m_watchpoint_list.Watchpoints()) { if (!wp_sp) return false; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits