summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2012-12-18 02:03:49 +0000
committerJim Ingham <jingham@apple.com>2012-12-18 02:03:49 +0000
commit1b5792e5ad1831aecd25ec50cc279e28e49e5c81 (patch)
treeda58d6cc035945e68cbf63cb89fe5ba5763b1999 /lldb
parent2a45e409a8ae86c7761d805ecb61b2052a4d570f (diff)
downloadbcm5719-llvm-1b5792e5ad1831aecd25ec50cc279e28e49e5c81.tar.gz
bcm5719-llvm-1b5792e5ad1831aecd25ec50cc279e28e49e5c81.zip
Adding events when watchpoints are set or changed.
<rdar://problem/11597849> llvm-svn: 170400
Diffstat (limited to 'lldb')
-rw-r--r--lldb/include/lldb/API/SBEvent.h1
-rw-r--r--lldb/include/lldb/API/SBFrame.h1
-rw-r--r--lldb/include/lldb/API/SBTarget.h3
-rw-r--r--lldb/include/lldb/API/SBWatchpoint.h9
-rw-r--r--lldb/include/lldb/Breakpoint/Watchpoint.h55
-rw-r--r--lldb/include/lldb/Breakpoint/WatchpointList.h6
-rw-r--r--lldb/include/lldb/Target/Process.h4
-rw-r--r--lldb/include/lldb/Target/Target.h3
-rw-r--r--lldb/include/lldb/lldb-enumerations.h14
-rw-r--r--lldb/scripts/Python/interface/SBTarget.i3
-rw-r--r--lldb/scripts/Python/interface/SBWatchpoint.i10
-rw-r--r--lldb/source/API/SBWatchpoint.cpp25
-rw-r--r--lldb/source/Breakpoint/BreakpointList.cpp7
-rw-r--r--lldb/source/Breakpoint/Watchpoint.cpp125
-rw-r--r--lldb/source/Breakpoint/WatchpointList.cpp35
-rw-r--r--lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp4
-rw-r--r--lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h4
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp11
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h4
-rw-r--r--lldb/source/Target/Process.cpp4
-rw-r--r--lldb/source/Target/StopInfo.cpp8
-rw-r--r--lldb/source/Target/Target.cpp30
-rw-r--r--lldb/test/functionalities/watchpoint/watchpoint_events/Makefile5
-rw-r--r--lldb/test/functionalities/watchpoint/watchpoint_events/TestWatchpointEvents.py103
-rw-r--r--lldb/test/functionalities/watchpoint/watchpoint_events/main.c9
25 files changed, 432 insertions, 51 deletions
diff --git a/lldb/include/lldb/API/SBEvent.h b/lldb/include/lldb/API/SBEvent.h
index f1160606528..6cb975a1ff7 100644
--- a/lldb/include/lldb/API/SBEvent.h
+++ b/lldb/include/lldb/API/SBEvent.h
@@ -75,6 +75,7 @@ protected:
friend class SBDebugger;
friend class SBProcess;
friend class SBThread;
+ friend class SBWatchpoint;
SBEvent (lldb::EventSP &event_sp);
diff --git a/lldb/include/lldb/API/SBFrame.h b/lldb/include/lldb/API/SBFrame.h
index ea26ed3c4fc..f8e86beb01f 100644
--- a/lldb/include/lldb/API/SBFrame.h
+++ b/lldb/include/lldb/API/SBFrame.h
@@ -12,7 +12,6 @@
#include "lldb/API/SBDefines.h"
#include "lldb/API/SBValueList.h"
-#include "lldb/API/SBWatchpoint.h"
namespace lldb {
diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 5adc8bec0f9..cdcc86fbf45 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -235,7 +235,8 @@ public:
{
eBroadcastBitBreakpointChanged = (1 << 0),
eBroadcastBitModulesLoaded = (1 << 1),
- eBroadcastBitModulesUnloaded = (1 << 2)
+ eBroadcastBitModulesUnloaded = (1 << 2),
+ eBroadcastBitWatchpointChanged = (1 << 3)
};
//------------------------------------------------------------------
diff --git a/lldb/include/lldb/API/SBWatchpoint.h b/lldb/include/lldb/API/SBWatchpoint.h
index d4f8d21a220..9bf51fd1ad0 100644
--- a/lldb/include/lldb/API/SBWatchpoint.h
+++ b/lldb/include/lldb/API/SBWatchpoint.h
@@ -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;
diff --git a/lldb/include/lldb/Breakpoint/Watchpoint.h b/lldb/include/lldb/Breakpoint/Watchpoint.h
index dda3eaead95..1a4551d27ba 100644
--- a/lldb/include/lldb/Breakpoint/Watchpoint.h
+++ b/lldb/include/lldb/Breakpoint/Watchpoint.h
@@ -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);
};
diff --git a/lldb/include/lldb/Breakpoint/WatchpointList.h b/lldb/include/lldb/Breakpoint/WatchpointList.h
index 92ae7bf41f6..d16cb25e3b7 100644
--- a/lldb/include/lldb/Breakpoint/WatchpointList.h
+++ b/lldb/include/lldb/Breakpoint/WatchpointList.h
@@ -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.
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index 2409bdb57d4..7ccb137c85b 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -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
diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index 5306c3205ea..354e7a917fb 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -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:
diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h
index 99c56739455..2b998741d35 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -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.
diff --git a/lldb/scripts/Python/interface/SBTarget.i b/lldb/scripts/Python/interface/SBTarget.i
index 9685c94fcc1..8b23dda8256 100644
--- a/lldb/scripts/Python/interface/SBTarget.i
+++ b/lldb/scripts/Python/interface/SBTarget.i
@@ -238,7 +238,8 @@ public:
{
eBroadcastBitBreakpointChanged = (1 << 0),
eBroadcastBitModulesLoaded = (1 << 1),
- eBroadcastBitModulesUnloaded = (1 << 2)
+ eBroadcastBitModulesUnloaded = (1 << 2),
+ eBroadcastBitWatchpointChanged = (1 << 3)
};
//------------------------------------------------------------------
diff --git a/lldb/scripts/Python/interface/SBWatchpoint.i b/lldb/scripts/Python/interface/SBWatchpoint.i
index 23c27d8905e..9a40131f518 100644
--- a/lldb/scripts/Python/interface/SBWatchpoint.i
+++ b/lldb/scripts/Python/interface/SBWatchpoint.i
@@ -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
diff --git a/lldb/source/API/SBWatchpoint.cpp b/lldb/source/API/SBWatchpoint.cpp
index 4794ba4c501..eb50fa8118e 100644
--- a/lldb/source/API/SBWatchpoint.cpp
+++ b/lldb/source/API/SBWatchpoint.cpp
@@ -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;
+}
diff --git a/lldb/source/Breakpoint/BreakpointList.cpp b/lldb/source/Breakpoint/BreakpointList.cpp
index 6a91bd6731a..5b40e2e67c4 100644
--- a/lldb/source/Breakpoint/BreakpointList.cpp
+++ b/lldb/source/Breakpoint/BreakpointList.cpp
@@ -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());
}
diff --git a/lldb/source/Breakpoint/Watchpoint.cpp b/lldb/source/Breakpoint/Watchpoint.cpp
index 4aadb9515ff..09cf2b671b1 100644
--- a/lldb/source/Breakpoint/Watchpoint.cpp
+++ b/lldb/source/Breakpoint/Watchpoint.cpp
@@ -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;
+}
diff --git a/lldb/source/Breakpoint/WatchpointList.cpp b/lldb/source/Breakpoint/WatchpointList.cpp
index ad4e873fe9a..6d62dffd22c 100644
--- a/lldb/source/Breakpoint/WatchpointList.cpp
+++ b/lldb/source/Breakpoint/WatchpointList.cpp
@@ -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();
}
diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
index 991cf680cad..7d33ccec68a 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
@@ -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");
diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h
index 9b24b4f5e78..bc26f6eea9e 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h
@@ -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()
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 9269c267d7e..0b6f12eca43 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -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
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index d19878f4837..520dfc44adc 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -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);
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 38622f0aa3e..aac93851596 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -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");
diff --git a/lldb/source/Target/StopInfo.cpp b/lldb/source/Target/StopInfo.cpp
index 9d62dd9df9a..77a960a260a 100644
--- a/lldb/source/Target/StopInfo.cpp
+++ b/lldb/source/Target/StopInfo.cpp
@@ -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();
}
}
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index e373efeea0a..de28ab161ee 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -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;
diff --git a/lldb/test/functionalities/watchpoint/watchpoint_events/Makefile b/lldb/test/functionalities/watchpoint/watchpoint_events/Makefile
new file mode 100644
index 00000000000..b09a579159d
--- /dev/null
+++ b/lldb/test/functionalities/watchpoint/watchpoint_events/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/test/functionalities/watchpoint/watchpoint_events/TestWatchpointEvents.py b/lldb/test/functionalities/watchpoint/watchpoint_events/TestWatchpointEvents.py
new file mode 100644
index 00000000000..b912981201d
--- /dev/null
+++ b/lldb/test/functionalities/watchpoint/watchpoint_events/TestWatchpointEvents.py
@@ -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()
diff --git a/lldb/test/functionalities/watchpoint/watchpoint_events/main.c b/lldb/test/functionalities/watchpoint/watchpoint_events/main.c
new file mode 100644
index 00000000000..4b917536a16
--- /dev/null
+++ b/lldb/test/functionalities/watchpoint/watchpoint_events/main.c
@@ -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;
+}
OpenPOWER on IntegriCloud