diff options
Diffstat (limited to 'llvm/tools/llvm-dwp/llvm-dwp.cpp')
-rw-r--r-- | llvm/tools/llvm-dwp/llvm-dwp.cpp | 87 |
1 files changed, 36 insertions, 51 deletions
diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp index 1c248d9f21c..70bad7565be 100644 --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -120,44 +120,15 @@ static uint32_t getCUAbbrev(StringRef Abbrev, uint64_t AbbrCode) { return Offset; } -static const char *getCUName(StringRef Abbrev, StringRef Info, - StringRef StrOffsets, StringRef Str) { - uint32_t Offset = 0; - DataExtractor InfoData(Info, true, 0); - InfoData.getU32(&Offset); // Length - uint16_t Version = InfoData.getU16(&Offset); - InfoData.getU32(&Offset); // Abbrev offset (should be zero) - uint8_t AddrSize = InfoData.getU8(&Offset); - - uint32_t AbbrCode = InfoData.getULEB128(&Offset); - - DataExtractor AbbrevData(Abbrev, true, 0); - uint32_t AbbrevOffset = getCUAbbrev(Abbrev, AbbrCode); - uint64_t Tag = AbbrevData.getULEB128(&AbbrevOffset); - (void)Tag; - // FIXME: Real error handling - assert(Tag == dwarf::DW_TAG_compile_unit); - // DW_CHILDREN - AbbrevData.getU8(&AbbrevOffset); - uint32_t Name; - uint32_t Form; - while ((Name = AbbrevData.getULEB128(&AbbrevOffset)) | - (Form = AbbrevData.getULEB128(&AbbrevOffset)) && - Name != dwarf::DW_AT_name) { - DWARFFormValue::skipValue(Form, InfoData, &Offset, Version, AddrSize); - } - // FIXME: Real error handling - assert(Name == dwarf::DW_AT_name); - auto StrIndex = InfoData.getULEB128(&Offset); - - DataExtractor StrOffsetsData(StrOffsets, true, 0); - uint32_t StrOffsetsOffset = 4 * StrIndex; - uint32_t StrOffset = StrOffsetsData.getU32(&StrOffsetsOffset); - DataExtractor StrData(Str, true, 0); - return StrData.getCStr(&StrOffset); -} +struct CompileUnitIdentifiers { + uint64_t Signature = 0; + const char *Name = nullptr; + const char *DWOName = nullptr; +}; -static uint64_t getCUSignature(StringRef Abbrev, StringRef Info) { +static CompileUnitIdentifiers getCUIdentifiers(StringRef Abbrev, StringRef Info, + StringRef StrOffsets, + StringRef Str) { uint32_t Offset = 0; DataExtractor InfoData(Info, true, 0); InfoData.getU32(&Offset); // Length @@ -177,14 +148,29 @@ static uint64_t getCUSignature(StringRef Abbrev, StringRef Info) { AbbrevData.getU8(&AbbrevOffset); uint32_t Name; uint32_t Form; + CompileUnitIdentifiers ID; while ((Name = AbbrevData.getULEB128(&AbbrevOffset)) | (Form = AbbrevData.getULEB128(&AbbrevOffset)) && - Name != dwarf::DW_AT_GNU_dwo_id) { - DWARFFormValue::skipValue(Form, InfoData, &Offset, Version, AddrSize); + (Name != 0 || Form != 0)) { + switch (Name) { + case dwarf::DW_AT_name: { + auto StrIndex = InfoData.getULEB128(&Offset); + + DataExtractor StrOffsetsData(StrOffsets, true, 0); + uint32_t StrOffsetsOffset = 4 * StrIndex; + uint32_t StrOffset = StrOffsetsData.getU32(&StrOffsetsOffset); + DataExtractor StrData(Str, true, 0); + ID.Name = StrData.getCStr(&StrOffset); + break; + } + case dwarf::DW_AT_GNU_dwo_id: + ID.Signature = InfoData.getU64(&Offset); + break; + default: + DWARFFormValue::skipValue(Form, InfoData, &Offset, Version, AddrSize); + } } - // FIXME: Real error handling - assert(Name == dwarf::DW_AT_GNU_dwo_id); - return InfoData.getU64(&Offset); + return ID; } struct UnitIndexEntry { @@ -476,7 +462,7 @@ static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) { continue; auto P = IndexEntries.insert(std::make_pair(E.getSignature(), CurEntry)); - const char* Name = getCUName( + CompileUnitIdentifiers ID = getCUIdentifiers( getSubsection(AbbrevSection, E, DW_SECT_ABBREV), getSubsection(InfoSection, E, DW_SECT_INFO), getSubsection(CurStrOffsetSection, E, DW_SECT_STR_OFFSETS), @@ -486,11 +472,11 @@ static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) { std::cerr << "Duplicate DWO ID (" << PrevE.first << ") in '" << PrevE.second.Name << "' "; if (!PrevE.second.DWPName.empty()) std::cerr << "(from '" << PrevE.second.DWPName.str() << "') "; - std::cerr << "and '" << Name << "' (from '" << Input << "')\n"; + std::cerr << "and '" << ID.Name << "' (from '" << Input << "')\n"; return make_error_code(std::errc::invalid_argument); } auto &NewEntry = P.first->second; - NewEntry.Name = Name; + NewEntry.Name = ID.Name; NewEntry.DWPName = Input; for (auto Kind : CUIndex.getColumnKinds()) { auto &C = NewEntry.Contributions[Kind - DW_SECT_INFO]; @@ -513,20 +499,19 @@ static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) { ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]); } } else { - auto P = IndexEntries.insert( - std::make_pair(getCUSignature(AbbrevSection, InfoSection), CurEntry)); - const char *Name = getCUName(AbbrevSection, InfoSection, - CurStrOffsetSection, CurStrSection); + CompileUnitIdentifiers ID = getCUIdentifiers( + AbbrevSection, InfoSection, CurStrOffsetSection, CurStrSection); + auto P = IndexEntries.insert(std::make_pair(ID.Signature, CurEntry)); if (!P.second) { auto &E = *P.first; - std::cerr << "Duplicate DWO ID (" << E.first << ") in '" << Name + std::cerr << "Duplicate DWO ID (" << E.first << ") in '" << ID.Name << "' "; if (!E.second.DWPName.empty()) std::cerr << "(from '" << E.second.DWPName.str() << "') "; std::cerr << "and '" << E.second.Name << "'\n"; return make_error_code(std::errc::invalid_argument); } - P.first->second.Name = Name; + P.first->second.Name = ID.Name; addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection, CurEntry, ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]); } |