Add GetByIndex() methods to the WatchpointLocationList class to facilitate iteration

through the watchpoint locations by index.

llvm-svn: 140071
This commit is contained in:
Johnny Chen 2011-09-19 21:53:51 +00:00
parent 52faf4bff9
commit ac559323aa
2 changed files with 68 additions and 1 deletions

View File

@ -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<lldb::WatchpointLocationSP> collection;
typedef std::map<lldb::addr_t, lldb::WatchpointLocationSP> 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;
};

View File

@ -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;