diff --git a/lldb/include/lldb/Breakpoint/WatchpointLocationList.h b/lldb/include/lldb/Breakpoint/WatchpointLocationList.h index b4dc1f4c2142..db46a410ec48 100644 --- a/lldb/include/lldb/Breakpoint/WatchpointLocationList.h +++ b/lldb/include/lldb/Breakpoint/WatchpointLocationList.h @@ -113,6 +113,34 @@ public: lldb::watch_id_t FindIDByAddress (lldb::addr_t addr); + //------------------------------------------------------------------ + /// Returns a shared pointer to the watchpoint location with + /// index \a i. + /// + /// @param[in] i + /// The watchpoint location index to seek for. + /// + /// @result + /// A shared pointer to the watchpoint location. May contain a NULL + /// pointer if the watchpoint location doesn't exist. + //------------------------------------------------------------------ + lldb::WatchpointLocationSP + GetByIndex (uint32_t i); + + //------------------------------------------------------------------ + /// Returns a shared pointer to the watchpoint location with index + /// \a i, const version. + /// + /// @param[in] i + /// The watchpoint location index to seek for. + /// + /// @result + /// A shared pointer to the watchpoint location. May contain a NULL + /// pointer if the watchpoint location doesn't exist. + //------------------------------------------------------------------ + const lldb::WatchpointLocationSP + GetByIndex (uint32_t i) const; + //------------------------------------------------------------------ /// Removes the watchpoint location given by \b watchID from this list. /// @@ -193,6 +221,7 @@ public: GetListMutex (lldb_private::Mutex::Locker &locker); protected: + typedef std::vector collection; typedef std::map addr_map; addr_map::iterator @@ -201,6 +230,7 @@ protected: addr_map::const_iterator GetIDConstIterator(lldb::watch_id_t watchID) const; + collection m_locations; addr_map m_address_to_location; mutable Mutex m_mutex; }; diff --git a/lldb/source/Breakpoint/WatchpointLocationList.cpp b/lldb/source/Breakpoint/WatchpointLocationList.cpp index 9227192ff74a..1664d5b4db3e 100644 --- a/lldb/source/Breakpoint/WatchpointLocationList.cpp +++ b/lldb/source/Breakpoint/WatchpointLocationList.cpp @@ -14,13 +14,13 @@ // Project includes #include "lldb/Breakpoint/WatchpointLocationList.h" #include "lldb/Breakpoint/WatchpointLocation.h" -#include "lldb/Core/ModuleList.h" #include "lldb/Target/Target.h" using namespace lldb; using namespace lldb_private; WatchpointLocationList::WatchpointLocationList() : + m_locations (), m_address_to_location (), m_mutex (Mutex::eMutexTypeRecursive) { @@ -47,7 +47,15 @@ WatchpointLocationList::Add (const WatchpointLocationSP &wp_loc_sp) else { m_address_to_location[wp_addr] = wp_loc_sp; + collection::iterator pos, end = m_locations.end(); + for (pos = m_locations.begin(); pos != end; ++pos) + if ((*pos)->GetLoadAddress() == wp_addr) + { + m_locations.erase(pos); + break; + } } + m_locations.push_back(wp_loc_sp); return wp_loc_sp->GetID(); } @@ -141,6 +149,28 @@ WatchpointLocationList::FindIDByAddress (lldb::addr_t addr) return LLDB_INVALID_WATCH_ID; } +WatchpointLocationSP +WatchpointLocationList::GetByIndex (uint32_t i) +{ + Mutex::Locker locker (m_mutex); + WatchpointLocationSP wp_loc_sp; + if (i < m_locations.size()) + wp_loc_sp = m_locations[i]; + + return wp_loc_sp; +} + +const WatchpointLocationSP +WatchpointLocationList::GetByIndex (uint32_t i) const +{ + Mutex::Locker locker (m_mutex); + WatchpointLocationSP wp_loc_sp; + if (i < m_locations.size()) + wp_loc_sp = m_locations[i]; + + return wp_loc_sp; +} + bool WatchpointLocationList::Remove (lldb::watch_id_t watch_id) { @@ -149,6 +179,13 @@ WatchpointLocationList::Remove (lldb::watch_id_t watch_id) if (pos != m_address_to_location.end()) { m_address_to_location.erase(pos); + collection::iterator pos, end = m_locations.end(); + for (pos = m_locations.begin(); pos != end; ++pos) + if ((*pos)->GetID() == watch_id) + { + m_locations.erase(pos); + break; + } return true; } return false;