mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-05 02:07:56 +00:00
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. llvm-svn: 264350
This commit is contained in:
parent
3edddc591b
commit
0feb27005d
@ -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.
|
||||
|
||||
|
@ -120,8 +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) {
|
||||
struct CompileUnitIdentifiers {
|
||||
uint64_t Signature = 0;
|
||||
const char *Name = nullptr;
|
||||
const char *DWOName = nullptr;
|
||||
};
|
||||
|
||||
static CompileUnitIdentifiers getCUIdentifiers(StringRef Abbrev, StringRef Info,
|
||||
StringRef StrOffsets,
|
||||
StringRef Str) {
|
||||
uint32_t Offset = 0;
|
||||
DataExtractor InfoData(Info, true, 0);
|
||||
InfoData.getU32(&Offset); // Length
|
||||
@ -141,50 +148,29 @@ static const char *getCUName(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_name) {
|
||||
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_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);
|
||||
}
|
||||
|
||||
static uint64_t getCUSignature(StringRef Abbrev, StringRef Info) {
|
||||
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_GNU_dwo_id) {
|
||||
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]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user