diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -111,6 +111,10 @@ MacroDwoSection }; + // When set parses debug_info.dwo/debug_abbrev.dwo manually and populates CU + // Index, and TU Index for DWARF5. + bool ParseCUTUIndexManually; + public: DWARFContext(std::unique_ptr DObj, std::string DWPName = "", @@ -454,6 +458,14 @@ /// into "SectionedAddress Address" DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address); + /// Returns whether CU/TU should be populated manually. TU Index populated + /// manually only for DWARF5. + bool getParseCUTUIndexManually() const { return ParseCUTUIndexManually; } + + /// Sets whether CU/TU should be populated manually. TU Index populated + /// manually only for DWARF5. + void setParseCUTUIndexManually(bool PCUTU) { ParseCUTUIndexManually = PCUTU; } + private: /// Parse a macro[.dwo] or macinfo[.dwo] section. std::unique_ptr diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -93,6 +93,7 @@ } uint64_t getLength() const { return Length; } uint64_t getAbbrOffset() const { return AbbrOffset; } + void setAbbrOffset(uint64_t Offset) { AbbrOffset = Offset; } Optional getDWOId() const { return DWOId; } void setDWOId(uint64_t Id) { assert((!DWOId || *DWOId == Id) && "setting DWOId to a different value"); diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h @@ -13,6 +13,7 @@ #include "llvm/ADT/StringRef.h" #include #include +#include namespace llvm { @@ -131,6 +132,8 @@ uint64_t getSignature() const { return Signature; } }; + using EntryType = DWARFUnitIndex::Entry::SectionContribution; + using EntryMap = std::unordered_map; private: struct Header Header; @@ -147,7 +150,7 @@ static StringRef getColumnHeader(DWARFSectionKind DS); - bool parseImpl(DataExtractor IndexData); + bool parseImpl(DataExtractor IndexData, EntryMap &SignatureMap); public: DWARFUnitIndex(DWARFSectionKind InfoColumnKind) @@ -155,6 +158,7 @@ explicit operator bool() const { return Header.NumBuckets; } + bool parse(DataExtractor IndexData, EntryMap &SignatureMap); bool parse(DataExtractor IndexData); void dump(raw_ostream &OS) const; diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -781,14 +781,92 @@ return Success; } +enum class IndexType { CUIndex, TUIndex }; +static DWARFUnitIndex::EntryMap +parseDebugInfo(const DWARFObject &DObj, DWARFContext &C, IndexType type) { + DWARFUnitIndex::EntryMap SignatureMap; + if (DObj.getCUIndexSection().empty()) + return SignatureMap; + + DWARFUnitVector UnitVector; + uint64_t Offset = 0; + DObj.forEachInfoDWOSections([&](const DWARFSection &S) { + if (!(C.getParseCUTUIndexManually() || + S.Data.size() >= std::numeric_limits::max())) + return; + DWARFDebugAbbrev AbbrevDWO; + DataExtractor abbrData(DObj.getAbbrevDWOSection(), C.isLittleEndian(), 0); + AbbrevDWO.extract(abbrData); + SmallVector AbbrOffsets; + for (auto &I : AbbrevDWO) + AbbrOffsets.push_back(I.second.getOffset()); + + DWARFDataExtractor Data(DObj, S, C.isLittleEndian(), 0); + int I = 0; + while (Data.isValidOffset(Offset)) { + DWARFUnitHeader Header; + if (!Header.extract(C, Data, &Offset, DWARFSectionKind::DW_SECT_INFO)) { + llvm::errs() << "Failed to parse CU header in DWP file\n"; + SignatureMap.clear(); + break; + } + + Offset = + Header.getOffset() + Header.getLength() + /* Size of legth field */ 4; + + // If we are parsing TU-index and for .debug_types section we don't need + // to do anything. + if (Header.getVersion() == 4 && type == IndexType::TUIndex) + break; + + // Parsing CU Index, can skip all the TUs + if (Header.isTypeUnit() && type == IndexType::CUIndex) + continue; + + Header.setAbbrOffset(AbbrOffsets[I]); + std::unique_ptr U; + + if (Header.isTypeUnit()) { + // If we are hitting type unit, we are parsing TU Index. + U = std::make_unique( + C, S, Header, C.getDebugAbbrevDWO(), &DObj.getRangesDWOSection(), + &DObj.getLocDWOSection(), DObj.getStrDWOSection(), + DObj.getStrOffsetsDWOSection(), &DObj.getAddrSection(), + DObj.getLineDWOSection(), C.isLittleEndian(), true, UnitVector); + } else { + // TUs share same abbrev as CU. So we move to next abbrev when we + // encounter a CU. + ++I; + if (type == IndexType::TUIndex) + continue; + U = std::make_unique( + C, S, Header, C.getDebugAbbrevDWO(), &DObj.getRangesDWOSection(), + &DObj.getLocDWOSection(), DObj.getStrDWOSection(), + DObj.getStrOffsetsDWOSection(), &DObj.getAddrSection(), + DObj.getLineDWOSection(), C.isLittleEndian(), true, UnitVector); + } + + uint64_t ID = Header.isTypeUnit() ? Header.getTypeHash() : *U->getDWOId(); + SignatureMap.insert( + {ID, + {(uint32_t)U->getOffset(), + (uint32_t)(U->getNextUnitOffset() - U->getOffset())}}); + } + }); + + return SignatureMap; +} + const DWARFUnitIndex &DWARFContext::getCUIndex() { if (CUIndex) return *CUIndex; + DWARFUnitIndex::EntryMap SignatureMap = + parseDebugInfo(*DObj, *this, IndexType::CUIndex); DataExtractor CUIndexData(DObj->getCUIndexSection(), isLittleEndian(), 0); CUIndex = std::make_unique(DW_SECT_INFO); - CUIndex->parse(CUIndexData); + CUIndex->parse(CUIndexData, SignatureMap); return *CUIndex; } @@ -796,10 +874,12 @@ if (TUIndex) return *TUIndex; + DWARFUnitIndex::EntryMap SignatureMap = + parseDebugInfo(*DObj, *this, IndexType::TUIndex); DataExtractor TUIndexData(DObj->getTUIndexSection(), isLittleEndian(), 0); TUIndex = std::make_unique(DW_SECT_EXT_TYPES); - TUIndex->parse(TUIndexData); + TUIndex->parse(TUIndexData, SignatureMap); return *TUIndex; } diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp @@ -116,8 +116,8 @@ OS << format("version = %u, units = %u, slots = %u\n\n", Version, NumUnits, NumBuckets); } -bool DWARFUnitIndex::parse(DataExtractor IndexData) { - bool b = parseImpl(IndexData); +bool DWARFUnitIndex::parse(DataExtractor IndexData, EntryMap &SignatureMap) { + bool b = parseImpl(IndexData, SignatureMap); if (!b) { // Make sure we don't try to dump anything Header.NumBuckets = 0; @@ -128,7 +128,13 @@ return b; } -bool DWARFUnitIndex::parseImpl(DataExtractor IndexData) { +bool DWARFUnitIndex::parse(DataExtractor IndexData) { + EntryMap SignatureMap; + return parse(IndexData, SignatureMap); +} + +bool DWARFUnitIndex::parseImpl(DataExtractor IndexData, + EntryMap &SignatureMap) { uint64_t Offset = 0; if (!Header.parse(IndexData, &Offset)) return false; @@ -152,6 +158,7 @@ for (unsigned i = 0; i != Header.NumBuckets; ++i) Rows[i].Signature = IndexData.getU64(&Offset); + auto Signatures = std::make_unique(Header.NumUnits); // Read Parallel Table of Indexes for (unsigned i = 0; i != Header.NumBuckets; ++i) { auto Index = IndexData.getU32(&Offset); @@ -161,6 +168,7 @@ Rows[i].Contributions = std::make_unique(Header.NumColumns); Contribs[Index - 1] = Rows[i].Contributions.get(); + Signatures[Index - 1] = Rows[i].Signature; } // Read the Column Headers @@ -177,19 +185,37 @@ if (InfoColumn == -1) return false; - // Read Table of Section Offsets - for (unsigned i = 0; i != Header.NumUnits; ++i) { + // Populating offsets and length for .debug-info.dwo section if we parsed it + // manually. + for (unsigned i = 0; !SignatureMap.empty() && i != Header.NumUnits; ++i) { auto *Contrib = Contribs[i]; - for (unsigned i = 0; i != Header.NumColumns; ++i) - Contrib[i].Offset = IndexData.getU32(&Offset); + auto Iter = SignatureMap.find(Signatures[i]); + if (Iter == SignatureMap.end()) { + llvm::errs() << "Signature not found\n"; + continue; + } + Contrib[InfoColumn].Offset = Iter->second.Offset; + Contrib[InfoColumn].Length = Iter->second.Length; } + auto PopulateField = + [&](uint32_t DWARFUnitIndex::Entry::SectionContribution::*Field) -> void { + for (unsigned i = 0; i != Header.NumUnits; ++i) { + auto *Contrib = Contribs[i]; + for (unsigned i = 0; i != Header.NumColumns; ++i) { + if (i == (unsigned)InfoColumn && !SignatureMap.empty()) { + Offset += 4; + continue; + } + Contrib[i].*Field = IndexData.getU32(&Offset); + } + } + }; + // Read Table of Section Offsets + PopulateField(&DWARFUnitIndex::Entry::SectionContribution::Offset); + // Read Table of Section Sizes - for (unsigned i = 0; i != Header.NumUnits; ++i) { - auto *Contrib = Contribs[i]; - for (unsigned i = 0; i != Header.NumColumns; ++i) - Contrib[i].Length = IndexData.getU32(&Offset); - } + PopulateField(&DWARFUnitIndex::Entry::SectionContribution::Length); return true; } diff --git a/llvm/test/tools/llvm-dwp/X86/debug_macro_v5.s b/llvm/test/tools/llvm-dwp/X86/debug_macro_v5.s --- a/llvm/test/tools/llvm-dwp/X86/debug_macro_v5.s +++ b/llvm/test/tools/llvm-dwp/X86/debug_macro_v5.s @@ -2,7 +2,8 @@ # RUN: llvm-mc -triple x86_64-unknown-linux --filetype=obj --split-dwarf-file=%t.dwo -dwarf-version=5 %s -o %t.o # RUN: llvm-dwp %t.dwo -o %t.dwp 2>&1 -# RUN: llvm-dwarfdump -debug-macro -debug-cu-index %t.dwp | FileCheck %s +# RUN: llvm-dwarfdump -debug-macro -debug-cu-index %t.dwp | FileCheck -check-prefix=CHECK %s +# RUN: llvm-dwarfdump -debug-macro -debug-cu-index -manaully-generate-cu-tu-index %t.dwp | FileCheck -check-prefix=CHECK2 %s # CHECK-DAG: .debug_macro.dwo contents: # CHECK: macro header: version = 0x0005, flags = 0x00, format = DWARF32 @@ -15,6 +16,9 @@ # CHECK: Index Signature INFO ABBREV STR_OFFSETS MACRO # CHECK: 1 0x0000000000000000 [0x00000000, 0x00000019) [0x00000000, 0x00000008) [0x00000000, 0x0000000c) [0x00000000, 0x0000000b) +# CHECK2: Index Signature INFO ABBREV STR_OFFSETS MACRO +# CHECK2: 1 0x0000000000000000 [0x00000000, 0x00000019) [0x00000000, 0x00000008) [0x00000000, 0x0000000c) [0x00000000, 0x0000000b) + .section .debug_info.dwo,"e",@progbits .long .Ldebug_info_dwo_end0-.Ldebug_info_dwo_start0 # Length of Unit .Ldebug_info_dwo_start0: diff --git a/llvm/test/tools/llvm-dwp/X86/info-v5.s b/llvm/test/tools/llvm-dwp/X86/info-v5.s --- a/llvm/test/tools/llvm-dwp/X86/info-v5.s +++ b/llvm/test/tools/llvm-dwp/X86/info-v5.s @@ -3,7 +3,8 @@ # RUN: llvm-mc --triple=x86_64-unknown-linux --filetype=obj --split-dwarf-file=%t.dwo -dwarf-version=5 %s -o %t.o # RUN: llvm-dwp %t.dwo -o %t.dwp -# RUN: llvm-dwarfdump -v %t.dwp | FileCheck %s +# RUN: llvm-dwarfdump -v %t.dwp | FileCheck -check-prefix=CHECK %s +# RUN: llvm-dwarfdump -manaully-generate-cu-tu-index -v %t.dwp | FileCheck -check-prefix=CHECK2 %s #CHECK-DAG: .debug_info.dwo contents: #CHECK: 0x00000000: Compile Unit: length = 0x00000050, format = DWARF32, version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset = 0x0000, addr_size = 0x08, DWO_id = [[DWOID:.*]] (next unit at 0x00000054) @@ -13,6 +14,14 @@ # CHECK: Index Signature INFO ABBREV # CHECK: 1 [[DWOID]] [0x00000000, 0x00000054) [0x00000000, 0x0000002a) +#CHECK2-DAG: .debug_info.dwo contents: +#CHECK2: 0x00000000: Compile Unit: length = 0x00000050, format = DWARF32, version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset = 0x0000, addr_size = 0x08, DWO_id = [[DWOID2:.*]] (next unit at 0x00000054) + +# CHECK2-DAG: .debug_cu_index contents: +# CHECK2: version = 5, units = 1, slots = 2 +# CHECK2: Index Signature INFO +# CHECK21: 1 [[DWOID2]] [0x00000000, 0x00000054) [0x00000000, 0x0000002a) + .section .debug_info.dwo,"e",@progbits .long .Ldebug_info_dwo_end0-.Ldebug_info_dwo_start0 # Length of Unit .Ldebug_info_dwo_start0: diff --git a/llvm/test/tools/llvm-dwp/X86/loclists.s b/llvm/test/tools/llvm-dwp/X86/loclists.s --- a/llvm/test/tools/llvm-dwp/X86/loclists.s +++ b/llvm/test/tools/llvm-dwp/X86/loclists.s @@ -3,7 +3,8 @@ # RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o %t.o \ # RUN: -split-dwarf-file=%t.dwo -dwarf-version=5 # RUN: llvm-dwp %t.dwo -o %t.dwp -# RUN: llvm-dwarfdump -debug-loclists -debug-cu-index -debug-tu-index %t.dwp | FileCheck %s +# RUN: llvm-dwarfdump -debug-loclists -debug-cu-index -debug-tu-index %t.dwp | FileCheck -check-prefix=CHECK %s +# RUN: llvm-dwarfdump -debug-cu-index -debug-tu-index -manaully-generate-cu-tu-index %t.dwp | FileCheck -check-prefix=CHECK2 %s # CHECK-DAG: .debug_loclists.dwo contents: # CHECK: locations list header: length = 0x00000019, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000001 @@ -22,6 +23,14 @@ # CHECK: Index Signature INFO ABBREV LOCLISTS # CHECK: 2 {{.*}} [0x00000000, 0x00000018) [0x00000000, 0x00000004) [0x00000000, 0x0000001d) +# CHECK2-DAG: .debug_cu_index contents: +# CHECK2: Index Signature INFO ABBREV LOCLISTS +# CHECK2: 1 {{.*}} [0x00000018, 0x0000002d) [0x00000000, 0x00000004) [0x00000000, 0x0000001d) + +# CHECK2-DAG: .debug_tu_index contents: +# CHECK2: Index Signature INFO ABBREV LOCLISTS +# CHECK2: 2 {{.*}} [0x00000000, 0x00000018) [0x00000000, 0x00000004) [0x00000000, 0x0000001d) + .section .debug_info.dwo,"e",@progbits .long .Ldebug_info_dwo_end0-.Ldebug_info_dwo_start0 # Length of Unit .Ldebug_info_dwo_start0: diff --git a/llvm/test/tools/llvm-dwp/X86/rnglists.s b/llvm/test/tools/llvm-dwp/X86/rnglists.s --- a/llvm/test/tools/llvm-dwp/X86/rnglists.s +++ b/llvm/test/tools/llvm-dwp/X86/rnglists.s @@ -3,7 +3,8 @@ # RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o %t.o \ # RUN: -split-dwarf-file=%t.dwo -dwarf-version=5 # RUN: llvm-dwp %t.dwo -o %t.dwp -# RUN: llvm-dwarfdump -debug-rnglists -debug-cu-index -debug-tu-index %t.dwp | FileCheck %s +# RUN: llvm-dwarfdump -debug-rnglists -debug-cu-index -debug-tu-index %t.dwp | FileCheck -check-prefix=CHECK %s +# RUN: llvm-dwarfdump -debug-cu-index -debug-tu-index -manaully-generate-cu-tu-index %t.dwp | FileCheck -check-prefix=CHECK2 %s # CHECK-DAG: .debug_cu_index contents: # CHECK: Index Signature INFO ABBREV RNGLISTS @@ -22,6 +23,14 @@ # CHECK-NEXT: [0x0000000000000004, 0x0000000000000008) # CHECK-NEXT: [0x000000000000000c, 0x0000000000000010) +# CHECK2-DAG: .debug_cu_index contents: +# CHECK2: Index Signature INFO ABBREV RNGLISTS +# CHECK2: 1 {{.*}} [0x00000018, 0x0000002d) [0x00000000, 0x00000004) [0x00000000, 0x00000017) + +# CHECK2-DAG: .debug_tu_index contents: +# CHECK2: Index Signature INFO ABBREV RNGLISTS +# CHECK2: 2 {{.*}} [0x00000000, 0x00000018) [0x00000000, 0x00000004) [0x00000000, 0x00000017) + .section .debug_info.dwo,"e",@progbits .long .Ldebug_info_dwo_end0-.Ldebug_info_dwo_start0 # Length of Unit .Ldebug_info_dwo_start0: diff --git a/llvm/test/tools/llvm-dwp/X86/tu_units_v5.s b/llvm/test/tools/llvm-dwp/X86/tu_units_v5.s --- a/llvm/test/tools/llvm-dwp/X86/tu_units_v5.s +++ b/llvm/test/tools/llvm-dwp/X86/tu_units_v5.s @@ -3,7 +3,8 @@ # RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o %t.o \ # RUN: -split-dwarf-file=%t.dwo -dwarf-version=5 # RUN: llvm-dwp %t.dwo -o %t.dwp -# RUN: llvm-dwarfdump -debug-info -debug-tu-index %t.dwp | FileCheck %s +# RUN: llvm-dwarfdump -debug-info -debug-tu-index %t.dwp | FileCheck -check-prefix=CHECK %s +# RUN2: llvm-dwarfdump -debug-info -debug-tu-index -manaully-generate-cu-tu-index %t.dwp | FileCheck -check-prefix=CHECK2 %s ## Note: In order to check whether the type unit index is generated ## there is no need to add the missing DIEs for the structure type of the type unit. @@ -17,6 +18,15 @@ # CHECK: 1 [[TUID1]] [0x00000000, 0x0000001b) [0x00000000, 0x00000010) # CHECK: 4 [[TUID2]] [0x0000001b, 0x00000036) [0x00000000, 0x00000010) +# CHECK2-DAG: .debug_info.dwo contents: +# CHECK2: 0x00000000: Type Unit: length = 0x00000017, format = DWARF32, version = 0x0005, unit_type = DW_UT_split_type, abbr_offset = 0x0000, addr_size = 0x08, name = '', type_signature = [[TUID1:.*]], type_offset = 0x0019 (next unit at 0x0000001b) +# CHECK2: 0x0000001b: Type Unit: length = 0x00000017, format = DWARF32, version = 0x0005, unit_type = DW_UT_split_type, abbr_offset = 0x0000, addr_size = 0x08, name = '', type_signature = [[TUID2:.*]], type_offset = 0x0019 (next unit at 0x00000036) +# CHECK2-DAG: .debug_tu_index contents: +# CHECK2: version = 5, units = 2, slots = 4 +# CHECK2: Index Signature INFO ABBREV +# CHECK2: 1 [[TUID1]] [0x00000000, 0x0000001b) [0x00000000, 0x00000010) +# CHECK2: 4 [[TUID2]] [0x0000001b, 0x00000036) [0x00000000, 0x00000010) + .section .debug_info.dwo,"e",@progbits .long .Ldebug_info_dwo_end0-.Ldebug_info_dwo_start0 # Length of Unit .Ldebug_info_dwo_start0: diff --git a/llvm/test/tools/llvm-dwp/X86/type_dedup.test b/llvm/test/tools/llvm-dwp/X86/type_dedup.test --- a/llvm/test/tools/llvm-dwp/X86/type_dedup.test +++ b/llvm/test/tools/llvm-dwp/X86/type_dedup.test @@ -1,8 +1,10 @@ RUN: llvm-dwp %p/../Inputs/type_dedup/a.dwo %p/../Inputs/type_dedup/b.dwo -o %t -RUN: llvm-dwarfdump -v %t | FileCheck %s +RUN: llvm-dwarfdump -v %t | FileCheck -check-prefix=CHECK %s +RUN: llvm-dwarfdump -v -manaully-generate-cu-tu-index %t | FileCheck -check-prefix=CHECK2 %s RUN: llvm-dwp %p/../Inputs/type_dedup/b.dwo -o %tb.dwp RUN: llvm-dwp %p/../Inputs/type_dedup/a.dwo %tb.dwp -o %t -RUN: llvm-dwarfdump -v %t | FileCheck %s +RUN: llvm-dwarfdump -v %t | FileCheck -check-prefix=CHECK %s +RUN: llvm-dwarfdump -v -manaully-generate-cu-tu-index %t | FileCheck -check-prefix=CHECK2 %s a.cpp: struct common { }; @@ -36,3 +38,24 @@ CHECK: 0x00000066: DW_TAG_structure_type CHECK: DW_AT_name {{.*}} "bdistinct" CHECK-NOT: Type Unit + +CHECK2-LABEL: .debug_types.dwo contents: +CHECK2: [[COMMONUOFF:0x[0-9a-f]*]]: +CHECK2-LABEL: Type Unit: length = 0x00000020, format = DWARF32, version = 0x0004, abbr_offset = +CHECK2: 0x0000, addr_size = 0x08, name = 'common', type_signature = [[COMMONSIG:0x[0-9a-f]*]], type_offset = 0x[[COMMONOFF:.*]] (next unit at [[AUOFF:.*]]) +CHECK2: DW_TAG_type_unit +CHECK2: [[COMMONOFF]]: DW_TAG_structure_type +CHECK2: DW_AT_name {{.*}} "common" +CHECK2: [[AUOFF]]: +CHECK2-LABEL: Type Unit: length = 0x00000020, format = DWARF32, version = 0x0004, abbr_offset = +CHECK2: 0x0000, addr_size = 0x08, name = 'adistinct', type_signature = [[ASIG:0x[0-9a-f]*]], type_offset = 0x[[AOFF:.*]] (next unit at [[BUOFF:.*]]) +CHECK2: DW_TAG_type_unit +CHECK2: 0x00000042: DW_TAG_structure_type +CHECK2: DW_AT_name {{.*}} "adistinct" +CHECK2: [[BUOFF]]: +CHECK2-LABEL: Type Unit: length = 0x00000020, format = DWARF32, version = 0x0004, abbr_offset = +CHECK2: 0x{{.*}}, addr_size = 0x08, name = 'bdistinct', type_signature = [[BSIG:0x[0-9a-f]*]], type_offset = 0x[[BOFF:.*]] (next unit at [[XUOFF:.*]]) +CHECK2: DW_TAG_type_unit +CHECK2: 0x00000066: DW_TAG_structure_type +CHECK2: DW_AT_name {{.*}} "bdistinct" +CHECK2-NOT: Type Unit diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp --- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -255,6 +255,14 @@ ShowSources("show-sources", cl::desc("Show the sources across all compilation units."), cat(DwarfDumpCategory)); +static cl::opt + ManuallyGenerateCUIndex("manaully-generate-cu-tu-index", + cl::desc("if the input is dwp file, parse debug " + "info section and use it to populate " + "DEBUG_INFO contributions in cu-index. " + "For DWARF5 it also populated TU Index."), + cl::init(false), cl::Hidden, + cl::cat(DwarfDumpCategory)); // facebook begin D13311561 static cl::opt Analyze("analyze", @@ -669,6 +677,7 @@ std::unique_ptr DICtx = DWARFContext::create( *Obj, DWARFContext::ProcessDebugRelocations::Process, nullptr, "", RecoverableErrorHandler); + DICtx->setParseCUTUIndexManually(ManuallyGenerateCUIndex); if (!HandleObj(*Obj, *DICtx, Filename, OS)) Result = false; }