[Lldb-commits] [lldb] r140211 - in /lldb/trunk: include/lldb/Breakpoint/WatchpointLocationList.h include/lldb/Target/Target.h source/Breakpoint/WatchpointLocation.cpp source/Breakpoint/WatchpointLocationList.cpp source/Target/Target.cpp

Johnny Chen johnny.chen at apple.com
Tue Sep 20 16:28:55 PDT 2011


Author: johnny
Date: Tue Sep 20 18:28:55 2011
New Revision: 140211

URL: http://llvm.org/viewvc/llvm-project?rev=140211&view=rev
Log:
Add some watchpoint maintenance methods to the Target class.
Plus some minor changes to the WatchpointLocationList and WatchpointLocation classes.

Modified:
    lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/source/Breakpoint/WatchpointLocation.cpp
    lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h?rev=140211&r1=140210&r2=140211&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/WatchpointLocationList.h Tue Sep 20 18:28:55 2011
@@ -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.

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=140211&r1=140210&r2=140211&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Tue Sep 20 18:28:55 2011
@@ -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);
 

Modified: lldb/trunk/source/Breakpoint/WatchpointLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/WatchpointLocation.cpp?rev=140211&r1=140210&r2=140211&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/WatchpointLocation.cpp (original)
+++ lldb/trunk/source/Breakpoint/WatchpointLocation.cpp Tue Sep 20 18:28:55 2011
@@ -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,

Modified: lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp?rev=140211&r1=140210&r2=140211&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp (original)
+++ lldb/trunk/source/Breakpoint/WatchpointLocationList.cpp Tue Sep 20 18:28:55 2011
@@ -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();
+    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

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=140211&r1=140210&r2=140211&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Tue Sep 20 18:28:55 2011
@@ -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);





More information about the lldb-commits mailing list