From 5cba569c4b435dcef195dccc736f37215da14856 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Wed, 18 Jun 2014 23:32:53 +0000 Subject: [PATCH] Add a lock in the UnwindTable class so two Targets won't try 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. llvm-svn: 211241 --- lldb/include/lldb/Symbol/UnwindTable.h | 2 ++ lldb/source/Plugins/Process/Utility/HistoryThread.cpp | 2 +- lldb/source/Plugins/Process/Utility/HistoryUnwind.cpp | 2 +- lldb/source/Symbol/UnwindTable.cpp | 9 +++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lldb/include/lldb/Symbol/UnwindTable.h b/lldb/include/lldb/Symbol/UnwindTable.h index 684cd19d91ea..3a89f9f1f3c6 100644 --- a/lldb/include/lldb/Symbol/UnwindTable.h +++ b/lldb/include/lldb/Symbol/UnwindTable.h @@ -14,6 +14,7 @@ #include #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; diff --git a/lldb/source/Plugins/Process/Utility/HistoryThread.cpp b/lldb/source/Plugins/Process/Utility/HistoryThread.cpp index 11ad81521761..cdb0528394cc 100644 --- a/lldb/source/Plugins/Process/Utility/HistoryThread.cpp +++ b/lldb/source/Plugins/Process/Utility/HistoryThread.cpp @@ -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)); diff --git a/lldb/source/Plugins/Process/Utility/HistoryUnwind.cpp b/lldb/source/Plugins/Process/Utility/HistoryUnwind.cpp index 4659e4859625..bf8b3f5fb6ca 100644 --- a/lldb/source/Plugins/Process/Utility/HistoryUnwind.cpp +++ b/lldb/source/Plugins/Process/Utility/HistoryUnwind.cpp @@ -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; diff --git a/lldb/source/Symbol/UnwindTable.cpp b/lldb/source/Symbol/UnwindTable.cpp index 9aaacb30ee92..df9f5b932565 100644 --- a/lldb/source/Symbol/UnwindTable.cpp +++ b/lldb/source/Symbol/UnwindTable.cpp @@ -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();