Index: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -205,7 +205,7 @@ 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 @@ -246,16 +246,14 @@ /// length and form. The given offset is expected to be derived from the unit /// DIE's DW_AT_str_offsets_base attribute. Optional - 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 - determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA, - uint64_t Offset); + determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA); public: DWARFUnit(DWARFContext &Context, const DWARFSection &Section, @@ -267,7 +265,7 @@ 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; } Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -175,7 +175,7 @@ : 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 @@ -197,7 +197,7 @@ Optional 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 @@ -409,7 +409,7 @@ DWARFDie UnitDie = getUnitDIE(); if (Optional 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); @@ -426,27 +426,19 @@ // 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(), @@ -466,20 +458,20 @@ // 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; @@ -794,7 +786,7 @@ if (ValidationSize >= Size) if (DA.isValidOffsetForDataOfSize((uint32_t)Base, ValidationSize)) return *this; - return Optional(); + return None; } // Look for a DWARF64-formatted contribution to the string offsets table @@ -802,18 +794,17 @@ static Optional parseDWARF64StringOffsetsTableHeader(DWARFDataExtractor &DA, uint32_t Offset) { if (!DA.isValidOffsetForDataOfSize(Offset, 16)) - return Optional(); + return None; if (DA.getU32(&Offset) != 0xffffffff) - return Optional(); + 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(Descriptor); + return {{Offset, Size - 4, Version, DWARF64}}; } // Look for a DWARF32-formatted contribution to the string offsets table @@ -821,22 +812,20 @@ static Optional parseDWARF32StringOffsetsTableHeader(DWARFDataExtractor &DA, uint32_t Offset) { if (!DA.isValidOffsetForDataOfSize(Offset, 8)) - return Optional(); + return None; uint32_t ContributionSize = DA.getU32(&Offset); if (ContributionSize >= 0xfffffff0) - return Optional(); + 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(Descriptor); + return {{Offset, ContributionSize - 4, Version, DWARF32}}; } Optional -DWARFUnit::determineStringOffsetsTableContribution(DWARFDataExtractor &DA, - uint64_t Offset) { +DWARFUnit::determineStringOffsetsTableContribution(DWARFDataExtractor &DA) { + auto Offset = toSectionOffset(getUnitDIE().find(DW_AT_str_offsets_base), 0); Optional Descriptor; // Attempt to find a DWARF64 contribution 16 bytes before the base. if (Offset >= 16) @@ -849,8 +838,13 @@ } Optional -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 = @@ -862,15 +856,9 @@ // 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(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; }