diff --git a/lldb/source/Symbol/TypeSystem.cpp b/lldb/source/Symbol/TypeSystem.cpp --- a/lldb/source/Symbol/TypeSystem.cpp +++ b/lldb/source/Symbol/TypeSystem.cpp @@ -217,7 +217,17 @@ void TypeSystemMap::ForEach( std::function const &callback) { - std::lock_guard guard(m_mutex); + + // The callback may call into this function again causing + // us to lock m_mutex twice if we held it across the callback. + // Since we just care about guarding access to 'm_map', make + // a local copy and iterate over that instead. + collection map_snapshot; + { + std::lock_guard guard(m_mutex); + map_snapshot = m_map; + } + // Use a std::set so we only call the callback once for each unique // TypeSystem instance. llvm::DenseSet visited;