[Lldb-commits] [lldb] r228777 - As part of the cleanup when a process dies, tell watchpoints to forget their previously recorded values

Enrico Granata egranata at apple.com
Tue Feb 10 16:37:55 PST 2015


Author: enrico
Date: Tue Feb 10 18:37:54 2015
New Revision: 228777

URL: http://llvm.org/viewvc/llvm-project?rev=228777&view=rev
Log:
As part of the cleanup when a process dies, tell watchpoints to forget their previously recorded values

Because types are not reliably protected against the death of their owners, having ValueObjects lurking around like that past the useful lifetime of their owner processes is a potential source of crashes
That is - in itself - worth fixing at some point, but for this case, watchpoints holding on to old values don't offer enough value to make the larger fix worth

Fixes rdar://19788756


Modified:
    lldb/trunk/include/lldb/Breakpoint/Watchpoint.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/include/lldb/Utility/SharingPtr.h
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Breakpoint/Watchpoint.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/Watchpoint.h?rev=228777&r1=228776&r2=228777&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/Watchpoint.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/Watchpoint.h Tue Feb 10 18:37:54 2015
@@ -205,7 +205,18 @@ private:
     friend class Target;
     friend class WatchpointList;
 
-    void        ResetHitCount() { m_hit_count = 0; }
+    void
+    ResetHitCount ()
+    {
+        m_hit_count = 0;
+    }
+    
+    void
+    ResetHistoricValues ()
+    {
+        m_old_value_sp.reset(nullptr);
+        m_new_value_sp.reset(nullptr);
+    }
 
     Target      &m_target;
     bool        m_enabled;             // Is this watchpoint enabled

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=228777&r1=228776&r2=228777&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Tue Feb 10 18:37:54 2015
@@ -783,6 +783,9 @@ public:
     ClearAllWatchpointHitCounts ();
 
     bool
+    ClearAllWatchpointHistoricValues ();
+    
+    bool
     IgnoreAllWatchpoints (uint32_t ignore_count);
 
     bool

Modified: lldb/trunk/include/lldb/Utility/SharingPtr.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/SharingPtr.h?rev=228777&r1=228776&r2=228777&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/SharingPtr.h (original)
+++ lldb/trunk/include/lldb/Utility/SharingPtr.h Tue Feb 10 18:37:54 2015
@@ -154,6 +154,7 @@ public:
     void swap(SharingPtr& r);
     void reset();
     template<class Y> void reset(Y* p);
+    void reset(std::nullptr_t);
 
     element_type* get() const {return ptr_;}
     element_type& operator*() const {return *ptr_;}
@@ -295,6 +296,14 @@ SharingPtr<T>::reset()
 }
 
 template<class T>
+inline
+void
+SharingPtr<T>::reset (std::nullptr_t p)
+{
+    reset();
+}
+    
+template<class T>
 template<class Y>
 inline
 void
@@ -547,7 +556,7 @@ public:
         if (cb_)
             cb_(baton_, *this, false);
     }
-
+    
     void SetCallback(Callback cb, void* baton)
     {
         cb_ = cb;

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=228777&r1=228776&r2=228777&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Tue Feb 10 18:37:54 2015
@@ -175,6 +175,7 @@ Target::CleanupProcess ()
     this->GetWatchpointList().GetListMutex(locker);
     DisableAllWatchpoints(false);
     ClearAllWatchpointHitCounts();
+    ClearAllWatchpointHistoricValues();
 }
 
 void
@@ -906,6 +907,26 @@ Target::ClearAllWatchpointHitCounts ()
     }
     return true; // Success!
 }
+
+// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
+bool
+Target::ClearAllWatchpointHistoricValues ()
+{
+    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
+    if (log)
+        log->Printf ("Target::%s\n", __FUNCTION__);
+    
+    size_t num_watchpoints = m_watchpoint_list.GetSize();
+    for (size_t i = 0; i < num_watchpoints; ++i)
+    {
+        WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
+        if (!wp_sp)
+            return false;
+        
+        wp_sp->ResetHistoricValues();
+    }
+    return true; // Success!
+}
 
 // Assumption: Caller holds the list mutex lock for m_watchpoint_list
 // during these operations.





More information about the lldb-commits mailing list