Watchpoint WIP:

o WatchpointLocationList:
  Add a GetListMutex() method.
o WatchpointLocation:
  Fix Dump() method where there was an extra % in the format string.
o Target.cpp:
  Add implementation to CreateWatchpointLocation() to create and enable a watchpoint.

o DNBArchImplX86_64.cpp:
  Fix bugs in SetWatchpoint()/ClearWatchpoint() where '==' was used, instead of '=',
  to assign/reset the data break address to a debug register.

  Also fix bugs where a by reference debug_state should have been used, not by value.

llvm-svn: 139666
This commit is contained in:
Johnny Chen 2011-09-13 23:29:31 +00:00
parent e64f0dc7bf
commit 3c53258964
7 changed files with 50 additions and 16 deletions

View File

@ -29,7 +29,7 @@ class WatchpointLocation :
{
public:
WatchpointLocation (lldb::addr_t m_addr, size_t size, bool hardware);
WatchpointLocation (lldb::addr_t addr, size_t size, bool hardware = true);
~WatchpointLocation ();

View File

@ -174,6 +174,15 @@ public:
GetDescription (Stream *s,
lldb::DescriptionLevel level);
//------------------------------------------------------------------
/// Sets the passed in Locker to hold the Watchpoint Location List mutex.
///
/// @param[in] locker
/// The locker object that is set.
//------------------------------------------------------------------
void
GetListMutex (lldb_private::Mutex::Locker &locker);
protected:
typedef std::map<lldb::addr_t, lldb::WatchpointLocationSP> addr_map;

View File

@ -46,7 +46,7 @@ namespace lldb_private {
OptionParsingStarting (CommandInterpreter &interpreter);
// Note:
// eWatchRead == LLDB_WATCH_TYPE_EREAD; and
// eWatchRead == LLDB_WATCH_TYPE_READ; and
// eWatchWrite == LLDB_WATCH_TYPE_WRITE
typedef enum WatchType {
eWatchInvalid = 0,

View File

@ -85,7 +85,7 @@ WatchpointLocation::Dump(Stream *s) const
if (s == NULL)
return;
s->Printf("WatchpointLocation %u: tid = %4.4x addr = 0x%8.8llx size = %zu state = %s type = %s watchpoint (%s%s) hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p",
s->Printf("WatchpointLocation %u: addr = 0x%8.8llx size = %zu state = %s type = %s watchpoint (%s%s) hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p",
GetID(),
(uint64_t)m_addr,
m_byte_size,

View File

@ -188,3 +188,8 @@ WatchpointLocationList::GetDescription (Stream *s, lldb::DescriptionLevel level)
}
}
void
WatchpointLocationList::GetListMutex (Mutex::Locker &locker)
{
return locker.Reset (m_mutex.GetMutex());
}

View File

@ -341,7 +341,27 @@ Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type)
if (size == 0)
return wp_loc_sp;
// FIXME: Add implmenetation.
WatchpointLocationSP matched_sp = m_watchpoint_location_list.FindByAddress(addr);
if (matched_sp)
{
size_t old_size = wp_loc_sp->GetByteSize();
uint32_t old_type =
(wp_loc_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
(wp_loc_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
// Return an empty watchpoint location if the same one exists already.
if (size == old_size && type == old_type)
return wp_loc_sp;
// Nil the matched watchpoint location; we will be creating a new one.
m_process_sp->DisableWatchpoint(matched_sp.get());
m_watchpoint_location_list.Remove(matched_sp->GetID());
}
WatchpointLocation *new_loc = new WatchpointLocation(addr, size);
new_loc->SetWatchpointType(type);
wp_loc_sp.reset(new_loc);
m_watchpoint_location_list.Add(wp_loc_sp);
m_process_sp->EnableWatchpoint(wp_loc_sp.get());
return wp_loc_sp;
}

View File

@ -481,7 +481,7 @@ DNBArchImplX86_64::ThreadWillResume()
if (kret != KERN_SUCCESS)
return;
DBG debug_state = m_state.context.dbg;
DBG &debug_state = m_state.context.dbg;
bool need_reset = false;
uint32_t i, num = NumSupportedHardwareWatchpoints();
for (i = 0; i < num; ++i)
@ -650,13 +650,13 @@ DNBArchImplX86_64::SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t
size_and_rw_bits(size, read, write) << (16+4*hw_index));
switch (hw_index) {
case 0:
debug_state.__dr0 == addr; break;
debug_state.__dr0 = addr; break;
case 1:
debug_state.__dr1 == addr; break;
debug_state.__dr1 = addr; break;
case 2:
debug_state.__dr2 == addr; break;
debug_state.__dr2 = addr; break;
case 3:
debug_state.__dr3 == addr; break;
debug_state.__dr3 = addr; break;
default:
assert(0 && "invalid hardware register index, must be one of 0, 1, 2, or 3");
}
@ -669,13 +669,13 @@ DNBArchImplX86_64::ClearWatchpoint(DBG &debug_state, uint32_t hw_index)
debug_state.__dr7 &= ~(3 << (2*hw_index));
switch (hw_index) {
case 0:
debug_state.__dr0 == 0; break;
debug_state.__dr0 = 0; break;
case 1:
debug_state.__dr1 == 0; break;
debug_state.__dr1 = 0; break;
case 2:
debug_state.__dr2 == 0; break;
debug_state.__dr2 = 0; break;
case 3:
debug_state.__dr3 == 0; break;
debug_state.__dr3 = 0; break;
default:
assert(0 && "invalid hardware register index, must be one of 0, 1, 2, or 3");
}
@ -759,7 +759,7 @@ DNBArchImplX86_64::EnableHardwareWatchpoint (nub_addr_t addr, nub_size_t size, b
// Check to make sure we have the needed hardware support
uint32_t i = 0;
DBG debug_state = m_state.context.dbg;
DBG &debug_state = m_state.context.dbg;
for (i = 0; i < num_hw_watchpoints; ++i)
{
if (IsWatchpointVacant(debug_state, i))
@ -794,7 +794,7 @@ DNBArchImplX86_64::DisableHardwareWatchpoint (uint32_t hw_index)
const uint32_t num_hw_points = NumSupportedHardwareWatchpoints();
if (kret == KERN_SUCCESS)
{
DBG debug_state = m_state.context.dbg;
DBG &debug_state = m_state.context.dbg;
if (hw_index < num_hw_points && !IsWatchpointVacant(debug_state, hw_index))
{
// Modify our local copy of the debug state, first.
@ -820,7 +820,7 @@ DNBArchImplX86_64::GetHardwareWatchpointHit(nub_addr_t &addr)
DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::GetHardwareWatchpointHit() GetDBGState() => 0x%8.8x.", kret);
if (kret == KERN_SUCCESS)
{
DBG debug_state = m_state.context.dbg;
DBG &debug_state = m_state.context.dbg;
uint32_t i, num = NumSupportedHardwareWatchpoints();
for (i = 0; i < num; ++i)
{