diff options
author | Johnny Chen <johnny.chen@apple.com> | 2011-09-20 23:28:55 +0000 |
---|---|---|
committer | Johnny Chen <johnny.chen@apple.com> | 2011-09-20 23:28:55 +0000 |
commit | 86364b452164b2bb678cd7fd6a0bc0aebdea723e (patch) | |
tree | f848b925a3ca2beeac5224e67c6ae0a13bb56ecb | |
parent | 1815b688cc04f8390ed63e9e9405a503a256851b (diff) | |
download | bcm5719-llvm-86364b452164b2bb678cd7fd6a0bc0aebdea723e.tar.gz bcm5719-llvm-86364b452164b2bb678cd7fd6a0bc0aebdea723e.zip |
Add some watchpoint maintenance methods to the Target class.
Plus some minor changes to the WatchpointLocationList and WatchpointLocation classes.
llvm-svn: 140211
-rw-r--r-- | lldb/include/lldb/Breakpoint/WatchpointLocationList.h | 5 | ||||
-rw-r--r-- | lldb/include/lldb/Target/Target.h | 22 | ||||
-rw-r--r-- | lldb/source/Breakpoint/WatchpointLocation.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Breakpoint/WatchpointLocationList.cpp | 18 | ||||
-rw-r--r-- | lldb/source/Target/Target.cpp | 157 |
5 files changed, 195 insertions, 10 deletions
diff --git a/lldb/include/lldb/Breakpoint/WatchpointLocationList.h b/lldb/include/lldb/Breakpoint/WatchpointLocationList.h index db46a410ec4..32ad0998784 100644 --- a/lldb/include/lldb/Breakpoint/WatchpointLocationList.h +++ b/lldb/include/lldb/Breakpoint/WatchpointLocationList.h @@ -209,7 +209,10 @@ public: lldb::DescriptionLevel level); void - ClearAllWatchpointLocations (); + SetEnabledAll (bool enabled); + + void + RemoveAll (); //------------------------------------------------------------------ /// Sets the passed in Locker to hold the Watchpoint Location List mutex. diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 0a78b972675..0defa9dd310 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -180,6 +180,10 @@ private: const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp); + // Helper function. + bool + ProcessIsValid (); + public: ~Target(); @@ -311,6 +315,24 @@ public: bool RemoveBreakpointByID (lldb::break_id_t break_id); + bool + RemoveAllWatchpointLocations (); + + bool + DisableAllWatchpointLocations (); + + bool + EnableAllWatchpointLocations (); + + bool + DisableWatchpointLocationByID (lldb::watch_id_t watch_id); + + bool + EnableWatchpointLocationByID (lldb::watch_id_t watch_id); + + bool + RemoveWatchpointLocationByID (lldb::watch_id_t watch_id); + void ModulesDidLoad (ModuleList &module_list); diff --git a/lldb/source/Breakpoint/WatchpointLocation.cpp b/lldb/source/Breakpoint/WatchpointLocation.cpp index b4b9441c910..f647e42d882 100644 --- a/lldb/source/Breakpoint/WatchpointLocation.cpp +++ b/lldb/source/Breakpoint/WatchpointLocation.cpp @@ -113,7 +113,8 @@ WatchpointLocation::DumpWithLevel(Stream *s, lldb::DescriptionLevel description_ s->Printf("\n declare @ '%s'", m_decl_str.c_str()); if (description_level >= lldb::eDescriptionLevelVerbose) - s->Printf("\n hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p", + s->Printf("\n hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p", + GetHardwareIndex(), GetHitCount(), GetIgnoreCount(), m_callback, diff --git a/lldb/source/Breakpoint/WatchpointLocationList.cpp b/lldb/source/Breakpoint/WatchpointLocationList.cpp index c39bd5861c1..4e6dbb782a3 100644 --- a/lldb/source/Breakpoint/WatchpointLocationList.cpp +++ b/lldb/source/Breakpoint/WatchpointLocationList.cpp @@ -232,13 +232,27 @@ WatchpointLocationList::GetDescription (Stream *s, lldb::DescriptionLevel level) } void -WatchpointLocationList::ClearAllWatchpointLocations () +WatchpointLocationList::SetEnabledAll (bool enabled) { Mutex::Locker locker(m_mutex); + addr_map::iterator pos, end = m_address_to_location.end(); + for (pos = m_address_to_location.begin(); pos != end; ++pos) + pos->second->SetEnabled (enabled); +} + +void +WatchpointLocationList::RemoveAll () +{ + Mutex::Locker locker(m_mutex); + addr_map::iterator pos, end = m_address_to_location.end(); for (pos = m_address_to_location.begin(); pos != end; ++pos) - m_address_to_location.erase(pos); + m_address_to_location.erase(pos); + + collection::iterator p, e = m_locations.end(); + for (p = m_locations.begin(); p != e; ++pos) + m_locations.erase(p); } void diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index fd9eb2438fa..154946206d9 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -124,7 +124,7 @@ Target::DeleteCurrentProcess () // clean up needs some help from the process. m_breakpoint_list.ClearAllBreakpointSites(); m_internal_breakpoint_list.ClearAllBreakpointSites(); - m_watchpoint_location_list.ClearAllWatchpointLocations(); + m_watchpoint_location_list.RemoveAll(); m_process_sp.reset(); } } @@ -331,6 +331,12 @@ Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resol return bp_sp; } +bool +Target::ProcessIsValid() +{ + return (m_process_sp && m_process_sp->IsAlive()); +} + // See also WatchpointLocation::SetWatchpointType(uint32_t type) and // the OptionGroupWatchpoint::WatchType enum type. WatchpointLocationSP @@ -342,8 +348,7 @@ Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type) __FUNCTION__, addr, size, type); WatchpointLocationSP wp_loc_sp; - bool process_is_valid = m_process_sp && m_process_sp->IsAlive(); - if (!process_is_valid) + if (!ProcessIsValid()) return wp_loc_sp; if (addr == LLDB_INVALID_ADDRESS || size == 0) return wp_loc_sp; @@ -500,6 +505,148 @@ Target::EnableBreakpointByID (break_id_t break_id) return false; } +// Assumption: caller holds the list mutex lock for m_watchpoint_location_list. +bool +Target::RemoveAllWatchpointLocations () +{ + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); + if (log) + log->Printf ("Target::%s\n", __FUNCTION__); + + if (!ProcessIsValid()) + return false; + + size_t num_watchpoints = m_watchpoint_location_list.GetSize(); + for (size_t i = 0; i < num_watchpoints; ++i) + { + WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i); + if (!wp_loc_sp) + return false; + + Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get()); + if (rc.Fail()) + return false; + } + m_watchpoint_location_list.RemoveAll (); + return true; // Success! +} + +// Assumption: caller holds the list mutex lock for m_watchpoint_location_list. +bool +Target::DisableAllWatchpointLocations () +{ + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); + if (log) + log->Printf ("Target::%s\n", __FUNCTION__); + + if (!ProcessIsValid()) + return false; + + size_t num_watchpoints = m_watchpoint_location_list.GetSize(); + for (size_t i = 0; i < num_watchpoints; ++i) + { + WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i); + if (!wp_loc_sp) + return false; + + Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get()); + if (rc.Fail()) + return false; + } + m_watchpoint_location_list.SetEnabledAll (false); + return true; // Success! +} + +// Assumption: caller holds the list mutex lock for m_watchpoint_location_list. +bool +Target::EnableAllWatchpointLocations () +{ + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); + if (log) + log->Printf ("Target::%s\n", __FUNCTION__); + + if (!ProcessIsValid()) + return false; + + size_t num_watchpoints = m_watchpoint_location_list.GetSize(); + for (size_t i = 0; i < num_watchpoints; ++i) + { + WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i); + if (!wp_loc_sp) + return false; + + Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get()); + if (rc.Fail()) + return false; + } + m_watchpoint_location_list.SetEnabledAll (true); + return true; // Success! +} + +// Assumption: caller holds the list mutex lock for m_watchpoint_location_list. +bool +Target::DisableWatchpointLocationByID (lldb::watch_id_t watch_id) +{ + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); + if (log) + log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); + + if (!ProcessIsValid()) + return false; + + WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.FindByID (watch_id); + if (wp_loc_sp) + { + Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get()); + if (rc.Fail()) + return false; + + wp_loc_sp->SetEnabled (false); + return true; + } + return false; +} + +// Assumption: caller holds the list mutex lock for m_watchpoint_location_list. +bool +Target::EnableWatchpointLocationByID (lldb::watch_id_t watch_id) +{ + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); + if (log) + log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); + + if (!ProcessIsValid()) + return false; + + WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.FindByID (watch_id); + if (wp_loc_sp) + { + Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get()); + if (rc.Fail()) + return false; + + wp_loc_sp->SetEnabled (true); + return true; + } + return false; +} + +// Assumption: caller holds the list mutex lock for m_watchpoint_location_list. +bool +Target::RemoveWatchpointLocationByID (lldb::watch_id_t watch_id) +{ + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); + if (log) + log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); + + if (DisableWatchpointLocationByID (watch_id)) + { + m_watchpoint_location_list.Remove(watch_id); + return true; + } + return false; +} + ModuleSP Target::GetExecutableModule () { @@ -722,8 +869,6 @@ Target::ReadMemory (const Address& addr, if (load_addr_ptr) *load_addr_ptr = LLDB_INVALID_ADDRESS; - bool process_is_valid = m_process_sp && m_process_sp->IsAlive(); - size_t bytes_read = 0; addr_t load_addr = LLDB_INVALID_ADDRESS; @@ -759,7 +904,7 @@ Target::ReadMemory (const Address& addr, return bytes_read; } - if (process_is_valid) + if (ProcessIsValid()) { if (load_addr == LLDB_INVALID_ADDRESS) load_addr = resolved_addr.GetLoadAddress (this); |