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,11 +217,21 @@ 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; - for (auto &pair : m_map) { + for (auto &pair : map_snapshot) { TypeSystem *type_system = pair.second.get(); if (!type_system || visited.count(type_system)) continue;