Add a lock in the UnwindTable class so two Targets won't try
authorJason Molenda <jmolenda@apple.com>
Wed, 18 Jun 2014 23:32:53 +0000 (23:32 +0000)
committerJason Molenda <jmolenda@apple.com>
Wed, 18 Jun 2014 23:32:53 +0000 (23:32 +0000)
to modify the same UnwindTable object simultaneously.  Fix
HistoryThread and HistoryUnwind's mutex lock acqusition to
retain the lock for the duration of the operation instead of
releasing the temporary immediately.
<rdar://problem/17055023>

llvm-svn: 211241

lldb/include/lldb/Symbol/UnwindTable.h
lldb/source/Plugins/Process/Utility/HistoryThread.cpp
lldb/source/Plugins/Process/Utility/HistoryUnwind.cpp
lldb/source/Symbol/UnwindTable.cpp

index 684cd19..3a89f9f 100644 (file)
@@ -14,6 +14,7 @@
 #include <map>
 
 #include "lldb/lldb-private.h" 
+#include "lldb/Host/Mutex.h"
 
 namespace lldb_private {
 
@@ -59,6 +60,7 @@ private:
     collection          m_unwinds;
 
     bool                m_initialized;  // delay some initialization until ObjectFile is set up
+    Mutex               m_mutex;
 
     DWARFCallFrameInfo* m_eh_frame;
     
index 11ad815..cdb0528 100644 (file)
@@ -78,7 +78,7 @@ HistoryThread::CreateRegisterContextForFrame (StackFrame *frame)
 lldb::StackFrameListSP
 HistoryThread::GetStackFrameList ()
 {
-    Mutex::Locker (m_framelist_mutex);
+    Mutex::Locker locker(m_framelist_mutex);
     if (m_framelist.get() == NULL)
     {
         m_framelist.reset (new StackFrameList (*this, StackFrameListSP(), true));
index 4659e48..bf8b3f5 100644 (file)
@@ -66,7 +66,7 @@ HistoryUnwind::DoCreateRegisterContextForFrame (StackFrame *frame)
 bool
 HistoryUnwind::DoGetFrameInfoAtIndex (uint32_t frame_idx, lldb::addr_t& cfa, lldb::addr_t& pc)
 {
-    Mutex::Locker (m_unwind_mutex);
+    Mutex::Locker locker(m_unwind_mutex);
     if (frame_idx < m_pcs.size())
     {
         cfa = frame_idx;
index 9aaacb3..df9f5b9 100644 (file)
@@ -29,6 +29,7 @@ UnwindTable::UnwindTable (ObjectFile& objfile) :
     m_object_file (objfile), 
     m_unwinds (),
     m_initialized (false),
+    m_mutex (),
     m_eh_frame (nullptr)
 {
 }
@@ -42,6 +43,11 @@ UnwindTable::Initialize ()
     if (m_initialized)
         return;
 
+    Mutex::Locker locker(m_mutex);
+
+    if (m_initialized) // check again once we've acquired the lock
+        return;
+
     SectionList* sl = m_object_file.GetSectionList ();
     if (sl)
     {
@@ -68,6 +74,8 @@ UnwindTable::GetFuncUnwindersContainingAddress (const Address& addr, SymbolConte
 
     Initialize();
 
+    Mutex::Locker locker(m_mutex);
+
     // There is an UnwindTable per object file, so we can safely use file handles
     addr_t file_addr = addr.GetFileAddress();
     iterator end = m_unwinds.end ();
@@ -128,6 +136,7 @@ UnwindTable::GetUncachedFuncUnwindersContainingAddress (const Address& addr, Sym
 void
 UnwindTable::Dump (Stream &s)
 {
+    Mutex::Locker locker(m_mutex);
     s.Printf("UnwindTable for '%s':\n", m_object_file.GetFileSpec().GetPath().c_str());
     const_iterator begin = m_unwinds.begin();
     const_iterator end = m_unwinds.end();