[Lldb-commits] [lldb] r225538 - Make the list of synthetic children thread safe

Enrico Granata egranata at apple.com
Fri Jan 9 11:47:45 PST 2015


Author: enrico
Date: Fri Jan  9 13:47:45 2015
New Revision: 225538

URL: http://llvm.org/viewvc/llvm-project?rev=225538&view=rev
Log:
Make the list of synthetic children thread safe

I have been seeing a few crashes where LLDB tries to acquire a cached synthetic child by index, and crashes in the ClusterManager obtaining a shared_ptr for that ValueObject
That kind of crash most often means that I am holding on to a raw pointer to a ValueObject that was let go from the cluster

The main way that could happen is that the synthetic provider is being updated at the same time that some child is being accessed from the previous provider state

This fixes the problem by making the children be stored in a thread-safe map

Fixes rdar://18627964


Modified:
    lldb/trunk/include/lldb/Core/ThreadSafeSTLMap.h
    lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h
    lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp

Modified: lldb/trunk/include/lldb/Core/ThreadSafeSTLMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ThreadSafeSTLMap.h?rev=225538&r1=225537&r2=225538&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ThreadSafeSTLMap.h (original)
+++ lldb/trunk/include/lldb/Core/ThreadSafeSTLMap.h Fri Jan  9 13:47:45 2015
@@ -16,6 +16,7 @@
 
 // Other libraries and framework includes
 // Project includes
+#include "lldb/lldb-defines.h"
 #include "lldb/Host/Mutex.h"
 
 namespace lldb_private {

Modified: lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h?rev=225538&r1=225537&r2=225538&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObjectSyntheticFilter.h Fri Jan  9 13:47:45 2015
@@ -12,10 +12,10 @@
 
 // C Includes
 // C++ Includes
-#include <map>
 #include <vector>
 // Other libraries and framework includes
 // Project includes
+#include "lldb/Core/ThreadSafeSTLMap.h"
 #include "lldb/Core/ValueObject.h"
 
 namespace lldb_private {
@@ -154,8 +154,8 @@ protected:
     lldb::SyntheticChildrenSP m_synth_sp;
     std::unique_ptr<SyntheticChildrenFrontEnd> m_synth_filter_ap;
     
-    typedef std::map<uint32_t, ValueObject*> ByIndexMap;
-    typedef std::map<const char*, uint32_t> NameToIndexMap;
+    typedef ThreadSafeSTLMap<uint32_t, ValueObject*> ByIndexMap;
+    typedef ThreadSafeSTLMap<const char*, uint32_t> NameToIndexMap;
     
     typedef ByIndexMap::iterator ByIndexIterator;
     typedef NameToIndexMap::iterator NameToIndexIterator;

Modified: lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp?rev=225538&r1=225537&r2=225538&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectSyntheticFilter.cpp Fri Jan  9 13:47:45 2015
@@ -182,8 +182,8 @@ ValueObjectSynthetic::UpdateValue ()
     if (m_synth_filter_ap->Update() == false)
     {
         // filter said that cached values are stale
-        m_children_byindex.clear();
-        m_name_toindex.clear();
+        m_children_byindex.Clear();
+        m_name_toindex.Clear();
         // usually, an object's value can change but this does not alter its children count
         // for a synthetic VO that might indeed happen, so we need to tell the upper echelons
         // that they need to come back to us asking for children
@@ -216,23 +216,22 @@ ValueObjectSynthetic::GetChildAtIndex (s
 {
     UpdateValueIfNeeded();
     
-    ByIndexIterator iter = m_children_byindex.find(idx);
-    
-    if (iter == m_children_byindex.end())
+    ValueObject *valobj;
+    if (m_children_byindex.GetValueForKey(idx, valobj) == false)
     {
         if (can_create && m_synth_filter_ap.get() != NULL)
         {
             lldb::ValueObjectSP synth_guy = m_synth_filter_ap->GetChildAtIndex (idx);
             if (!synth_guy)
                 return synth_guy;
-            m_children_byindex[idx]= synth_guy.get();
+            m_children_byindex.SetValueForKey(idx, synth_guy.get());
             return synth_guy;
         }
         else
             return lldb::ValueObjectSP();
     }
     else
-        return iter->second->GetSP();
+        return valobj->GetSP();
 }
 
 lldb::ValueObjectSP
@@ -253,20 +252,21 @@ ValueObjectSynthetic::GetIndexOfChildWit
 {
     UpdateValueIfNeeded();
     
-    NameToIndexIterator iter = m_name_toindex.find(name.GetCString());
+    uint32_t found_index = UINT32_MAX;
+    bool did_find = m_name_toindex.GetValueForKey(name.GetCString(), found_index);
     
-    if (iter == m_name_toindex.end() && m_synth_filter_ap.get() != NULL)
+    if (!did_find && m_synth_filter_ap.get() != NULL)
     {
         uint32_t index = m_synth_filter_ap->GetIndexOfChildWithName (name);
         if (index == UINT32_MAX)
             return index;
-        m_name_toindex[name.GetCString()] = index;
+        m_name_toindex.SetValueForKey(name.GetCString(), index);
         return index;
     }
-    else if (iter == m_name_toindex.end() && m_synth_filter_ap.get() == NULL)
+    else if (!did_find && m_synth_filter_ap.get() == NULL)
         return UINT32_MAX;
     else /*if (iter != m_name_toindex.end())*/
-        return iter->second;
+        return found_index;
 }
 
 bool





More information about the lldb-commits mailing list