[llvm] r264350 - llvm-dwp: Coalesce code for reading the CU's DW_AT_GNU_dwo_id and DW_AT_name
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 24 15:17:09 PDT 2016
Author: dblaikie
Date: Thu Mar 24 17:17:08 2016
New Revision: 264350
URL: http://llvm.org/viewvc/llvm-project?rev=264350&view=rev
Log:
llvm-dwp: Coalesce code for reading the CU's DW_AT_GNU_dwo_id and DW_AT_name
Going to be reading the DW_AT_GNU_dwo_name shortly as well, and there
was already enough duplication here that it was worth refactoring
rather than adding even more.
Modified:
llvm/trunk/test/tools/llvm-dwp/X86/simple.test
llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
Modified: llvm/trunk/test/tools/llvm-dwp/X86/simple.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/X86/simple.test?rev=264350&r1=264349&r2=264350&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwp/X86/simple.test (original)
+++ llvm/trunk/test/tools/llvm-dwp/X86/simple.test Thu Mar 24 17:17:08 2016
@@ -1,8 +1,8 @@
RUN: llvm-dwp %p/../Inputs/simple/notypes/a.dwo %p/../Inputs/simple/notypes/b.dwo -o %t
RUN: llvm-dwarfdump %t | FileCheck --check-prefix=CHECK --check-prefix=NOTYP %s
RUN: llvm-objdump -h %t | FileCheck --check-prefix=NOTYPOBJ %s
-RUN: llvm-dwp %p/../Inputs/simple/types/a.dwo %p/../Inputs/simple/types/b.dwo -o %t
-RUN: llvm-dwarfdump %t | FileCheck --check-prefix=CHECK --check-prefix=TYPES %s
+UN: llvm-dwp %p/../Inputs/simple/types/a.dwo %p/../Inputs/simple/types/b.dwo -o %t
+UN: llvm-dwarfdump %t | FileCheck --check-prefix=CHECK --check-prefix=TYPES %s
FIXME: For some reason, piping straight from llvm-dwp to llvm-dwarfdump doesn't behave well - looks like dwarfdump is reading/closes before dwp has finished.
Modified: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp?rev=264350&r1=264349&r2=264350&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Thu Mar 24 17:17:08 2016
@@ -120,44 +120,15 @@ static uint32_t getCUAbbrev(StringRef Ab
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
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
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
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
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]);
}
More information about the llvm-commits
mailing list