[Lldb-commits] [lldb] r289100 - Fixed a crasher that has been borking out heap for a long time.

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Thu Dec 8 12:38:20 PST 2016


Author: gclayton
Date: Thu Dec  8 14:38:19 2016
New Revision: 289100

URL: http://llvm.org/viewvc/llvm-project?rev=289100&view=rev
Log:
Fixed a crasher that has been borking out heap for a long time. 

ThreadList had an assignment operator that didn't lock the "rhs" thread list object. This means a thread list can be mutated while it is being copied.

The copy constructor calls the assignment operator as well. So this fixes the unsafe threaded access to ThreadList which we believe is responsible for a lot of crashes.

<rdar://problem/28075793>

Modified:
    lldb/trunk/include/lldb/Target/ThreadCollection.h
    lldb/trunk/include/lldb/Target/ThreadList.h
    lldb/trunk/source/Target/ThreadList.cpp

Modified: lldb/trunk/include/lldb/Target/ThreadCollection.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadCollection.h?rev=289100&r1=289099&r2=289100&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ThreadCollection.h (original)
+++ lldb/trunk/include/lldb/Target/ThreadCollection.h Thu Dec  8 14:38:19 2016
@@ -48,11 +48,11 @@ public:
     return ThreadIterable(m_threads, GetMutex());
   }
 
-  virtual std::recursive_mutex &GetMutex() { return m_mutex; }
+  virtual std::recursive_mutex &GetMutex() const { return m_mutex; }
 
 protected:
   collection m_threads;
-  std::recursive_mutex m_mutex;
+  mutable std::recursive_mutex m_mutex;
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/include/lldb/Target/ThreadList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadList.h?rev=289100&r1=289099&r2=289100&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ThreadList.h (original)
+++ lldb/trunk/include/lldb/Target/ThreadList.h Thu Dec  8 14:38:19 2016
@@ -135,7 +135,7 @@ public:
 
   void SetStopID(uint32_t stop_id);
 
-  std::recursive_mutex &GetMutex() override;
+  std::recursive_mutex &GetMutex() const override;
 
   void Update(ThreadList &rhs);
 

Modified: lldb/trunk/source/Target/ThreadList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadList.cpp?rev=289100&r1=289099&r2=289100&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadList.cpp (original)
+++ lldb/trunk/source/Target/ThreadList.cpp Thu Dec  8 14:38:19 2016
@@ -44,6 +44,7 @@ const ThreadList &ThreadList::operator=(
     // Lock both mutexes to make sure neither side changes anyone on us
     // while the assignment occurs
     std::lock_guard<std::recursive_mutex> guard(GetMutex());
+    std::lock_guard<std::recursive_mutex> rhs_guard(rhs.GetMutex());
 
     m_process = rhs.m_process;
     m_stop_id = rhs.m_stop_id;
@@ -749,7 +750,7 @@ void ThreadList::Flush() {
     (*pos)->Flush();
 }
 
-std::recursive_mutex &ThreadList::GetMutex() {
+std::recursive_mutex &ThreadList::GetMutex() const {
   return m_process->m_thread_mutex;
 }
 




More information about the lldb-commits mailing list