Index: include/lldb/Symbol/SymbolVendor.h =================================================================== --- include/lldb/Symbol/SymbolVendor.h +++ include/lldb/Symbol/SymbolVendor.h @@ -130,6 +130,10 @@ FileSpec GetMainFileSpec() const; + /// Populate the unified section list of a module with sections the vendor's + /// sections. + virtual void CreateSections(SectionList &UnifiedList) {} + // Get module unified section list symbol table. virtual Symtab *GetSymtab(); Index: lit/Modules/Inputs/stripped.yaml =================================================================== --- /dev/null +++ lit/Modules/Inputs/stripped.yaml @@ -0,0 +1,25 @@ +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 + Entry: 0x00000000004003D0 +Sections: + - Name: .note.gnu.build-id + Type: SHT_NOTE + Flags: [ SHF_ALLOC ] + Address: 0x0000000000400274 + AddressAlign: 0x0000000000000004 + Content: 040000001400000003000000474E55001B8A73AC238390E32A7FF4AC8EBE4D6A41ECF5C9 + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x00000000004003D0 + AddressAlign: 0x0000000000000010 + Content: DEADBEEFBAADF00D + - Name: .gnu_debuglink + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000004 + Content: 38613733616332333833393065333261376666346163386562653464366134316563663563392E646562756700000000ADEE50C1 +... Index: lit/Modules/Inputs/unstripped.yaml =================================================================== --- /dev/null +++ lit/Modules/Inputs/unstripped.yaml @@ -0,0 +1,32 @@ +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 + Entry: 0x00000000004003D0 +Sections: + - Name: .debug_frame + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000008 + Content: DEADBEEFBAADF00D + - Name: .note.gnu.build-id + Type: SHT_NOTE + Flags: [ SHF_ALLOC ] + Address: 0x0000000000400274 + AddressAlign: 0x0000000000000004 + Content: 040000001400000003000000474E55001B8A73AC238390E32A7FF4AC8EBE4D6A41ECF5C9 + - Name: .text + Type: SHT_NOBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x00000000004003D0 + AddressAlign: 0x0000000000000010 + Size: 0x0000000000000008 +Symbols: + Local: + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x00000000004003D0 + Size: 0x0000000000000008 +... Index: lit/Modules/lit.local.cfg =================================================================== --- lit/Modules/lit.local.cfg +++ lit/Modules/lit.local.cfg @@ -1 +1 @@ -config.suffixes = ['.yaml'] +config.suffixes = ['.yaml', '.test'] Index: lit/Modules/unified-section-list.test =================================================================== --- /dev/null +++ lit/Modules/unified-section-list.test @@ -0,0 +1,8 @@ +RUN: mkdir -p %t/.build-id/1b +RUN: yaml2obj %S/Inputs/stripped.yaml > %t/stripped.out +RUN: yaml2obj %S/Inputs/unstripped.yaml > %t/.build-id/1b/8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9.debug +RUN: lldb-test module-sections %t/stripped.out | FileCheck %s + +CHECK: Name: .debug_frame +CHECK-NEXT: VM size: 0 +CHECK-NEXT: File size: 8 Index: lit/lit.cfg =================================================================== --- lit/lit.cfg +++ lit/lit.cfg @@ -28,6 +28,8 @@ # suffixes: We only support unit tests config.suffixes = [] +config.excludes = ['Inputs'] + # test_source_root: The root path where tests are located. config.test_source_root = os.path.dirname(__file__) Index: source/Core/Module.cpp =================================================================== --- source/Core/Module.cpp +++ source/Core/Module.cpp @@ -1280,9 +1280,10 @@ SectionList *Module::GetSectionList() { // Populate m_unified_sections_ap with sections from objfile. if (!m_sections_ap) { - ObjectFile *obj_file = GetObjectFile(); - if (obj_file != nullptr) + if (ObjectFile *obj_file = GetObjectFile()) obj_file->CreateSections(*GetUnifiedSectionList()); + if (SymbolVendor *vendor = GetSymbolVendor()) + vendor->CreateSections(*GetUnifiedSectionList()); } return m_sections_ap.get(); } Index: source/Plugins/SymbolVendor/ELF/SymbolVendorELF.h =================================================================== --- source/Plugins/SymbolVendor/ELF/SymbolVendorELF.h +++ source/Plugins/SymbolVendor/ELF/SymbolVendorELF.h @@ -26,6 +26,8 @@ ~SymbolVendorELF() override; + void CreateSections(lldb_private::SectionList &UnifiedList) override; + //------------------------------------------------------------------ // Static Functions //------------------------------------------------------------------ Index: source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp =================================================================== --- source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp +++ source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp @@ -120,47 +120,40 @@ dsym_objfile_sp->SetType(ObjectFile::eTypeDebugInfo); SymbolVendorELF *symbol_vendor = new SymbolVendorELF(module_sp); - if (symbol_vendor) { - // Get the module unified section list and add our debug sections to - // that. - SectionList *module_section_list = module_sp->GetSectionList(); - SectionList *objfile_section_list = dsym_objfile_sp->GetSectionList(); - - static const SectionType g_sections[] = { - eSectionTypeDWARFDebugAbbrev, eSectionTypeDWARFDebugAddr, - eSectionTypeDWARFDebugAranges, eSectionTypeDWARFDebugCuIndex, - eSectionTypeDWARFDebugFrame, eSectionTypeDWARFDebugInfo, - eSectionTypeDWARFDebugLine, eSectionTypeDWARFDebugLoc, - eSectionTypeDWARFDebugMacInfo, eSectionTypeDWARFDebugPubNames, - eSectionTypeDWARFDebugPubTypes, eSectionTypeDWARFDebugRanges, - eSectionTypeDWARFDebugStr, eSectionTypeDWARFDebugStrOffsets, - eSectionTypeELFSymbolTable, - }; - for (size_t idx = 0; idx < sizeof(g_sections) / sizeof(g_sections[0]); - ++idx) { - SectionType section_type = g_sections[idx]; - SectionSP section_sp( - objfile_section_list->FindSectionByType(section_type, true)); - if (section_sp) { - SectionSP module_section_sp( - module_section_list->FindSectionByType(section_type, true)); - if (module_section_sp) - module_section_list->ReplaceSection(module_section_sp->GetID(), - section_sp); - else - module_section_list->AddSection(section_sp); - } - } - - symbol_vendor->AddSymbolFileRepresentation(dsym_objfile_sp); - return symbol_vendor; - } + symbol_vendor->AddSymbolFileRepresentation(dsym_objfile_sp); + return symbol_vendor; } } } return NULL; } +void SymbolVendorELF::CreateSections(SectionList &UnifiedList) { + SectionList *ObjfileList = m_objfile_sp->GetSectionList(); + + static constexpr SectionType g_sections[] = { + eSectionTypeDWARFDebugAbbrev, eSectionTypeDWARFDebugAddr, + eSectionTypeDWARFDebugAranges, eSectionTypeDWARFDebugCuIndex, + eSectionTypeDWARFDebugFrame, eSectionTypeDWARFDebugInfo, + eSectionTypeDWARFDebugLine, eSectionTypeDWARFDebugLoc, + eSectionTypeDWARFDebugMacInfo, eSectionTypeDWARFDebugPubNames, + eSectionTypeDWARFDebugPubTypes, eSectionTypeDWARFDebugRanges, + eSectionTypeDWARFDebugStr, eSectionTypeDWARFDebugStrOffsets, + eSectionTypeELFSymbolTable, + }; + for (SectionType ST: g_sections) { + SectionSP section_sp = ObjfileList->FindSectionByType(ST, true); + if (!section_sp) + continue; + + SectionSP module_section_sp = UnifiedList.FindSectionByType(ST, true); + if (module_section_sp) + UnifiedList.ReplaceSection(module_section_sp->GetID(), section_sp); + else + UnifiedList.AddSection(section_sp); + } +} + //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ Index: tools/lldb-test/lldb-test.cpp =================================================================== --- tools/lldb-test/lldb-test.cpp +++ tools/lldb-test/lldb-test.cpp @@ -72,7 +72,6 @@ for (const auto &File : opts::module::InputFilenames) { ModuleSpec Spec{FileSpec(File, false)}; - Spec.GetSymbolFileSpec().SetFile(File, false); auto ModulePtr = std::make_shared(Spec); SectionList *Sections = ModulePtr->GetSectionList();