diff --git a/lldb/include/lldb/Breakpoint/WatchpointList.h b/lldb/include/lldb/Breakpoint/WatchpointList.h --- a/lldb/include/lldb/Breakpoint/WatchpointList.h +++ b/lldb/include/lldb/Breakpoint/WatchpointList.h @@ -14,6 +14,7 @@ #include #include "lldb/Core/Address.h" +#include "lldb/Utility/Iterable.h" #include "lldb/lldb-private.h" namespace lldb_private { @@ -37,6 +38,11 @@ /// Destructor, currently does nothing. ~WatchpointList(); + typedef std::list wp_collection; + typedef LockingAdaptedIterable + WatchpointIterable; + /// Add a Watchpoint to the list. /// /// \param[in] wp_sp @@ -184,8 +190,11 @@ /// The locker object that is set. void GetListMutex(std::unique_lock &lock); + WatchpointIterable Watchpoints() const { + return WatchpointIterable(m_watchpoints, m_mutex); + } + protected: - typedef std::list wp_collection; typedef std::vector id_vector; id_vector GetWatchpointIDs() const; diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp --- a/lldb/source/Commands/CommandCompletions.cpp +++ b/lldb/source/Commands/CommandCompletions.cpp @@ -774,9 +774,7 @@ 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 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1159,9 +1159,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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;