Skip to content

Commit

Permalink
[DWARF][NFC] cleanup (mostly leftovers from the implementation of str…
Browse files Browse the repository at this point in the history
…ing offsets tables)

Majority of the patch by David Blaikie.

Differential Revision: https://reviews.llvm.org/D53741

llvm-svn: 345404
  • Loading branch information
wolfy1961 committed Oct 26, 2018
1 parent 43245b1 commit d57b525
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 49 deletions.
10 changes: 4 additions & 6 deletions llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
Expand Up @@ -205,7 +205,7 @@ class DWARFUnit {
const DWARFSection *AddrOffsetSection;
uint32_t AddrOffsetSectionBase = 0;
bool isLittleEndian;
bool isDWO;
bool IsDWO;
const DWARFUnitVector &UnitVector;

/// Start, length, and DWARF format of the unit's contribution to the string
Expand Down Expand Up @@ -246,16 +246,14 @@ class DWARFUnit {
/// length and form. The given offset is expected to be derived from the unit
/// DIE's DW_AT_str_offsets_base attribute.
Optional<StrOffsetsContributionDescriptor>
determineStringOffsetsTableContribution(DWARFDataExtractor &DA,
uint64_t Offset);
determineStringOffsetsTableContribution(DWARFDataExtractor &DA);

/// Find the unit's contribution to the string offsets table and determine its
/// length and form. The given offset is expected to be 0 in a dwo file or,
/// in a dwp file, the start of the unit's contribution to the string offsets
/// table section (as determined by the index table).
Optional<StrOffsetsContributionDescriptor>
determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA,
uint64_t Offset);
determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA);

public:
DWARFUnit(DWARFContext &Context, const DWARFSection &Section,
Expand All @@ -267,7 +265,7 @@ class DWARFUnit {

virtual ~DWARFUnit();

bool isDWOUnit() const { return isDWO; }
bool isDWOUnit() const { return IsDWO; }
DWARFContext& getContext() const { return Context; }
const DWARFSection &getInfoSection() const { return InfoSection; }
const DWARFSection *getLocSection() const { return LocSection; }
Expand Down
74 changes: 31 additions & 43 deletions llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
Expand Up @@ -175,7 +175,7 @@ DWARFUnit::DWARFUnit(DWARFContext &DC, const DWARFSection &Section,
: Context(DC), InfoSection(Section), Header(Header), Abbrev(DA),
RangeSection(RS), LocSection(LocSection), LineSection(LS),
StringSection(SS), StringOffsetSection(SOS), AddrOffsetSection(AOS),
isLittleEndian(LE), isDWO(IsDWO), UnitVector(UnitVector) {
isLittleEndian(LE), IsDWO(IsDWO), UnitVector(UnitVector) {
clear();
// For split DWARF we only need to keep track of the location list section's
// data (no relocations), and if we are reading a package file, we need to
Expand All @@ -197,7 +197,7 @@ DWARFDataExtractor DWARFUnit::getDebugInfoExtractor() const {

Optional<SectionedAddress>
DWARFUnit::getAddrOffsetSectionItem(uint32_t Index) const {
if (isDWO) {
if (IsDWO) {
auto R = Context.info_section_units();
auto I = R.begin();
// Surprising if a DWO file has more than one skeleton unit in it - this
Expand Down Expand Up @@ -409,7 +409,7 @@ size_t DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) {
DWARFDie UnitDie = getUnitDIE();
if (Optional<uint64_t> DWOId = toUnsigned(UnitDie.find(DW_AT_GNU_dwo_id)))
Header.setDWOId(*DWOId);
if (!isDWO) {
if (!IsDWO) {
assert(AddrOffsetSectionBase == 0);
assert(RangeSectionBase == 0);
AddrOffsetSectionBase = toSectionOffset(UnitDie.find(DW_AT_addr_base), 0);
Expand All @@ -426,27 +426,19 @@ size_t DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) {
// offsets table starting at offset 0 of the debug_str_offsets.dwo section.
// In both cases we need to determine the format of the contribution,
// which may differ from the unit's format.
uint64_t StringOffsetsContributionBase =
isDWO ? 0 : toSectionOffset(UnitDie.find(DW_AT_str_offsets_base), 0);
auto IndexEntry = Header.getIndexEntry();
if (IndexEntry)
if (const auto *C = IndexEntry->getOffset(DW_SECT_STR_OFFSETS))
StringOffsetsContributionBase += C->Offset;

DWARFDataExtractor DA(Context.getDWARFObj(), StringOffsetSection,
isLittleEndian, 0);
if (isDWO)
if (IsDWO)
StringOffsetsTableContribution =
determineStringOffsetsTableContributionDWO(
DA, StringOffsetsContributionBase);
determineStringOffsetsTableContributionDWO(DA);
else if (getVersion() >= 5)
StringOffsetsTableContribution = determineStringOffsetsTableContribution(
DA, StringOffsetsContributionBase);
StringOffsetsTableContribution =
determineStringOffsetsTableContribution(DA);

// DWARF v5 uses the .debug_rnglists and .debug_rnglists.dwo sections to
// describe address ranges.
if (getVersion() >= 5) {
if (isDWO)
if (IsDWO)
setRangesSection(&Context.getDWARFObj().getRnglistsDWOSection(), 0);
else
setRangesSection(&Context.getDWARFObj().getRnglistsSection(),
Expand All @@ -466,20 +458,20 @@ size_t DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) {

// In a split dwarf unit, there is no DW_AT_rnglists_base attribute.
// Adjust RangeSectionBase to point past the table header.
if (isDWO && RngListTable)
if (IsDWO && RngListTable)
RangeSectionBase = RngListTable->getHeaderSize();
}
}

// Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for
// skeleton CU DIE, so that DWARF users not aware of it are not broken.
}
}

return DieArray.size();
}

bool DWARFUnit::parseDWO() {
if (isDWO)
if (IsDWO)
return false;
if (DWO.get())
return false;
Expand Down Expand Up @@ -794,49 +786,46 @@ StrOffsetsContributionDescriptor::validateContributionSize(
if (ValidationSize >= Size)
if (DA.isValidOffsetForDataOfSize((uint32_t)Base, ValidationSize))
return *this;
return Optional<StrOffsetsContributionDescriptor>();
return None;
}

// Look for a DWARF64-formatted contribution to the string offsets table
// starting at a given offset and record it in a descriptor.
static Optional<StrOffsetsContributionDescriptor>
parseDWARF64StringOffsetsTableHeader(DWARFDataExtractor &DA, uint32_t Offset) {
if (!DA.isValidOffsetForDataOfSize(Offset, 16))
return Optional<StrOffsetsContributionDescriptor>();
return None;

if (DA.getU32(&Offset) != 0xffffffff)
return Optional<StrOffsetsContributionDescriptor>();
return None;

uint64_t Size = DA.getU64(&Offset);
uint8_t Version = DA.getU16(&Offset);
(void)DA.getU16(&Offset); // padding
// The encoded length includes the 2-byte version field and the 2-byte
// padding, so we need to subtract them out when we populate the descriptor.
return StrOffsetsContributionDescriptor(Offset, Size - 4, Version, DWARF64);
//return Optional<StrOffsetsContributionDescriptor>(Descriptor);
return {{Offset, Size - 4, Version, DWARF64}};
}

// Look for a DWARF32-formatted contribution to the string offsets table
// starting at a given offset and record it in a descriptor.
static Optional<StrOffsetsContributionDescriptor>
parseDWARF32StringOffsetsTableHeader(DWARFDataExtractor &DA, uint32_t Offset) {
if (!DA.isValidOffsetForDataOfSize(Offset, 8))
return Optional<StrOffsetsContributionDescriptor>();
return None;
uint32_t ContributionSize = DA.getU32(&Offset);
if (ContributionSize >= 0xfffffff0)
return Optional<StrOffsetsContributionDescriptor>();
return None;
uint8_t Version = DA.getU16(&Offset);
(void)DA.getU16(&Offset); // padding
// The encoded length includes the 2-byte version field and the 2-byte
// padding, so we need to subtract them out when we populate the descriptor.
return StrOffsetsContributionDescriptor(Offset, ContributionSize - 4, Version,
DWARF32);
//return Optional<StrOffsetsContributionDescriptor>(Descriptor);
return {{Offset, ContributionSize - 4, Version, DWARF32}};
}

Optional<StrOffsetsContributionDescriptor>
DWARFUnit::determineStringOffsetsTableContribution(DWARFDataExtractor &DA,
uint64_t Offset) {
DWARFUnit::determineStringOffsetsTableContribution(DWARFDataExtractor &DA) {
auto Offset = toSectionOffset(getUnitDIE().find(DW_AT_str_offsets_base), 0);
Optional<StrOffsetsContributionDescriptor> Descriptor;
// Attempt to find a DWARF64 contribution 16 bytes before the base.
if (Offset >= 16)
Expand All @@ -849,8 +838,13 @@ DWARFUnit::determineStringOffsetsTableContribution(DWARFDataExtractor &DA,
}

Optional<StrOffsetsContributionDescriptor>
DWARFUnit::determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA,
uint64_t Offset) {
DWARFUnit::determineStringOffsetsTableContributionDWO(DWARFDataExtractor & DA) {
uint64_t Offset = 0;
auto IndexEntry = Header.getIndexEntry();
const auto *C =
IndexEntry ? IndexEntry->getOffset(DW_SECT_STR_OFFSETS) : nullptr;
if (C)
Offset = C->Offset;
if (getVersion() >= 5) {
// Look for a valid contribution at the given offset.
auto Descriptor =
Expand All @@ -862,15 +856,9 @@ DWARFUnit::determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA,
// Prior to DWARF v5, we derive the contribution size from the
// index table (in a package file). In a .dwo file it is simply
// the length of the string offsets section.
uint64_t Size = 0;
auto IndexEntry = Header.getIndexEntry();
if (!IndexEntry)
Size = StringOffsetSection.Data.size();
else if (const auto *C = IndexEntry->getOffset(DW_SECT_STR_OFFSETS))
Size = C->Length;
// Return a descriptor with the given offset as base, version 4 and
// DWARF32 format.
//return Optional<StrOffsetsContributionDescriptor>(
//StrOffsetsContributionDescriptor(Offset, Size, 4, DWARF32));
return StrOffsetsContributionDescriptor(Offset, Size, 4, DWARF32);
return {{0, StringOffsetSection.Data.size(), 4, DWARF32}};
if (C)
return {{C->Offset, C->Length, 4, DWARF32}};
return None;
}

0 comments on commit d57b525

Please sign in to comment.