diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h @@ -48,8 +48,8 @@ virtual lldb_private::CompilerDeclContext GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) = 0; - virtual std::vector - GetDIEForDeclContext(lldb_private::CompilerDeclContext decl_context) = 0; + virtual void EnsureAllDIEsInDeclContextHaveBeenParsed( + lldb_private::CompilerDeclContext decl_context) = 0; static llvm::Optional ParseChildArrayInfo(const DWARFDIE &parent_die, 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 @@ -51,8 +51,8 @@ lldb_private::CompilerDecl GetDeclForUIDFromDWARF(const DWARFDIE &die) override; - std::vector - GetDIEForDeclContext(lldb_private::CompilerDeclContext decl_context) override; + void EnsureAllDIEsInDeclContextHaveBeenParsed( + lldb_private::CompilerDeclContext decl_context) override; lldb_private::CompilerDeclContext GetDeclContextForUIDFromDWARF(const DWARFDIE &die) override; 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 @@ -2183,15 +2183,16 @@ return false; } -std::vector DWARFASTParserClang::GetDIEForDeclContext( +void DWARFASTParserClang::EnsureAllDIEsInDeclContextHaveBeenParsed( lldb_private::CompilerDeclContext decl_context) { - std::vector result; 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++) - result.push_back(it->second); - return result; + 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.GetFirstChild(); decl; + decl = decl.GetSibling()) + GetClangDeclForDIE(decl); } CompilerDecl DWARFASTParserClang::GetDeclForUIDFromDWARF(const DWARFDIE &die) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1204,16 +1204,9 @@ void SymbolFileDWARF::ParseDeclsForContext(CompilerDeclContext decl_ctx) { auto *type_system = decl_ctx.GetTypeSystem(); - if (!type_system) - return; - DWARFASTParser *ast_parser = type_system->GetDWARFParser(); - std::vector decl_ctx_die_list = - ast_parser->GetDIEForDeclContext(decl_ctx); - - for (DWARFDIE decl_ctx_die : decl_ctx_die_list) - for (DWARFDIE decl = decl_ctx_die.GetFirstChild(); decl; - decl = decl.GetSibling()) - ast_parser->GetDeclForUIDFromDWARF(decl); + if (type_system != nullptr) + type_system->GetDWARFParser()->EnsureAllDIEsInDeclContextHaveBeenParsed( + decl_ctx); } user_id_t SymbolFileDWARF::GetUID(DIERef ref) { 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 @@ -24,24 +24,28 @@ // If your implementation needs to dereference the dummy pointers we are // defining here, causing this test to fail, feel free to delete it. -TEST(DWARFASTParserClangTests, - TestGetDIEForDeclContextReturnsOnlyMatchingEntries) { - ClangASTContext ast_ctx; - DWARFASTParserClangStub ast_parser(ast_ctx); - - DWARFUnit *unit = nullptr; - DWARFDIE die1(unit, (DWARFDebugInfoEntry *)1LL); - DWARFDIE die2(unit, (DWARFDebugInfoEntry *)2LL); - DWARFDIE die3(unit, (DWARFDebugInfoEntry *)3LL); - DWARFDIE die4(unit, (DWARFDebugInfoEntry *)4LL); - ast_parser.LinkDeclContextToDIE((clang::DeclContext *)1LL, die1); - ast_parser.LinkDeclContextToDIE((clang::DeclContext *)2LL, die2); - ast_parser.LinkDeclContextToDIE((clang::DeclContext *)2LL, die3); - ast_parser.LinkDeclContextToDIE((clang::DeclContext *)3LL, die4); - - auto die_list = ast_parser.GetDIEForDeclContext( - CompilerDeclContext(nullptr, (clang::DeclContext *)2LL)); - ASSERT_EQ(2u, die_list.size()); - ASSERT_EQ(die2, die_list[0]); - ASSERT_EQ(die3, die_list[1]); -} +// TEST(DWARFASTParserClangTests, +// TestForEachDIEInDeclContextReturnsOnlyMatchingEntries) { +// ClangASTContext ast_ctx; +// DWARFASTParserClangStub ast_parser(ast_ctx); + +// DWARFUnit *unit = nullptr; +// DWARFDIE die1(unit, (DWARFDebugInfoEntry *)1LL); +// DWARFDIE die2(unit, (DWARFDebugInfoEntry *)2LL); +// DWARFDIE die3(unit, (DWARFDebugInfoEntry *)3LL); +// DWARFDIE die4(unit, (DWARFDebugInfoEntry *)4LL); +// ast_parser.LinkDeclContextToDIE((clang::DeclContext *)1LL, die1); +// ast_parser.LinkDeclContextToDIE((clang::DeclContext *)2LL, die2); +// ast_parser.LinkDeclContextToDIE((clang::DeclContext *)2LL, die3); +// ast_parser.LinkDeclContextToDIE((clang::DeclContext *)3LL, die4); + +// std::vector die_list; +// ast_parser.ForEachDIEInDeclContext( +// CompilerDeclContext(nullptr, (clang::DeclContext *)2LL), +// [&die_list](DWARFDIE die) { die_list.push_back(die); }); + +// ASSERT_EQ(2u, die_list.size()); +// ASSERT_NE(die_list.end(), std::find(die_list.begin(), die_list.end(), +// die2)); ASSERT_NE(die_list.end(), std::find(die_list.begin(), +// die_list.end(), die3)); +// }