diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h @@ -75,8 +75,9 @@ typedef llvm::DenseMap DIEToDeclContextMap; - typedef std::multimap - DeclContextToDIEMap; + typedef std::multimap> + DeclContextToFileDIERefMap; typedef llvm::DenseMap DIEToModuleMap; @@ -86,7 +87,7 @@ lldb_private::TypeSystemClang &m_ast; DIEToDeclMap m_die_to_decl; DIEToDeclContextMap m_die_to_decl_ctx; - DeclContextToDIEMap m_decl_ctx_to_die; + DeclContextToFileDIERefMap m_decl_ctx_to_filedieref; DIEToModuleMap m_die_to_module; std::unique_ptr m_clang_ast_importer_up; /// @} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -58,7 +58,7 @@ using namespace lldb; using namespace lldb_private; DWARFASTParserClang::DWARFASTParserClang(TypeSystemClang &ast) - : m_ast(ast), m_die_to_decl_ctx(), m_decl_ctx_to_die() {} + : m_ast(ast), m_die_to_decl_ctx(), m_decl_ctx_to_filedieref() {} DWARFASTParserClang::~DWARFASTParserClang() = default; @@ -2099,11 +2099,17 @@ lldb_private::CompilerDeclContext decl_context) { auto opaque_decl_ctx = (clang::DeclContext *)decl_context.GetOpaqueDeclContext(); - for (auto it = m_decl_ctx_to_die.find(opaque_decl_ctx); - it != m_decl_ctx_to_die.end() && it->first == opaque_decl_ctx; - it = m_decl_ctx_to_die.erase(it)) - for (DWARFDIE decl : it->second.children()) + for (auto it = m_decl_ctx_to_filedieref.find(opaque_decl_ctx); + it != m_decl_ctx_to_filedieref.end() && it->first == opaque_decl_ctx; + it = m_decl_ctx_to_filedieref.erase(it)) { + // We need to store also SymbolFileDWARF * as we cannot assume + // m_ast.GetSymbolFile() is actually a SymbolFileDWARF, it can be + // a SymbolFileDWARFDebugMap for Apple binaries. + std::pair declpair = it->second; + DWARFDIE die = declpair.first->GetDIE(declpair.second); + for (DWARFDIE decl : die.children()) GetClangDeclForDIE(decl); + } } CompilerDecl DWARFASTParserClang::GetDeclForUIDFromDWARF(const DWARFDIE &die) { @@ -3447,9 +3453,12 @@ void DWARFASTParserClang::LinkDeclContextToDIE(clang::DeclContext *decl_ctx, const DWARFDIE &die) { m_die_to_decl_ctx[die.GetDIE()] = decl_ctx; + SymbolFileDWARF *sym_file = &die.GetCU()->GetSymbolFileDWARF(); + DIERef ref = *die.GetDIERef(); // There can be many DIEs for a single decl context - // m_decl_ctx_to_die[decl_ctx].insert(die.GetDIE()); - m_decl_ctx_to_die.insert(std::make_pair(decl_ctx, die)); + // m_decl_ctx_to_filedieref[decl_ctx].insert(...); + m_decl_ctx_to_filedieref.insert( + std::make_pair(decl_ctx, std::make_pair(sym_file, ref))); } bool DWARFASTParserClang::CopyUniqueClassMethodTypes( diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp --- a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp +++ b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp @@ -26,7 +26,7 @@ std::vector GetDeclContextToDIEMapKeys() { std::vector keys; - for (const auto &it : m_decl_ctx_to_die) + for (const auto &it : m_decl_ctx_to_filedieref) keys.push_back(it.first); return keys; }