Adding events when watchpoints are set or changed.

<rdar://problem/11597849>

llvm-svn: 170400
This commit is contained in:
Jim Ingham 2012-12-18 02:03:49 +00:00
parent 2a45e409a8
commit 1b5792e5ad
25 changed files with 432 additions and 51 deletions

View File

@ -75,6 +75,7 @@ protected:
friend class SBDebugger;
friend class SBProcess;
friend class SBThread;
friend class SBWatchpoint;
SBEvent (lldb::EventSP &event_sp);

View File

@ -12,7 +12,6 @@
#include "lldb/API/SBDefines.h"
#include "lldb/API/SBValueList.h"
#include "lldb/API/SBWatchpoint.h"
namespace lldb {

View File

@ -235,7 +235,8 @@ public:
{
eBroadcastBitBreakpointChanged = (1 << 0),
eBroadcastBitModulesLoaded = (1 << 1),
eBroadcastBitModulesUnloaded = (1 << 2)
eBroadcastBitModulesUnloaded = (1 << 2),
eBroadcastBitWatchpointChanged = (1 << 3)
};
//------------------------------------------------------------------

View File

@ -81,6 +81,15 @@ public:
void
SetSP (const lldb::WatchpointSP &sp);
static bool
EventIsWatchpointEvent (const lldb::SBEvent &event);
static lldb::WatchpointEventType
GetWatchpointEventTypeFromEvent (const lldb::SBEvent& event);
static lldb::SBWatchpoint
GetWatchpointFromEvent (const lldb::SBEvent& event);
private:
friend class SBTarget;
friend class SBValue;

View File

@ -28,10 +28,54 @@
namespace lldb_private {
class Watchpoint :
public STD_ENABLE_SHARED_FROM_THIS(Watchpoint),
public StoppointLocation
{
public:
class WatchpointEventData :
public EventData
{
public:
static const ConstString &
GetFlavorString ();
virtual const ConstString &
GetFlavor () const;
WatchpointEventData (lldb::WatchpointEventType sub_type,
const lldb::WatchpointSP &new_watchpoint_sp);
virtual
~WatchpointEventData();
lldb::WatchpointEventType
GetWatchpointEventType () const;
lldb::WatchpointSP &
GetWatchpoint ();
virtual void
Dump (Stream *s) const;
static lldb::WatchpointEventType
GetWatchpointEventTypeFromEvent (const lldb::EventSP &event_sp);
static lldb::WatchpointSP
GetWatchpointFromEvent (const lldb::EventSP &event_sp);
static const WatchpointEventData *
GetEventDataFromEvent (const Event *event_sp);
private:
lldb::WatchpointEventType m_watchpoint_event;
lldb::WatchpointSP m_new_watchpoint_sp;
DISALLOW_COPY_AND_ASSIGN (WatchpointEventData);
};
Watchpoint (Target& target, lldb::addr_t addr, size_t size, const ClangASTType *type, bool hardware = true);
~Watchpoint ();
@ -42,7 +86,7 @@ public:
IsEnabled () const;
void
SetEnabled (bool enabled);
SetEnabled (bool enabled, bool notify = true);
virtual bool
IsHardware () const;
@ -54,7 +98,7 @@ public:
bool WatchpointWrite () const;
uint32_t GetIgnoreCount () const;
void SetIgnoreCount (uint32_t n);
void SetWatchpointType (uint32_t type);
void SetWatchpointType (uint32_t type, bool notify = true);
void SetDeclInfo (const std::string &str);
std::string GetWatchSpec();
void SetWatchSpec (const std::string &str);
@ -188,10 +232,17 @@ private:
Error m_error; // An error object describing errors associated with this watchpoint.
WatchpointOptions m_options; // Settable watchpoint options, which is a delegate to handle
// the callback machinery.
bool m_being_created;
std::auto_ptr<ClangUserExpression> m_condition_ap; // The condition to test.
void SetID(lldb::watch_id_t id) { m_loc_id = id; }
void
SendWatchpointChangedEvent (lldb::WatchpointEventType eventKind);
void
SendWatchpointChangedEvent (WatchpointEventData *data);
DISALLOW_COPY_AND_ASSIGN (Watchpoint);
};

View File

@ -58,7 +58,7 @@ public:
/// The ID of the Watchpoint in the list.
//------------------------------------------------------------------
lldb::watch_id_t
Add (const lldb::WatchpointSP& wp_sp);
Add (const lldb::WatchpointSP& wp_sp, bool notify);
//------------------------------------------------------------------
/// Standard "Dump" method.
@ -180,7 +180,7 @@ public:
/// \b true if the watchpoint \a watchID was in the list.
//------------------------------------------------------------------
bool
Remove (lldb::watch_id_t watchID);
Remove (lldb::watch_id_t watchID, bool notify);
//------------------------------------------------------------------
/// Returns the number hit count of all watchpoints in this list.
@ -241,7 +241,7 @@ public:
SetEnabledAll (bool enabled);
void
RemoveAll ();
RemoveAll (bool notify);
//------------------------------------------------------------------
/// Sets the passed in Locker to hold the Watchpoint List mutex.

View File

@ -3113,10 +3113,10 @@ public:
// Process Watchpoints (optional)
//----------------------------------------------------------------------
virtual Error
EnableWatchpoint (Watchpoint *wp);
EnableWatchpoint (Watchpoint *wp, bool notify = true);
virtual Error
DisableWatchpoint (Watchpoint *wp);
DisableWatchpoint (Watchpoint *wp, bool notify = true);
//------------------------------------------------------------------
// Thread Queries

View File

@ -278,7 +278,8 @@ public:
{
eBroadcastBitBreakpointChanged = (1 << 0),
eBroadcastBitModulesLoaded = (1 << 1),
eBroadcastBitModulesUnloaded = (1 << 2)
eBroadcastBitModulesUnloaded = (1 << 2),
eBroadcastBitWatchpointChanged = (1 << 3)
};
// These two functions fill out the Broadcaster interface:

View File

@ -300,6 +300,20 @@ namespace lldb {
eBreakpointEventTypeThreadChanged = (1u << 11)
} BreakpointEventType;
typedef enum WatchpointEventType
{
eWatchpointEventTypeInvalidType = (1u << 0),
eWatchpointEventTypeAdded = (1u << 1),
eWatchpointEventTypeRemoved = (1u << 2),
eWatchpointEventTypeEnabled = (1u << 6),
eWatchpointEventTypeDisabled = (1u << 7),
eWatchpointEventTypeCommandChanged = (1u << 8),
eWatchpointEventTypeConditionChanged = (1u << 9),
eWatchpointEventTypeIgnoreChanged = (1u << 10),
eWatchpointEventTypeThreadChanged = (1u << 11),
eWatchpointEventTypeTypeChanged = (1u << 12)
} WatchpointEventType;
//----------------------------------------------------------------------
/// Programming language type.

View File

@ -238,7 +238,8 @@ public:
{
eBroadcastBitBreakpointChanged = (1 << 0),
eBroadcastBitModulesLoaded = (1 << 1),
eBroadcastBitModulesUnloaded = (1 << 2)
eBroadcastBitModulesUnloaded = (1 << 2),
eBroadcastBitWatchpointChanged = (1 << 3)
};
//------------------------------------------------------------------

View File

@ -84,6 +84,16 @@ public:
bool
GetDescription (lldb::SBStream &description, DescriptionLevel level);
static bool
EventIsWatchpointEvent (const lldb::SBEvent &event);
static lldb::WatchpointEventType
GetWatchpointEventTypeFromEvent (const lldb::SBEvent& event);
static lldb::SBWatchpoint
GetWatchpointFromEvent (const lldb::SBEvent& event);
};
} // namespace lldb

View File

@ -11,6 +11,7 @@
#include "lldb/API/SBDefines.h"
#include "lldb/API/SBAddress.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBStream.h"
#include "lldb/lldb-types.h"
@ -271,3 +272,27 @@ SBWatchpoint::SetSP (const lldb::WatchpointSP &sp)
{
m_opaque_sp = sp;
}
bool
SBWatchpoint::EventIsWatchpointEvent (const lldb::SBEvent &event)
{
return Watchpoint::WatchpointEventData::GetEventDataFromEvent(event.get()) != NULL;
}
WatchpointEventType
SBWatchpoint::GetWatchpointEventTypeFromEvent (const SBEvent& event)
{
if (event.IsValid())
return Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent (event.GetSP());
return eWatchpointEventTypeInvalidType;
}
SBWatchpoint
SBWatchpoint::GetWatchpointFromEvent (const lldb::SBEvent& event)
{
SBWatchpoint sb_watchpoint;
if (event.IsValid())
sb_watchpoint.m_opaque_sp = Watchpoint::WatchpointEventData::GetWatchpointFromEvent (event.GetSP());
return sb_watchpoint;
}

View File

@ -88,9 +88,14 @@ BreakpointList::RemoveAll (bool notify)
{
bp_collection::iterator pos, end = m_breakpoints.end();
for (pos = m_breakpoints.begin(); pos != end; ++pos)
{
if ((*pos)->GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged))
{
(*pos)->GetTarget().BroadcastEvent (Target::eBroadcastBitBreakpointChanged,
new Breakpoint::BreakpointEventData (eBreakpointEventTypeRemoved, *pos));
new Breakpoint::BreakpointEventData (eBreakpointEventTypeRemoved,
*pos));
}
}
}
m_breakpoints.erase (m_breakpoints.begin(), m_breakpoints.end());
}

View File

@ -45,7 +45,8 @@ Watchpoint::Watchpoint (Target& target, lldb::addr_t addr, size_t size, const Cl
m_watch_spec_str(),
m_type(),
m_error(),
m_options ()
m_options (),
m_being_created(true)
{
if (type && type->IsValid())
m_type = *type;
@ -64,6 +65,7 @@ Watchpoint::Watchpoint (Target& target, lldb::addr_t addr, size_t size, const Cl
m_target.GetProcessSP()->CalculateExecutionContext(exe_ctx);
CaptureWatchedValue (exe_ctx);
}
m_being_created = false;
}
Watchpoint::~Watchpoint()
@ -78,7 +80,7 @@ Watchpoint::SetCallback (WatchpointHitCallback callback, void *baton, bool is_sy
// or delete it when it goes goes out of scope.
m_options.SetCallback(callback, BatonSP (new Baton(baton)), is_synchronous);
//SendWatchpointChangedEvent (eWatchpointEventTypeCommandChanged);
SendWatchpointChangedEvent (eWatchpointEventTypeCommandChanged);
}
// This function is used when a baton needs to be freed and therefore is
@ -87,12 +89,14 @@ void
Watchpoint::SetCallback (WatchpointHitCallback callback, const BatonSP &callback_baton_sp, bool is_synchronous)
{
m_options.SetCallback(callback, callback_baton_sp, is_synchronous);
SendWatchpointChangedEvent (eWatchpointEventTypeCommandChanged);
}
void
Watchpoint::ClearCallback ()
{
m_options.ClearCallback ();
SendWatchpointChangedEvent (eWatchpointEventTypeCommandChanged);
}
void
@ -297,7 +301,7 @@ Watchpoint::IsDisabledDuringEphemeralMode()
}
void
Watchpoint::SetEnabled(bool enabled)
Watchpoint::SetEnabled(bool enabled, bool notify)
{
if (!enabled)
{
@ -309,14 +313,21 @@ Watchpoint::SetEnabled(bool enabled)
// Don't clear the snapshots for now.
// Within StopInfo.cpp, we purposely do disable/enable watchpoint while performing watchpoint actions.
}
bool changed = enabled != m_enabled;
m_enabled = enabled;
if (notify && !m_is_ephemeral && changed)
SendWatchpointChangedEvent (enabled ? eWatchpointEventTypeEnabled : eWatchpointEventTypeDisabled);
}
void
Watchpoint::SetWatchpointType (uint32_t type)
Watchpoint::SetWatchpointType (uint32_t type, bool notify)
{
int old_watch_read = m_watch_read;
int old_watch_write = m_watch_write;
m_watch_read = (type & LLDB_WATCH_TYPE_READ) != 0;
m_watch_write = (type & LLDB_WATCH_TYPE_WRITE) != 0;
if (notify && (old_watch_read != m_watch_read || old_watch_write != m_watch_write))
SendWatchpointChangedEvent (eWatchpointEventTypeTypeChanged);
}
bool
@ -338,7 +349,10 @@ Watchpoint::GetIgnoreCount () const
void
Watchpoint::SetIgnoreCount (uint32_t n)
{
bool changed = m_ignore_count != n;
m_ignore_count = n;
if (changed)
SendWatchpointChangedEvent (eWatchpointEventTypeIgnoreChanged);
}
bool
@ -360,6 +374,7 @@ Watchpoint::SetCondition (const char *condition)
// Pass NULL for expr_prefix (no translation-unit level definitions).
m_condition_ap.reset(new ClangUserExpression (condition, NULL, lldb::eLanguageTypeUnknown, ClangUserExpression::eResultTypeAny));
}
SendWatchpointChangedEvent (eWatchpointEventTypeConditionChanged);
}
const char *
@ -371,3 +386,105 @@ Watchpoint::GetConditionText () const
return NULL;
}
void
Watchpoint::SendWatchpointChangedEvent (lldb::WatchpointEventType eventKind)
{
if (!m_being_created
&& GetTarget().EventTypeHasListeners(Target::eBroadcastBitWatchpointChanged))
{
WatchpointEventData *data = new Watchpoint::WatchpointEventData (eventKind, shared_from_this());
GetTarget().BroadcastEvent (Target::eBroadcastBitWatchpointChanged, data);
}
}
void
Watchpoint::SendWatchpointChangedEvent (WatchpointEventData *data)
{
if (data == NULL)
return;
if (!m_being_created
&& GetTarget().EventTypeHasListeners(Target::eBroadcastBitWatchpointChanged))
GetTarget().BroadcastEvent (Target::eBroadcastBitWatchpointChanged, data);
else
delete data;
}
Watchpoint::WatchpointEventData::WatchpointEventData (WatchpointEventType sub_type,
const WatchpointSP &new_watchpoint_sp) :
EventData (),
m_watchpoint_event (sub_type),
m_new_watchpoint_sp (new_watchpoint_sp)
{
}
Watchpoint::WatchpointEventData::~WatchpointEventData ()
{
}
const ConstString &
Watchpoint::WatchpointEventData::GetFlavorString ()
{
static ConstString g_flavor ("Watchpoint::WatchpointEventData");
return g_flavor;
}
const ConstString &
Watchpoint::WatchpointEventData::GetFlavor () const
{
return WatchpointEventData::GetFlavorString ();
}
WatchpointSP &
Watchpoint::WatchpointEventData::GetWatchpoint ()
{
return m_new_watchpoint_sp;
}
WatchpointEventType
Watchpoint::WatchpointEventData::GetWatchpointEventType () const
{
return m_watchpoint_event;
}
void
Watchpoint::WatchpointEventData::Dump (Stream *s) const
{
}
const Watchpoint::WatchpointEventData *
Watchpoint::WatchpointEventData::GetEventDataFromEvent (const Event *event)
{
if (event)
{
const EventData *event_data = event->GetData();
if (event_data && event_data->GetFlavor() == WatchpointEventData::GetFlavorString())
return static_cast <const WatchpointEventData *> (event->GetData());
}
return NULL;
}
WatchpointEventType
Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent (const EventSP &event_sp)
{
const WatchpointEventData *data = GetEventDataFromEvent (event_sp.get());
if (data == NULL)
return eWatchpointEventTypeInvalidType;
else
return data->GetWatchpointEventType();
}
WatchpointSP
Watchpoint::WatchpointEventData::GetWatchpointFromEvent (const EventSP &event_sp)
{
WatchpointSP wp_sp;
const WatchpointEventData *data = GetEventDataFromEvent (event_sp.get());
if (data)
wp_sp = data->m_new_watchpoint_sp;
return wp_sp;
}

View File

@ -31,11 +31,17 @@ WatchpointList::~WatchpointList()
// Add a watchpoint to the list.
lldb::watch_id_t
WatchpointList::Add (const WatchpointSP &wp_sp)
WatchpointList::Add (const WatchpointSP &wp_sp, bool notify)
{
Mutex::Locker locker (m_mutex);
wp_sp->SetID(++m_next_wp_id);
m_watchpoints.push_back(wp_sp);
if (notify)
{
if (wp_sp->GetTarget().EventTypeHasListeners(Target::eBroadcastBitWatchpointChanged))
wp_sp->GetTarget().BroadcastEvent (Target::eBroadcastBitWatchpointChanged,
new Watchpoint::WatchpointEventData (eWatchpointEventTypeAdded, wp_sp));
}
return wp_sp->GetID();
}
@ -200,12 +206,19 @@ WatchpointList::GetWatchpointIDs() const
}
bool
WatchpointList::Remove (lldb::watch_id_t watch_id)
WatchpointList::Remove (lldb::watch_id_t watch_id, bool notify)
{
Mutex::Locker locker (m_mutex);
wp_collection::iterator pos = GetIDIterator(watch_id);
if (pos != m_watchpoints.end())
{
WatchpointSP wp_sp = *pos;
if (notify)
{
if (wp_sp->GetTarget().EventTypeHasListeners(Target::eBroadcastBitWatchpointChanged))
wp_sp->GetTarget().BroadcastEvent (Target::eBroadcastBitWatchpointChanged,
new Watchpoint::WatchpointEventData (eWatchpointEventTypeRemoved, wp_sp));
}
m_watchpoints.erase(pos);
return true;
}
@ -264,9 +277,25 @@ WatchpointList::SetEnabledAll (bool enabled)
}
void
WatchpointList::RemoveAll ()
WatchpointList::RemoveAll (bool notify)
{
Mutex::Locker locker(m_mutex);
if (notify)
{
{
wp_collection::iterator pos, end = m_watchpoints.end();
for (pos = m_watchpoints.begin(); pos != end; ++pos)
{
if ((*pos)->GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged))
{
(*pos)->GetTarget().BroadcastEvent (Target::eBroadcastBitWatchpointChanged,
new Watchpoint::WatchpointEventData (eWatchpointEventTypeRemoved,
*pos));
}
}
}
}
m_watchpoints.clear();
}

View File

@ -650,7 +650,7 @@ ProcessKDP::DisableBreakpoint (BreakpointSite *bp_site)
}
Error
ProcessKDP::EnableWatchpoint (Watchpoint *wp)
ProcessKDP::EnableWatchpoint (Watchpoint *wp, bool notify)
{
Error error;
error.SetErrorString ("watchpoints are not suppported in kdp remote debugging");
@ -658,7 +658,7 @@ ProcessKDP::EnableWatchpoint (Watchpoint *wp)
}
Error
ProcessKDP::DisableWatchpoint (Watchpoint *wp)
ProcessKDP::DisableWatchpoint (Watchpoint *wp, bool notify)
{
Error error;
error.SetErrorString ("watchpoints are not suppported in kdp remote debugging");

View File

@ -183,10 +183,10 @@ public:
// Process Watchpoints
//----------------------------------------------------------------------
virtual lldb_private::Error
EnableWatchpoint (lldb_private::Watchpoint *wp);
EnableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
virtual lldb_private::Error
DisableWatchpoint (lldb_private::Watchpoint *wp);
DisableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
CommunicationKDP &
GetCommunication()

View File

@ -2341,7 +2341,7 @@ GetGDBStoppointType (Watchpoint *wp)
}
Error
ProcessGDBRemote::EnableWatchpoint (Watchpoint *wp)
ProcessGDBRemote::EnableWatchpoint (Watchpoint *wp, bool notify)
{
Error error;
if (wp)
@ -2364,7 +2364,7 @@ ProcessGDBRemote::EnableWatchpoint (Watchpoint *wp)
{
if (m_gdb_comm.SendGDBStoppointTypePacket(type, true, addr, wp->GetByteSize()) == 0)
{
wp->SetEnabled(true);
wp->SetEnabled(true, notify);
return error;
}
else
@ -2383,7 +2383,7 @@ ProcessGDBRemote::EnableWatchpoint (Watchpoint *wp)
}
Error
ProcessGDBRemote::DisableWatchpoint (Watchpoint *wp)
ProcessGDBRemote::DisableWatchpoint (Watchpoint *wp, bool notify)
{
Error error;
if (wp)
@ -2393,6 +2393,7 @@ ProcessGDBRemote::DisableWatchpoint (Watchpoint *wp)
LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_WATCHPOINTS));
addr_t addr = wp->GetLoadAddress();
if (log)
log->Printf ("ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64 ") addr = 0x%8.8" PRIx64, watchID, (uint64_t)addr);
@ -2403,7 +2404,7 @@ ProcessGDBRemote::DisableWatchpoint (Watchpoint *wp)
// See also 'class WatchpointSentry' within StopInfo.cpp.
// This disabling attempt might come from the user-supplied actions, we'll route it in order for
// the watchpoint object to intelligently process this action.
wp->SetEnabled(false);
wp->SetEnabled(false, notify);
return error;
}
@ -2413,7 +2414,7 @@ ProcessGDBRemote::DisableWatchpoint (Watchpoint *wp)
// Pass down an appropriate z/Z packet...
if (m_gdb_comm.SendGDBStoppointTypePacket(type, false, addr, wp->GetByteSize()) == 0)
{
wp->SetEnabled(false);
wp->SetEnabled(false, notify);
return error;
}
else

View File

@ -202,10 +202,10 @@ public:
// Process Watchpoints
//----------------------------------------------------------------------
virtual lldb_private::Error
EnableWatchpoint (lldb_private::Watchpoint *wp);
EnableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
virtual lldb_private::Error
DisableWatchpoint (lldb_private::Watchpoint *wp);
DisableWatchpoint (lldb_private::Watchpoint *wp, bool notify = true);
virtual lldb_private::Error
GetWatchpointSupportInfo (uint32_t &num);

View File

@ -2579,7 +2579,7 @@ Process::ReadModuleFromMemory (const FileSpec& file_spec,
}
Error
Process::EnableWatchpoint (Watchpoint *watchpoint)
Process::EnableWatchpoint (Watchpoint *watchpoint, bool notify)
{
Error error;
error.SetErrorString("watchpoints are not supported");
@ -2587,7 +2587,7 @@ Process::EnableWatchpoint (Watchpoint *watchpoint)
}
Error
Process::DisableWatchpoint (Watchpoint *watchpoint)
Process::DisableWatchpoint (Watchpoint *watchpoint, bool notify)
{
Error error;
error.SetErrorString("watchpoints are not supported");

View File

@ -435,8 +435,9 @@ public:
{
if (process && watchpoint)
{
const bool notify = false;
watchpoint->TurnOnEphemeralMode();
process->DisableWatchpoint(watchpoint);
process->DisableWatchpoint(watchpoint, notify);
}
}
~WatchpointSentry()
@ -444,7 +445,10 @@ public:
if (process && watchpoint)
{
if (!watchpoint->IsDisabledDuringEphemeralMode())
process->EnableWatchpoint(watchpoint);
{
const bool notify = false;
process->EnableWatchpoint(watchpoint, notify);
}
watchpoint->TurnOffEphemeralMode();
}
}

View File

@ -101,6 +101,7 @@ Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::Plat
SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
SetEventName (eBroadcastBitWatchpointChanged, "watchpoint-changed");
CheckInWithManager();
@ -575,6 +576,7 @@ Target::CreateWatchpoint(lldb::addr_t addr, size_t size, const ClangASTType *typ
// of watchpoints limited by the hardware which the inferior is running on.
// Grab the list mutex while doing operations.
const bool notify = false; // Don't notify about all the state changes we do on creating the watchpoint.
Mutex::Locker locker;
this->GetWatchpointList().GetListMutex(locker);
WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
@ -587,28 +589,22 @@ Target::CreateWatchpoint(lldb::addr_t addr, size_t size, const ClangASTType *typ
// Return the existing watchpoint if both size and type match.
if (size == old_size && kind == old_type) {
wp_sp = matched_sp;
wp_sp->SetEnabled(false);
wp_sp->SetEnabled(false, notify);
} else {
// Nil the matched watchpoint; we will be creating a new one.
m_process_sp->DisableWatchpoint(matched_sp.get());
m_watchpoint_list.Remove(matched_sp->GetID());
m_process_sp->DisableWatchpoint(matched_sp.get(), notify);
m_watchpoint_list.Remove(matched_sp->GetID(), true);
}
}
if (!wp_sp)
{
Watchpoint *new_wp = new Watchpoint(*this, addr, size, type);
if (!new_wp)
{
error.SetErrorString("Watchpoint ctor failed, out of memory?");
return wp_sp;
}
new_wp->SetWatchpointType(kind);
wp_sp.reset(new_wp);
m_watchpoint_list.Add(wp_sp);
wp_sp.reset(new Watchpoint(*this, addr, size, type));
wp_sp->SetWatchpointType(kind, notify);
m_watchpoint_list.Add (wp_sp, true);
}
error = m_process_sp->EnableWatchpoint(wp_sp.get());
error = m_process_sp->EnableWatchpoint(wp_sp.get(), notify);
if (log)
log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
__FUNCTION__,
@ -619,7 +615,7 @@ Target::CreateWatchpoint(lldb::addr_t addr, size_t size, const ClangASTType *typ
{
// Enabling the watchpoint on the device side failed.
// Remove the said watchpoint from the list maintained by the target instance.
m_watchpoint_list.Remove(wp_sp->GetID());
m_watchpoint_list.Remove (wp_sp->GetID(), true);
// See if we could provide more helpful error message.
if (!CheckIfWatchpointsExhausted(this, error))
{
@ -755,7 +751,7 @@ Target::RemoveAllWatchpoints (bool end_to_end)
log->Printf ("Target::%s\n", __FUNCTION__);
if (!end_to_end) {
m_watchpoint_list.RemoveAll();
m_watchpoint_list.RemoveAll(true);
return true;
}
@ -775,7 +771,7 @@ Target::RemoveAllWatchpoints (bool end_to_end)
if (rc.Fail())
return false;
}
m_watchpoint_list.RemoveAll ();
m_watchpoint_list.RemoveAll (true);
return true; // Success!
}
@ -945,7 +941,7 @@ Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
if (DisableWatchpointByID (watch_id))
{
m_watchpoint_list.Remove(watch_id);
m_watchpoint_list.Remove(watch_id, true);
return true;
}
return false;

View File

@ -0,0 +1,5 @@
LEVEL = ../../../make
C_SOURCES := main.c
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,103 @@
"""Test that adding, deleting and modifying watchpoints sends the appropriate events."""
import os, time
import unittest2
import lldb
import lldbutil
from lldbtest import *
class TestWatchpointEvents (TestBase):
mydir = os.path.join("functionalities", "watchpoint", "watchpoint_events")
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@python_api_test
@dsym_test
def test_with_dsym_and_python_api(self):
"""Test that adding, deleting and modifying watchpoints sends the appropriate events."""
self.buildDsym()
self.step_over_stepping()
@expectedFailureLinux # bugzilla 14437
@python_api_test
@dwarf_test
def test_with_dwarf_and_python_api(self):
"""Test that adding, deleting and modifying watchpoints sends the appropriate events."""
self.buildDwarf()
self.step_over_stepping()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line numbers that we will step to in main:
self.main_source = "main.c"
def GetWatchpointEvent (self, event_type):
# We added a watchpoint so we should get a watchpoint added event.
event = lldb.SBEvent()
success = self.listener.WaitForEvent (1, event)
self.assertTrue(success == True, "Successfully got watchpoint event")
self.assertTrue (lldb.SBWatchpoint.EventIsWatchpointEvent(event), "Event is a watchpoint event.")
found_type = lldb.SBWatchpoint.GetWatchpointEventTypeFromEvent (event)
self.assertTrue (found_type == event_type, "Event is not correct type, expected: %d, found: %d"%(event_type, found_type))
# There shouldn't be another event waiting around:
found_event = self.listener.PeekAtNextEventForBroadcasterWithType (self.target_bcast, lldb.SBTarget.eBroadcastBitBreakpointChanged, event)
if found_event:
print "Found an event I didn't expect: ", event
self.assertTrue (not found_event, "Only one event per change.")
def step_over_stepping(self):
"""Use Python APIs to test stepping over and hitting breakpoints."""
exe = os.path.join(os.getcwd(), "a.out")
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
self.main_source_spec = lldb.SBFileSpec (self.main_source)
break_in_main = target.BreakpointCreateBySourceRegex ('// Put a breakpoint here.', self.main_source_spec)
self.assertTrue(break_in_main, VALID_BREAKPOINT)
# Now launch the process, and do not stop at entry point.
process = target.LaunchSimple (None, None, os.getcwd())
self.assertTrue(process, PROCESS_IS_VALID)
# The stop reason of the thread should be breakpoint.
threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_in_main)
if len(threads) != 1:
self.fail ("Failed to stop at first breakpoint in main.")
thread = threads[0]
frame = thread.GetFrameAtIndex(0)
local_var = frame.FindVariable ("local_var")
self.assertTrue (local_var.IsValid())
self.listener = lldb.SBListener("com.lldb.testsuite_listener")
self.target_bcast = target.GetBroadcaster()
self.target_bcast.AddListener (self.listener, lldb.SBTarget.eBroadcastBitWatchpointChanged)
self.listener.StartListeningForEvents (self.target_bcast, lldb.SBTarget.eBroadcastBitWatchpointChanged)
error = lldb.SBError()
local_watch = local_var.Watch(True, True, True, error)
if not error.Success():
self.fail ("Failed to make watchpoint for local_var: %s"%(error.GetCString()))
self.GetWatchpointEvent (lldb.eWatchpointEventTypeAdded)
# Now change some of the features of this watchpoint and make sure we get events:
local_watch.SetEnabled(False)
self.GetWatchpointEvent (lldb.eWatchpointEventTypeDisabled)
local_watch.SetIgnoreCount(10)
self.GetWatchpointEvent (lldb.eWatchpointEventTypeIgnoreChanged)
local_watch.SetCondition ("1 == 2")
self.GetWatchpointEvent (lldb.eWatchpointEventTypeConditionChanged)
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()

View File

@ -0,0 +1,9 @@
#include <stdio.h>
int
main (int argc, char **argv)
{
int local_var = 10;
printf ("local_var is: %d.\n", local_var++); // Put a breakpoint here.
return local_var;
}