diff options
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/API/SBWatchpoint.cpp | 25 | ||||
-rw-r--r-- | lldb/source/Breakpoint/BreakpointList.cpp | 7 | ||||
-rw-r--r-- | lldb/source/Breakpoint/Watchpoint.cpp | 125 | ||||
-rw-r--r-- | lldb/source/Breakpoint/WatchpointList.cpp | 35 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h | 4 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp | 11 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h | 4 | ||||
-rw-r--r-- | lldb/source/Target/Process.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Target/StopInfo.cpp | 8 | ||||
-rw-r--r-- | lldb/source/Target/Target.cpp | 30 |
11 files changed, 217 insertions, 40 deletions
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; |