Skip to content

Commit

Permalink
llvm-dwp: Coalesce code for reading the CU's DW_AT_GNU_dwo_id and DW_…
Browse files Browse the repository at this point in the history
…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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264350 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dwblaikie committed Mar 24, 2016
1 parent b5f62ce commit dfb4013
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 53 deletions.
4 changes: 2 additions & 2 deletions test/tools/llvm-dwp/X86/simple.test
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
87 changes: 36 additions & 51 deletions tools/llvm-dwp/llvm-dwp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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),
Expand All @@ -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];
Expand All @@ -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]);
}
Expand Down

0 comments on commit dfb4013

Please sign in to comment.