Index: include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h +++ include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h @@ -10,6 +10,7 @@ #ifndef LLVM_DEBUGINFO_DWARFACCELERATORTABLE_H #define LLVM_DEBUGINFO_DWARFACCELERATORTABLE_H +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h" @@ -20,11 +21,30 @@ namespace llvm { class raw_ostream; +class ScopedPrinter; + +class DWARFAcceleratorTable { +protected: + DWARFDataExtractor AccelSection; + DataExtractor StringSection; + +public: + DWARFAcceleratorTable(const DWARFDataExtractor &AccelSection, + DataExtractor StringSection) + : AccelSection(AccelSection), StringSection(StringSection) {} + virtual ~DWARFAcceleratorTable(); + + virtual llvm::Error extract() = 0; + virtual void dump(raw_ostream &OS) const = 0; + + DWARFAcceleratorTable(const DWARFAcceleratorTable &) = delete; + void operator=(const DWARFAcceleratorTable &) = delete; +}; /// This implements the Apple accelerator table format, a precursor of the /// DWARF 5 accelerator table format. /// TODO: Factor out a common base class for both formats. -class AppleAcceleratorTable { +class AppleAcceleratorTable : public DWARFAcceleratorTable { struct Header { uint32_t Magic; uint16_t Version; @@ -44,8 +64,6 @@ struct Header Hdr; struct HeaderData HdrData; - DWARFDataExtractor AccelSection; - DataExtractor StringSection; bool IsValid = false; public: @@ -85,12 +103,11 @@ } }; - AppleAcceleratorTable(const DWARFDataExtractor &AccelSection, DataExtractor StringSection) - : AccelSection(AccelSection), StringSection(StringSection) {} + : DWARFAcceleratorTable(AccelSection, StringSection) {} - llvm::Error extract(); + llvm::Error extract() override; uint32_t getNumBuckets(); uint32_t getNumHashes(); uint32_t getSizeHdr(); @@ -107,12 +124,99 @@ /// related to the input hash data offset. /// DieTag is the tag of the DIE std::pair readAtoms(uint32_t &HashDataOffset); - void dump(raw_ostream &OS) const; + void dump(raw_ostream &OS) const override; /// Look up all entries in the accelerator table matching \c Key. iterator_range equal_range(StringRef Key) const; }; +/// .debug_names section consists of one or more units. Each unit starts with a +/// header, which is followed by a list of compilation units, local and foreign +/// type units. +/// +/// These may be followed by an (optional) hash lookup table, which consists of +/// an array of buckets and hashes similar to the apple tables above. The only +/// difference is that the hashes array is 1-based, and consequently an empty +/// bucket is denoted by 0 and not UINT32_MAX. +/// +/// Next is the name table, which consists of an array of names and array of +/// entry offsets. This is different from the apple tables, which store names +/// next to the actual entries. +/// +/// The structure of the entries is described by an abbreviations table, which +/// comes after the name table. Unlike the apple tables, which have a uniform +/// entry structure described in the header, each .debug_names entry may have +/// different index attributes (DW_IDX_???) attached to it. +/// +/// The last segment consists of a list of entries, which is a 0-terminated list +/// referenced by the name table and interpreted with the help of the +/// abbreviation table. +class DWARFDebugNames : public DWARFAcceleratorTable { +public: + struct Header { + uint32_t UnitLength; + uint16_t Version; + uint16_t Padding; + uint32_t NumCUs; + uint32_t NumLocalTUs; + uint32_t NumForeignTUs; + uint32_t NumBuckets; + uint32_t NumNames; + uint32_t AbbrevLength; + uint32_t AugmentationLen; + // Augmentation bytes follow + }; + struct Abbrev { + dwarf::Tag Tag; + std::vector> Indices; + }; + + class Unit { + DenseMap Abbrevs; + struct Header Hdr; + llvm::SmallString<8> HeaderAugmentation; + const DWARFDebugNames &Section; + + // Base of the whole unit and of various important tables, as offsets from + // the start of the section. + uint32_t Base; + uint32_t CUsBase; + uint32_t BucketsBase; + uint32_t HashesBase; + uint32_t StringOffsetsBase; + uint32_t EntryOffsetsBase; + uint32_t EntriesBase; + + void dumpCUs(ScopedPrinter &W) const; + void dumpLocalTUs(ScopedPrinter &W) const; + void dumpForeignTUs(ScopedPrinter &W) const; + void dumpAbbreviations(ScopedPrinter &W) const; + bool dumpEntry(ScopedPrinter &W, uint32_t *Offset) const; + void dumpName(ScopedPrinter &W, uint32_t Index, + Optional Hash) const; + void dumpBucket(ScopedPrinter &W, uint32_t Bucket) const; + + public: + Unit(const DWARFDebugNames &Section, uint32_t Base) + : Section(Section), Base(Base) {} + + llvm::Error extract(); + uint32_t getNextUnitOffset() const { return Base + 4 + Hdr.UnitLength; } + void dump(ScopedPrinter &W) const; + }; + +private: + std::vector Units; + +public: + DWARFDebugNames(const DWARFDataExtractor &AccelSection, + DataExtractor StringSection) + : DWARFAcceleratorTable(AccelSection, StringSection) {} + + llvm::Error extract() override; + void dump(raw_ostream &OS) const override; +}; + } // end namespace llvm #endif // LLVM_DEBUGINFO_DWARFACCELERATORTABLE_H Index: include/llvm/DebugInfo/DWARF/DWARFContext.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFContext.h +++ include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -69,6 +69,7 @@ std::unique_ptr DebugFrame; std::unique_ptr EHFrame; std::unique_ptr Macro; + std::unique_ptr Names; std::unique_ptr AppleNames; std::unique_ptr AppleTypes; std::unique_ptr AppleNamespaces; @@ -242,6 +243,9 @@ /// Get a pointer to the parsed DebugMacro object. const DWARFDebugMacro *getDebugMacro(); + /// Get a reference to the parsed accelerator table object. + const DWARFDebugNames &getDebugNames(); + /// Get a reference to the parsed accelerator table object. const AppleAcceleratorTable &getAppleNames(); Index: include/llvm/DebugInfo/DWARF/DWARFObject.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFObject.h +++ include/llvm/DebugInfo/DWARF/DWARFObject.h @@ -67,6 +67,7 @@ virtual const DWARFSection &getAppleNamespacesSection() const { return Dummy; } + virtual const DWARFSection &getDebugNamesSection() const { return Dummy; } virtual const DWARFSection &getAppleObjCSection() const { return Dummy; } virtual StringRef getCUIndexSection() const { return ""; } virtual StringRef getGdbIndexSection() const { return ""; } Index: lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp +++ lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp @@ -14,6 +14,7 @@ #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Format.h" +#include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -21,6 +22,33 @@ using namespace llvm; +static std::string formatEnum(StringRef (*StringFn)(unsigned), StringRef Type, unsigned Value) { + std::string Str = StringFn(Value); + if (!Str.empty()) + return Str; + raw_string_ostream SS(Str); + SS << "DW_" << Type << "_Unknown_0x" << format("%x", Value); + return SS.str(); +} + +static std::string formatTag(unsigned Tag) { + return formatEnum(dwarf::TagString, "TAG", Tag); +} + +static std::string formatForm(unsigned Form) { + return formatEnum(dwarf::FormEncodingString, "FORM", Form); +} + +static std::string formatIndex(unsigned Idx) { + return formatEnum(dwarf::IndexString, "IDX", Idx); +} + +static std::string formatAtom(unsigned Atom) { + return formatEnum(dwarf::AtomTypeString, "IDX", Atom); +} + +DWARFAcceleratorTable::~DWARFAcceleratorTable() = default; + llvm::Error AppleAcceleratorTable::extract() { uint32_t Offset = 0; @@ -131,19 +159,8 @@ unsigned i = 0; SmallVector AtomForms; for (const auto &Atom: HdrData.Atoms) { - OS << format("Atom[%d] Type: ", i++); - auto TypeString = dwarf::AtomTypeString(Atom.first); - if (!TypeString.empty()) - OS << TypeString; - else - OS << format("DW_ATOM_Unknown_0x%x", Atom.first); - OS << " Form: "; - auto FormString = dwarf::FormEncodingString(Atom.second); - if (!FormString.empty()) - OS << FormString; - else - OS << format("DW_FORM_Unknown_0x%x", Atom.second); - OS << '\n'; + OS << format("Atom[%d] Type: ", i++) << formatAtom(Atom.first) + << " Form: " << formatForm(Atom.second) << '\n'; AtomForms.push_back(DWARFFormValue(Atom.second)); } @@ -266,3 +283,261 @@ } return make_range(ValueIterator(), ValueIterator()); } + +static std::pair getULEB128Pair(const DWARFDataExtractor &E, + uint32_t *Offset) { + uint32_t One = E.getULEB128(Offset); + uint32_t Two = E.getULEB128(Offset); + return {One, Two}; +} + +llvm::Error DWARFDebugNames::Unit::extract() { + uint32_t Offset = Base; + const DWARFDataExtractor &AS = Section.AccelSection; + + // Check that we can at least read the header. + if (!AS.isValidOffset(Offset + sizeof(Header) - 1)) + return make_error("Section too small: cannot read header.", + inconvertibleErrorCode()); + + Hdr.UnitLength = AS.getU32(&Offset); + Hdr.Version = AS.getU16(&Offset); + Hdr.Padding = AS.getU16(&Offset); + Hdr.NumCUs = AS.getU32(&Offset); + Hdr.NumLocalTUs = AS.getU32(&Offset); + Hdr.NumForeignTUs = AS.getU32(&Offset); + Hdr.NumBuckets = AS.getU32(&Offset); + Hdr.NumNames = AS.getU32(&Offset); + Hdr.AbbrevLength = AS.getU32(&Offset); + Hdr.AugmentationLen = AS.getU32(&Offset); + + if (!AS.isValidOffsetForDataOfSize(Offset, Hdr.AugmentationLen)) + return make_error( + "Section too small: cannot read header augmentation.", + inconvertibleErrorCode()); + HeaderAugmentation.resize(Hdr.AugmentationLen); + AS.getU8(&Offset, reinterpret_cast(HeaderAugmentation.data()), + Hdr.AugmentationLen); + Offset = alignTo(Offset, 4); + + CUsBase = Offset; + Offset += Hdr.NumCUs * 4; + Offset += Hdr.NumLocalTUs * 4; + Offset += Hdr.NumForeignTUs * 8; + BucketsBase = Offset; + Offset += Hdr.NumBuckets * 4; + HashesBase = Offset; + if (Hdr.NumBuckets > 0) + Offset += Hdr.NumNames * 4; + StringOffsetsBase = Offset; + Offset += Hdr.NumNames * 4; + EntryOffsetsBase = Offset; + Offset += Hdr.NumNames * 4; + + if (!AS.isValidOffsetForDataOfSize(Offset, Hdr.AbbrevLength)) + return make_error( + "Section too small: cannot read abbreviations.", + inconvertibleErrorCode()); + + EntriesBase = Offset + Hdr.AbbrevLength; + + uint32_t Code; + while ((Code = AS.getULEB128(&Offset)) != 0) { + Abbrev &A = Abbrevs[Code]; + A.Tag = dwarf::Tag(AS.getULEB128(&Offset)); + std::pair IndexForm; + while (IndexForm = getULEB128Pair(AS, &Offset), + IndexForm.first || IndexForm.second) { + A.Indices.emplace_back(dwarf::Index(IndexForm.first), + dwarf::Form(IndexForm.second)); + } + } + + return Error::success(); +} + +// Returns true if we should continue scanning for entries, false if this is the +// last (sentinel) entry). In case of a parsing error we also return false, as +// it's not possible to recover this entry list (but the other lists may still +// parse OK). +bool DWARFDebugNames::Unit::dumpEntry(ScopedPrinter &W, + uint32_t *Offset) const { + DWARFFormParams FormParams = {Hdr.Version, 0, dwarf::DwarfFormat::DWARF32}; + const DWARFDataExtractor &AS = Section.AccelSection; + uint32_t EntryID = *Offset; + uint32_t AbbrevID = AS.getULEB128(Offset); + if (AbbrevID == 0) + return false; + + DictScope EntryScope(W, ("Entry@0x" + Twine::utohexstr(EntryID)).str()); + W.printHex("Abbrev", AbbrevID); + + const auto AbbrevIt = Abbrevs.find(AbbrevID); + if (AbbrevIt == Abbrevs.end()) { + W.startLine() << "Invalid abbreviation\n"; + return false; + } + const Abbrev &Abbr = AbbrevIt->second; + W.startLine() << "Tag: " << formatTag(Abbr.Tag) << "\n"; + + for (const auto &Ind : Abbr.Indices) { + W.startLine() << formatIndex(Ind.first) << ": "; + DWARFFormValue Form(Ind.second); + if (!Form.extractValue(AS, Offset, FormParams)) { + W.getOStream() << "Error extracting the value\n"; + return false; + } + Form.dump(W.getOStream()); + W.getOStream() << '\n'; + } + return true; +} + +void DWARFDebugNames::Unit::dumpName(ScopedPrinter &W, uint32_t Index, + Optional Hash) const { + uint32_t StringOffsetOffset = StringOffsetsBase + 4 * (Index - 1); + uint32_t EntryOffsetOffset = EntryOffsetsBase + 4 * (Index - 1); + const DWARFDataExtractor &AS = Section.AccelSection; + const DataExtractor &SS = Section.StringSection; + + DictScope NameScope(W, ("Name " + Twine(Index)).str()); + if (Hash) + W.printHex("Hash", *Hash); + + uint32_t StringOffset = AS.getRelocatedValue(4, &StringOffsetOffset); + W.startLine() << format("String: 0x%08x", StringOffset); + W.getOStream() << " \"" << SS.getCStr(&StringOffset) << "\"\n"; + + uint32_t EntryOffset = AS.getU32(&EntryOffsetOffset); + EntryOffset += EntriesBase; + + do { + if (!AS.isValidOffset(EntryOffset)) { + W.startLine() << "Incorrectly terminated entry list\n"; + break; + } + } while (dumpEntry(W, &EntryOffset)); +} + +void DWARFDebugNames::Unit::dumpCUs(ScopedPrinter &W) const { + uint32_t Offset = CUsBase; + const DWARFDataExtractor &AS = Section.AccelSection; + ListScope CUScope(W, "Compilation Unit offsets"); + for (uint32_t CU = 0; CU < Hdr.NumCUs; ++CU) { + uint32_t CUOffset = AS.getRelocatedValue(4, &Offset); + W.startLine() << format("CU[%u]: 0x%08X\n", CU, CUOffset); + } +} + +void DWARFDebugNames::Unit::dumpLocalTUs(ScopedPrinter &W) const { + if (Hdr.NumLocalTUs == 0) + return; + + uint32_t Offset = CUsBase + Hdr.NumCUs * 4; + const DWARFDataExtractor &AS = Section.AccelSection; + ListScope TUScope(W, "Local Type Unit offsets"); + for (uint32_t TU = 0; TU < Hdr.NumLocalTUs; ++TU) { + uint32_t TUOffset = AS.getRelocatedValue(4, &Offset); + W.startLine() << format("LocalTU[%u]: 0x%08X\n", TU, TUOffset); + } +} + +void DWARFDebugNames::Unit::dumpForeignTUs(ScopedPrinter &W) const { + if (Hdr.NumForeignTUs == 0) + return; + + uint32_t Offset = CUsBase + (Hdr.NumCUs + Hdr.NumLocalTUs) * 4; + const DWARFDataExtractor &AS = Section.AccelSection; + ListScope TUScope(W, "Foreign Type Unit signatures"); + for (uint32_t TU = 0; TU < Hdr.NumForeignTUs; ++TU) { + uint64_t TUOffset = AS.getU64(&Offset); + W.startLine() << format("ForeignTU[%u]: 0x%016" PRIx64 "\n", TU, TUOffset); + } +} + +void DWARFDebugNames::Unit::dumpAbbreviations(ScopedPrinter &W) const { + ListScope AbbrevsScope(W, "Abbreviations"); + for (const auto &KV : Abbrevs) { + DictScope AbbrevScope( + W, ("Abbreviation 0x" + Twine::utohexstr(KV.getFirst())).str()); + W.startLine() << "Tag: " << formatTag(KV.getSecond().Tag) << '\n'; + + for (const auto &IndexForm : KV.getSecond().Indices) { + W.startLine() << formatIndex(IndexForm.first) << ": " + << formatForm(IndexForm.second) << '\n'; + } + } +} + +void DWARFDebugNames::Unit::dumpBucket(ScopedPrinter &W, + uint32_t Bucket) const { + uint32_t Offset = BucketsBase + 4 * Bucket; + const DWARFDataExtractor &AS = Section.AccelSection; + ListScope BucketScope(W, ("Bucket " + Twine(Bucket)).str()); + uint32_t Index = AS.getU32(&Offset); + if (Index == 0) { + W.printString("EMPTY"); + return; + } + if (Index > Hdr.NumNames) { + W.printString("Name index is invalid"); + return; + } + + for (; Index <= Hdr.NumNames; ++Index) { + uint32_t HashOffset = HashesBase + 4 * (Index - 1); + + uint32_t Hash = AS.getU32(&HashOffset); + if (Hash % Hdr.NumBuckets != Bucket) + break; + + dumpName(W, Index, Hash); + } +} + +LLVM_DUMP_METHOD void DWARFDebugNames::Unit::dump(ScopedPrinter &W) const { + DictScope UnitScope(W, ("Unit@0x" + Twine::utohexstr(Base)).str()); + W.printHex("Length", Hdr.UnitLength); + W.printNumber("Version", Hdr.Version); + W.printHex("Padding", Hdr.Padding); + W.printNumber("CU count", Hdr.NumCUs); + W.printNumber("Local TU count", Hdr.NumLocalTUs); + W.printNumber("Foreign TU count", Hdr.NumForeignTUs); + W.printNumber("Bucket count", Hdr.NumBuckets); + W.printNumber("Name count", Hdr.NumNames); + W.printHex("Abbreviations length", Hdr.AbbrevLength); + W.startLine() << "Augmentation: '" << HeaderAugmentation << "'\n"; + + dumpCUs(W); + dumpLocalTUs(W); + dumpForeignTUs(W); + dumpAbbreviations(W); + + if (Hdr.NumBuckets > 0) { + for (uint32_t Bucket = 0; Bucket < Hdr.NumBuckets; ++Bucket) + dumpBucket(W, Bucket); + return; + } + + W.startLine() << "Hash table not present\n"; + for (uint32_t Index = 1; Index <= Hdr.NumNames; ++Index) + dumpName(W, Index, None); +} + +llvm::Error DWARFDebugNames::extract() { + uint32_t Offset = 0; + while (AccelSection.isValidOffset(Offset)) { + Unit Next(*this, Offset); + if (llvm::Error E = Next.extract()) + return E; + Offset = Next.getNextUnitOffset(); + Units.push_back(std::move(Next)); + } + return Error::success(); +} + +LLVM_DUMP_METHOD void DWARFDebugNames::dump(raw_ostream &OS) const { + ScopedPrinter W(OS); + for (const Unit &U : Units) + U.dump(W); +} Index: lib/DebugInfo/DWARF/DWARFContext.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFContext.cpp +++ lib/DebugInfo/DWARF/DWARFContext.cpp @@ -535,6 +535,9 @@ if (shouldDump(Explicit, ".apple_objc", DIDT_ID_AppleObjC, DObj->getAppleObjCSection().Data)) getAppleObjC().dump(OS); + if (shouldDump(Explicit, ".debug_names", DIDT_ID_DebugNames, + DObj->getDebugNamesSection().Data)) + getDebugNames().dump(OS); } DWARFCompileUnit *DWARFContext::getDWOCompileUnitForHash(uint64_t Hash) { @@ -703,15 +706,15 @@ return Macro.get(); } -static AppleAcceleratorTable & -getAccelTable(std::unique_ptr &Cache, - const DWARFObject &Obj, const DWARFSection &Section, - StringRef StringSection, bool IsLittleEndian) { +template +static T &getAccelTable(std::unique_ptr &Cache, const DWARFObject &Obj, + const DWARFSection &Section, StringRef StringSection, + bool IsLittleEndian) { if (Cache) return *Cache; DWARFDataExtractor AccelSection(Obj, Section, IsLittleEndian, 0); DataExtractor StrData(StringSection, IsLittleEndian, 0); - Cache.reset(new AppleAcceleratorTable(AccelSection, StrData)); + Cache.reset(new T(AccelSection, StrData)); if (Error E = Cache->extract()) llvm::consumeError(std::move(E)); return *Cache; @@ -738,6 +741,11 @@ DObj->getStringSection(), isLittleEndian()); } +const DWARFDebugNames &DWARFContext::getDebugNames() { + return getAccelTable(Names, *DObj, DObj->getDebugNamesSection(), + DObj->getStringSection(), isLittleEndian()); +} + const DWARFLineTable * DWARFContext::getLineTableForUnit(DWARFUnit *U) { if (!Line) @@ -1157,6 +1165,7 @@ DWARFSectionMap AppleTypesSection; DWARFSectionMap AppleNamespacesSection; DWARFSectionMap AppleObjCSection; + DWARFSectionMap DebugNamesSection; DWARFSectionMap *mapNameToDWARFSection(StringRef Name) { return StringSwitch(Name) @@ -1168,6 +1177,7 @@ .Case("debug_info.dwo", &InfoDWOSection) .Case("debug_loc.dwo", &LocDWOSection) .Case("debug_line.dwo", &LineDWOSection) + .Case("debug_names", &DebugNamesSection) .Case("debug_str_offsets.dwo", &StringOffsetDWOSection) .Case("debug_addr", &AddrSection) .Case("apple_names", &AppleNamesSection) @@ -1473,6 +1483,9 @@ const DWARFSection &getAppleObjCSection() const override { return AppleObjCSection; } + const DWARFSection &getDebugNamesSection() const override { + return DebugNamesSection; + } StringRef getFileName() const override { return FileName; } uint8_t getAddressSize() const override { return AddressSize; } Index: test/DebugInfo/X86/dwarfdump-debug-names.s =================================================================== --- /dev/null +++ test/DebugInfo/X86/dwarfdump-debug-names.s @@ -0,0 +1,172 @@ +# RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj -o - | llvm-dwarfdump -debug-names - | FileCheck %s + .section .debug_str,"MS",@progbits,1 +.Linfo_string0: + .asciz "foo" +.Linfo_string1: + .asciz "_Z3foov" +.Linfo_string2: + .asciz "bar" + +# Fake .debug_info. We just need it for the offsets to two "compile units" and +# two "DIEs" + .section .debug_info,"",@progbits +.Lcu_begin0: + .byte 0 +.Ldie0: + .byte 0 +.Lcu_begin1: + .byte 0 +.Ldie1: + .byte 0 + + .section .debug_names,"",@progbits + .long .Lnames_end0-.Lnames_start0 # Header: contribution length +.Lnames_start0: + .short 5 # Header: version + .short 0 # Header: padding + .long 1 # Header: compilation unit count + .long 0 # Header: local type unit count + .long 0 # Header: foreign type unit count + .long 2 # Header: bucket count + .long 2 # Header: name count + .long .Lnames_abbrev_end0-.Lnames_abbrev_start0 # Header: abbreviation table size + .long 0 # Header: augmentation length + .long .Lcu_begin0 # Compilation unit 0 + .long 0 # Bucket 0 + .long 1 # Bucket 1 + .long 193491849 # Hash in Bucket 1 + .long -1257882357 # Hash in Bucket 1 + .long .Linfo_string0 # String in Bucket 1: foo + .long .Linfo_string1 # String in Bucket 1: _Z3foov + .long .Lnames0-.Lnames_entries0 # Offset in Bucket 1 + .long .Lnames1-.Lnames_entries0 # Offset in Bucket 1 +.Lnames_abbrev_start0: + .byte 46 # Abbrev code + .byte 46 # DW_TAG_subprogram + .byte 3 # DW_IDX_die_offset + .byte 6 # DW_FORM_data4 + .byte 0 # End of abbrev + .byte 0 # End of abbrev + .byte 0 # End of abbrev list +.Lnames_abbrev_end0: +.Lnames_entries0: +.Lnames0: + .byte 46 # Abbrev code + .long .Ldie0 # DW_IDX_die_offset + .long 0 # End of list: foo +.Lnames1: + .byte 46 # Abbrev code + .long .Ldie0 # DW_IDX_die_offset + .long 0 # End of list: _Z3foov + .p2align 2 +.Lnames_end0: + + .long .Lnames_end1-.Lnames_start1 # Header: contribution length +.Lnames_start1: + .short 5 # Header: version + .short 0 # Header: padding + .long 1 # Header: compilation unit count + .long 0 # Header: local type unit count + .long 0 # Header: foreign type unit count + .long 1 # Header: bucket count + .long 1 # Header: name count + .long .Lnames_abbrev_end1-.Lnames_abbrev_start1 # Header: abbreviation table size + .long 0 # Header: augmentation length + .long .Lcu_begin1 # Compilation unit 0 + .long 1 # Bucket 0 + .long 193487034 # Hash in Bucket 0 + .long .Linfo_string2 # String in Bucket 0: bar + .long .Lnames2-.Lnames_entries1 # Offset in Bucket 0 +.Lnames_abbrev_start1: + .byte 52 # Abbrev code + .byte 52 # DW_TAG_variable + .byte 3 # DW_IDX_die_offset + .byte 6 # DW_FORM_data4 + .byte 0 # End of abbrev + .byte 0 # End of abbrev + .byte 0 # End of abbrev list +.Lnames_abbrev_end1: +.Lnames_entries1: +.Lnames2: + .byte 52 # Abbrev code + .long .Ldie1 # DW_IDX_die_offset + .long 0 # End of list: bar + .p2align 2 +.Lnames_end1: +# CHECK: .debug_names contents: +# CHECK-NEXT: Unit@0x0 { +# CHECK-NEXT: Length: 0x60 +# CHECK-NEXT: Version: 5 +# CHECK-NEXT: Padding: 0x0 +# CHECK-NEXT: CU count: 1 +# CHECK-NEXT: Local TU count: 0 +# CHECK-NEXT: Foreign TU count: 0 +# CHECK-NEXT: Bucket count: 2 +# CHECK-NEXT: Name count: 2 +# CHECK-NEXT: Abbreviations length: 0x7 +# CHECK-NEXT: Augmentation: '' +# CHECK-NEXT: Compilation Unit offsets [ +# CHECK-NEXT: CU[0]: 0x00000000 +# CHECK-NEXT: ] +# CHECK-NEXT: Abbreviations [ +# CHECK-NEXT: Abbreviation 0x2e { +# CHECK-NEXT: Tag: DW_TAG_subprogram +# CHECK-NEXT: DW_IDX_die_offset: DW_FORM_data4 +# CHECK-NEXT: } +# CHECK-NEXT: ] +# CHECK-NEXT: Bucket 0 [ +# CHECK-NEXT: EMPTY +# CHECK-NEXT: ] +# CHECK-NEXT: Bucket 1 [ +# CHECK-NEXT: Name 1 { +# CHECK-NEXT: Hash: 0xB887389 +# CHECK-NEXT: String: 0x00000000 "foo" +# CHECK-NEXT: Entry@0x4f { +# CHECK-NEXT: Abbrev: 0x2E +# CHECK-NEXT: Tag: DW_TAG_subprogram +# CHECK-NEXT: DW_IDX_die_offset: 0x00000001 +# CHECK-NEXT: } +# CHECK-NEXT: } +# CHECK-NEXT: Name 2 { +# CHECK-NEXT: Hash: 0xB5063D0B +# CHECK-NEXT: String: 0x00000004 "_Z3foov" +# CHECK-NEXT: Entry@0x58 { +# CHECK-NEXT: Abbrev: 0x2E +# CHECK-NEXT: Tag: DW_TAG_subprogram +# CHECK-NEXT: DW_IDX_die_offset: 0x00000001 +# CHECK-NEXT: } +# CHECK-NEXT: } +# CHECK-NEXT: ] +# CHECK-NEXT: } +# CHECK-NEXT: Unit@0x64 { +# CHECK-NEXT: Length: 0x44 +# CHECK-NEXT: Version: 5 +# CHECK-NEXT: Padding: 0x0 +# CHECK-NEXT: CU count: 1 +# CHECK-NEXT: Local TU count: 0 +# CHECK-NEXT: Foreign TU count: 0 +# CHECK-NEXT: Bucket count: 1 +# CHECK-NEXT: Name count: 1 +# CHECK-NEXT: Abbreviations length: 0x7 +# CHECK-NEXT: Augmentation: '' +# CHECK-NEXT: Compilation Unit offsets [ +# CHECK-NEXT: CU[0]: 0x00000002 +# CHECK-NEXT: ] +# CHECK-NEXT: Abbreviations [ +# CHECK-NEXT: Abbreviation 0x34 { +# CHECK-NEXT: Tag: DW_TAG_variable +# CHECK-NEXT: DW_IDX_die_offset: DW_FORM_data4 +# CHECK-NEXT: } +# CHECK-NEXT: ] +# CHECK-NEXT: Bucket 0 [ +# CHECK-NEXT: Name 1 { +# CHECK-NEXT: Hash: 0xB8860BA +# CHECK-NEXT: String: 0x0000000c "bar" +# CHECK-NEXT: Entry@0xa3 { +# CHECK-NEXT: Abbrev: 0x34 +# CHECK-NEXT: Tag: DW_TAG_variable +# CHECK-NEXT: DW_IDX_die_offset: 0x00000003 +# CHECK-NEXT: } +# CHECK-NEXT: } +# CHECK-NEXT: ] +# CHECK-NEXT: } Index: tools/llvm-dwarfdump/llvm-dwarfdump.cpp =================================================================== --- tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -377,6 +377,7 @@ return DumpOffsets[DIDT_ID_DebugInfo] = *Offset; if (auto Offset = find(DICtx.getAppleNamespaces())) return DumpOffsets[DIDT_ID_DebugInfo] = *Offset; + // TODO: Add .debug_names support } return None; }();