From 4b5bc38802dcc7d2c6d7f5af1eca1755bd0fd9cb Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Mon, 23 Dec 2019 16:31:36 +0100 Subject: [PATCH] [lldb/DWARF] Move location list sections into DWARFContext These are the last sections not managed by the DWARFContext object. I also introduce separate SectionType enums for dwo section variants, as this is necessary for proper handling of single-file split dwarf. --- lldb/include/lldb/lldb-enumerations.h | 2 ++ lldb/source/Core/Section.cpp | 4 +++ .../Plugins/ObjectFile/ELF/ObjectFileELF.cpp | 6 ++-- .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 2 ++ .../Plugins/SymbolFile/DWARF/DWARFContext.cpp | 11 ++++++++ .../Plugins/SymbolFile/DWARF/DWARFContext.h | 4 +++ .../Plugins/SymbolFile/DWARF/DWARFUnit.cpp | 13 +++++---- .../SymbolFile/DWARF/SymbolFileDWARF.cpp | 9 ------ .../SymbolFile/DWARF/SymbolFileDWARF.h | 3 -- lldb/source/Symbol/ObjectFile.cpp | 2 ++ .../Shell/ObjectFile/ELF/section-types.yaml | 28 +++++++++++++++++++ .../SymbolFile/DWARF/debug_loclists-dwo.s | 5 ++++ 12 files changed, 70 insertions(+), 19 deletions(-) diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h index dd3d9cc7da50..8cbb459ee1ea 100644 --- a/lldb/include/lldb/lldb-enumerations.h +++ b/lldb/include/lldb/lldb-enumerations.h @@ -692,6 +692,8 @@ enum SectionType { eSectionTypeDWARFDebugStrOffsetsDwo, eSectionTypeDWARFDebugTypesDwo, eSectionTypeDWARFDebugRngListsDwo, + eSectionTypeDWARFDebugLocDwo, + eSectionTypeDWARFDebugLocListsDwo, }; FLAGS_ENUM(EmulateInstructionOptions){ diff --git a/lldb/source/Core/Section.cpp b/lldb/source/Core/Section.cpp index b1d7eee108b7..1697f1f7a5d4 100644 --- a/lldb/source/Core/Section.cpp +++ b/lldb/source/Core/Section.cpp @@ -80,8 +80,12 @@ const char *Section::GetTypeAsCString() const { return "dwarf-line-str"; case eSectionTypeDWARFDebugLoc: return "dwarf-loc"; + case eSectionTypeDWARFDebugLocDwo: + return "dwarf-loc-dwo"; case eSectionTypeDWARFDebugLocLists: return "dwarf-loclists"; + case eSectionTypeDWARFDebugLocListsDwo: + return "dwarf-loclists-dwo"; case eSectionTypeDWARFDebugMacInfo: return "dwarf-macinfo"; case eSectionTypeDWARFDebugMacro: diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index 893d294c0fae..8b62afa18cd6 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -1572,8 +1572,10 @@ static SectionType GetSectionTypeFromName(llvm::StringRef Name) { .Case("info.dwo", eSectionTypeDWARFDebugInfoDwo) .Cases("line", "line.dwo", eSectionTypeDWARFDebugLine) .Cases("line_str", "line_str.dwo", eSectionTypeDWARFDebugLineStr) - .Cases("loc", "loc.dwo", eSectionTypeDWARFDebugLoc) - .Cases("loclists", "loclists.dwo", eSectionTypeDWARFDebugLocLists) + .Case("loc", eSectionTypeDWARFDebugLoc) + .Case("loc.dwo", eSectionTypeDWARFDebugLocDwo) + .Case("loclists", eSectionTypeDWARFDebugLocLists) + .Case("loclists.dwo", eSectionTypeDWARFDebugLocListsDwo) .Case("macinfo", eSectionTypeDWARFDebugMacInfo) .Cases("macro", "macro.dwo", eSectionTypeDWARFDebugMacro) .Case("names", eSectionTypeDWARFDebugNames) diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index e730aafbd3e2..3f9b68aad89f 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -1133,7 +1133,9 @@ AddressClass ObjectFileMachO::GetAddressClass(lldb::addr_t file_addr) { case eSectionTypeDWARFDebugLine: case eSectionTypeDWARFDebugLineStr: case eSectionTypeDWARFDebugLoc: + case eSectionTypeDWARFDebugLocDwo: case eSectionTypeDWARFDebugLocLists: + case eSectionTypeDWARFDebugLocListsDwo: case eSectionTypeDWARFDebugMacInfo: case eSectionTypeDWARFDebugMacro: case eSectionTypeDWARFDebugNames: diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp index db8d7b3747ec..5052b825fea6 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp @@ -70,6 +70,17 @@ const DWARFDataExtractor &DWARFContext::getOrLoadLineStrData() { m_data_debug_line_str); } +const DWARFDataExtractor &DWARFContext::getOrLoadLocData() { + return LoadOrGetSection(eSectionTypeDWARFDebugLoc, + eSectionTypeDWARFDebugLocDwo, m_data_debug_loc); +} + +const DWARFDataExtractor &DWARFContext::getOrLoadLocListsData() { + return LoadOrGetSection(eSectionTypeDWARFDebugLocLists, + eSectionTypeDWARFDebugLocListsDwo, + m_data_debug_loclists); +} + const DWARFDataExtractor &DWARFContext::getOrLoadMacroData() { return LoadOrGetSection(eSectionTypeDWARFDebugMacro, llvm::None, m_data_debug_macro); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h index 24baac90aa44..8691001b1b76 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.h @@ -34,6 +34,8 @@ private: SectionData m_data_debug_info; SectionData m_data_debug_line; SectionData m_data_debug_line_str; + SectionData m_data_debug_loc; + SectionData m_data_debug_loclists; SectionData m_data_debug_macro; SectionData m_data_debug_ranges; SectionData m_data_debug_rnglists; @@ -58,6 +60,8 @@ public: const DWARFDataExtractor &getOrLoadDebugInfoData(); const DWARFDataExtractor &getOrLoadLineData(); const DWARFDataExtractor &getOrLoadLineStrData(); + const DWARFDataExtractor &getOrLoadLocData(); + const DWARFDataExtractor &getOrLoadLocListsData(); const DWARFDataExtractor &getOrLoadMacroData(); const DWARFDataExtractor &getOrLoadRangesData(); const DWARFDataExtractor &getOrLoadRngListsData(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp index 142de7fb0ebe..22e3e40dac93 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -380,8 +380,9 @@ void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) { .GetByteSize() > 0) dwo_cu->SetRangesBase(llvm::DWARFListTableHeader::getHeaderSize(DWARF32)); - if (GetVersion() >= 5 && - m_dwo_symbol_file->get_debug_loclists_data().GetByteSize() > 0) + if (GetVersion() >= 5 && m_dwo_symbol_file->GetDWARFContext() + .getOrLoadLocListsData() + .GetByteSize() > 0) dwo_cu->SetLoclistsBase(llvm::DWARFListTableHeader::getHeaderSize(DWARF32)); dwo_cu->SetBaseAddress(GetBaseAddress()); @@ -455,7 +456,8 @@ void DWARFUnit::SetLoclistsBase(dw_addr_t loclists_base) { m_loclist_table_header.emplace(".debug_loclists", "locations"); uint64_t offset = loclists_base - header_size; if (llvm::Error E = m_loclist_table_header->extract( - m_dwarf.get_debug_loclists_data().GetAsLLVM(), &offset)) { + m_dwarf.GetDWARFContext().getOrLoadLocListsData().GetAsLLVM(), + &offset)) { GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError( "Failed to extract location list table at offset 0x%" PRIx64 ": %s", loclists_base, toString(std::move(E)).c_str()); @@ -474,8 +476,9 @@ DWARFUnit::GetLocationTable(const DataExtractor &data) const { } const DWARFDataExtractor &DWARFUnit::GetLocationData() const { - return GetVersion() >= 5 ? GetSymbolFileDWARF().get_debug_loclists_data() - : GetSymbolFileDWARF().get_debug_loc_data(); + DWARFContext &Ctx = GetSymbolFileDWARF().GetDWARFContext(); + return GetVersion() >= 5 ? Ctx.getOrLoadLocListsData() + : Ctx.getOrLoadLocData(); } void DWARFUnit::SetRangesBase(dw_addr_t ranges_base) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 533af5f4e834..d45a8b56efe4 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -597,15 +597,6 @@ void SymbolFileDWARF::LoadSectionData(lldb::SectionType sect_type, m_objfile_sp->ReadSectionData(section_sp.get(), data); } -const DWARFDataExtractor &SymbolFileDWARF::get_debug_loc_data() { - return GetCachedSectionData(eSectionTypeDWARFDebugLoc, m_data_debug_loc); -} - -const DWARFDataExtractor &SymbolFileDWARF::get_debug_loclists_data() { - return GetCachedSectionData(eSectionTypeDWARFDebugLocLists, - m_data_debug_loclists); -} - DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() { if (m_abbr) return m_abbr.get(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index f816dd77800e..23e26732453f 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -222,9 +222,6 @@ public: uint32_t GetPluginVersion() override; - const lldb_private::DWARFDataExtractor &get_debug_loc_data(); - const lldb_private::DWARFDataExtractor &get_debug_loclists_data(); - DWARFDebugAbbrev *DebugAbbrev(); const DWARFDebugAbbrev *DebugAbbrev() const; diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp index 4f6d74bbc757..8a72b5fe6f67 100644 --- a/lldb/source/Symbol/ObjectFile.cpp +++ b/lldb/source/Symbol/ObjectFile.cpp @@ -352,7 +352,9 @@ AddressClass ObjectFile::GetAddressClass(addr_t file_addr) { case eSectionTypeDWARFDebugLine: case eSectionTypeDWARFDebugLineStr: case eSectionTypeDWARFDebugLoc: + case eSectionTypeDWARFDebugLocDwo: case eSectionTypeDWARFDebugLocLists: + case eSectionTypeDWARFDebugLocListsDwo: case eSectionTypeDWARFDebugMacInfo: case eSectionTypeDWARFDebugMacro: case eSectionTypeDWARFDebugNames: diff --git a/lldb/test/Shell/ObjectFile/ELF/section-types.yaml b/lldb/test/Shell/ObjectFile/ELF/section-types.yaml index caac76a789ce..7d59b3b4870d 100644 --- a/lldb/test/Shell/ObjectFile/ELF/section-types.yaml +++ b/lldb/test/Shell/ObjectFile/ELF/section-types.yaml @@ -13,6 +13,18 @@ # CHECK-LABEL: Name: .debug_types.dwo # CHECK-NEXT: Type: dwarf-types-dwo +# CHECK-LABEL: Name: .debug_loc +# CHECK-NEXT: Type: dwarf-loc + +# CHECK-LABEL: Name: .debug_loc.dwo +# CHECK-NEXT: Type: dwarf-loc-dwo + +# CHECK-LABEL: Name: .debug_loclists +# CHECK-NEXT: Type: dwarf-loclists + +# CHECK-LABEL: Name: .debug_loclists.dwo +# CHECK-NEXT: Type: dwarf-loclists-dwo + # CHECK-LABEL: Name: .debug_rnglists # CHECK-NEXT: Type: dwarf-rnglists @@ -64,6 +76,22 @@ Sections: Type: SHT_PROGBITS AddressAlign: 0x0000000000000001 Content: DEADBEEFBAADF00D + - Name: .debug_loc + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: DEADBEEFBAADF00D + - Name: .debug_loc.dwo + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: DEADBEEFBAADF00D + - Name: .debug_loclists + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: DEADBEEFBAADF00D + - Name: .debug_loclists.dwo + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: DEADBEEFBAADF00D - Name: .debug_rnglists Type: SHT_PROGBITS AddressAlign: 0x0000000000000001 diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug_loclists-dwo.s b/lldb/test/Shell/SymbolFile/DWARF/debug_loclists-dwo.s index 9ecb0b27f735..b045d7de9abb 100644 --- a/lldb/test/Shell/SymbolFile/DWARF/debug_loclists-dwo.s +++ b/lldb/test/Shell/SymbolFile/DWARF/debug_loclists-dwo.s @@ -82,6 +82,11 @@ lookup_loclists: .quad .Ltmp1 .Ldebug_addr_end0: +# The presence of an extra non-dwo loclists section should not confuse us. +# .debug_info.dwo always refers to .debug_loclists.dwo + .section .debug_loclists,"",@progbits + .quad 0xdeadbeefbaadf00d + .section .debug_loclists.dwo,"e",@progbits .long .Ldebug_loclist_table_end0-.Ldebug_loclist_table_start0 # Length .Ldebug_loclist_table_start0: -- 2.34.1