Add some watchpoint maintenance methods to the Target class.
Plus some minor changes to the WatchpointLocationList and WatchpointLocation classes.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@140211 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/lldb/Breakpoint/WatchpointLocationList.h b/include/lldb/Breakpoint/WatchpointLocationList.h
index db46a41..32ad099 100644
--- a/include/lldb/Breakpoint/WatchpointLocationList.h
+++ b/include/lldb/Breakpoint/WatchpointLocationList.h
@@ -209,7 +209,10 @@
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/include/lldb/Target/Target.h b/include/lldb/Target/Target.h
index 0a78b97..0defa9d 100644
--- a/include/lldb/Target/Target.h
+++ b/include/lldb/Target/Target.h
@@ -180,6 +180,10 @@
const ArchSpec &target_arch,
const lldb::PlatformSP &platform_sp);
+ // Helper function.
+ bool
+ ProcessIsValid ();
+
public:
~Target();
@@ -311,6 +315,24 @@
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/source/Breakpoint/WatchpointLocation.cpp b/source/Breakpoint/WatchpointLocation.cpp
index b4b9441..f647e42 100644
--- a/source/Breakpoint/WatchpointLocation.cpp
+++ b/source/Breakpoint/WatchpointLocation.cpp
@@ -113,7 +113,8 @@
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/source/Breakpoint/WatchpointLocationList.cpp b/source/Breakpoint/WatchpointLocationList.cpp
index c39bd58..4e6dbb7 100644
--- a/source/Breakpoint/WatchpointLocationList.cpp
+++ b/source/Breakpoint/WatchpointLocationList.cpp
@@ -232,13 +232,27 @@
}
void
-WatchpointLocationList::ClearAllWatchpointLocations ()
+WatchpointLocationList::SetEnabledAll (bool enabled)
{
Mutex::Locker locker(m_mutex);
- addr_map::iterator pos, end = m_address_to_location.end();
+ 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);
+ 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);
+
+ collection::iterator p, e = m_locations.end();
+ for (p = m_locations.begin(); p != e; ++pos)
+ m_locations.erase(p);
}
void
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index fd9eb24..1549462 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -124,7 +124,7 @@
// 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 @@
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 @@
__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 @@
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 @@
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 @@
return bytes_read;
}
- if (process_is_valid)
+ if (ProcessIsValid())
{
if (load_addr == LLDB_INVALID_ADDRESS)
load_addr = resolved_addr.GetLoadAddress (this);