--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -486,12 +486,11 @@ void DWARFUnit::SetLoclistsBase(dw_addr_t loclists_base) { std::unique_ptr DWARFUnit::GetLocationTable(const DataExtractor &data) const { llvm::DWARFDataExtractor llvm_data( - data.GetData(), data.GetByteOrder() == lldb::eByteOrderLittle, - data.GetAddressByteSize()); + data.GetData(), data.GetByteOrder() == lldb::eByteOrderLittle); if (m_is_dwo || GetVersion() >= 5) - return std::make_unique(llvm_data, GetVersion()); - return std::make_unique(llvm_data); + return std::make_unique(llvm_data, GetVersion(), data.GetAddressByteSize()); + return std::make_unique(llvm_data, data.GetAddressByteSize()); } DWARFDataExtractor DWARFUnit::GetLocationData() const { --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h @@ -26,15 +26,15 @@ public: /// Constructor for the normal case of extracting data from a DWARF section. /// The DWARFSection's lifetime must be at least as long as the extractor's. DWARFDataExtractor(const DWARFObject &Obj, const DWARFSection &Section, - bool IsLittleEndian, uint8_t AddressSize) + bool IsLittleEndian, uint8_t AddressSize = 0) : DataExtractor(Section.Data, IsLittleEndian, AddressSize), Obj(&Obj), Section(&Section) {} /// Constructor for cases when there are no relocations. - DWARFDataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize) + DWARFDataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize = 0) : DataExtractor(Data, IsLittleEndian, AddressSize) {} DWARFDataExtractor(ArrayRef Data, bool IsLittleEndian, - uint8_t AddressSize) + uint8_t AddressSize = 0) : DataExtractor( StringRef(reinterpret_cast(Data.data()), Data.size()), IsLittleEndian, AddressSize) {} --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h @@ -45,7 +45,7 @@ struct DWARFLocationEntry { /// .debug_loclists, and their dwo variants). class DWARFLocationTable { public: - DWARFLocationTable(DWARFDataExtractor Data) : Data(std::move(Data)) {} + DWARFLocationTable(DWARFDataExtractor Data, uint8_t AddressSize); virtual ~DWARFLocationTable() = default; /// Call the user-provided callback for each entry (including the end-of-list @@ -101,8 +101,8 @@ private: LocationLists Locations; public: - DWARFDebugLoc(DWARFDataExtractor Data) - : DWARFLocationTable(std::move(Data)) {} + DWARFDebugLoc(DWARFDataExtractor Data, uint8_t AddressSize) + : DWARFLocationTable(std::move(Data), AddressSize) {} /// Print the location lists found within the debug_loc section. void dump(raw_ostream &OS, const MCRegisterInfo *RegInfo, @@ -121,8 +121,8 @@ protected: class DWARFDebugLoclists final : public DWARFLocationTable { public: - DWARFDebugLoclists(DWARFDataExtractor Data, uint16_t Version) - : DWARFLocationTable(std::move(Data)), Version(Version) {} + DWARFDebugLoclists(DWARFDataExtractor Data, uint16_t Version, uint8_t AddressSize) + : DWARFLocationTable(std::move(Data), AddressSize), Version(Version) {} Error visitLocationList( uint64_t *Offset, --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -319,8 +319,7 @@ static void dumpLoclistsSection(raw_ostream &OS, DIDumpOptions DumpOpts, Header.dump(Data, OS, DumpOpts); uint64_t EndOffset = Header.length() + Header.getHeaderOffset(); - Data.setAddressSize(Header.getAddrSize()); - DWARFDebugLoclists Loc(Data, Header.getVersion()); + DWARFDebugLoclists Loc(Data, Header.getVersion(), Header.getAddrSize()); if (DumpOffset) { if (DumpOffset >= Offset && DumpOffset < EndOffset) { Offset = *DumpOffset; @@ -438,9 +437,8 @@ void DWARFContext::dump( if (const auto *Off = shouldDump(ExplicitDWO, ".debug_loc.dwo", DIDT_ID_DebugLoc, DObj->getLocDWOSection().Data)) { - DWARFDataExtractor Data(*DObj, DObj->getLocDWOSection(), isLittleEndian(), - 4); - DWARFDebugLoclists Loc(Data, /*Version=*/4); + DWARFDataExtractor Data(*DObj, DObj->getLocDWOSection(), isLittleEndian()); + DWARFDebugLoclists Loc(Data, /*Version=*/4, /*AddressSize=*/4); if (*Off) { uint64_t Offset = **Off; Loc.dumpLocationList(&Offset, OS, @@ -803,10 +801,11 @@ const DWARFDebugLoc *DWARFContext::getDebugLoc() { // Assume all units have the same address byte size. auto LocData = getNumCompileUnits() - ? DWARFDataExtractor(*DObj, DObj->getLocSection(), isLittleEndian(), - getUnitAtIndex(0)->getAddressByteSize()) - : DWARFDataExtractor("", isLittleEndian(), 0); - Loc.reset(new DWARFDebugLoc(std::move(LocData))); + ? DWARFDataExtractor(*DObj, DObj->getLocSection(), isLittleEndian()) + : DWARFDataExtractor("", isLittleEndian()); + uint8_t AddressSize = + getNumCompileUnits() ? getUnitAtIndex(0)->getAddressByteSize() : 0; + Loc.reset(new DWARFDebugLoc(std::move(LocData), AddressSize)); return Loc.get(); } --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp @@ -40,6 +40,10 @@ public: }; } // namespace +DWARFLocationTable::DWARFLocationTable(DWARFDataExtractor Data_, uint8_t AddressSize) : Data(std::move(Data_)) { + Data.setAddressSize(AddressSize); +} + static Error createResolverError(uint32_t Index, unsigned Kind) { return createStringError(errc::invalid_argument, "Unable to resolve indirect address %u for: %s", --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -535,20 +535,20 @@ Error DWARFUnit::tryExtractDIEsIfNeeded(bool CUDieOnly) { Header.getVersion() >= 5 ? DW_SECT_LOCLISTS : DW_SECT_EXT_LOC)) Data = Data.substr(C->Offset, C->Length); - DWARFDataExtractor DWARFData(Data, isLittleEndian, getAddressByteSize()); + DWARFDataExtractor DWARFData(Data, isLittleEndian); LocTable = - std::make_unique(DWARFData, Header.getVersion()); + std::make_unique(DWARFData, Header.getVersion(), getAddressByteSize()); LocSectionBase = DWARFListTableHeader::getHeaderSize(Header.getFormat()); } else if (getVersion() >= 5) { LocTable = std::make_unique( DWARFDataExtractor(Context.getDWARFObj(), Context.getDWARFObj().getLoclistsSection(), - isLittleEndian, getAddressByteSize()), - getVersion()); + isLittleEndian), + getVersion(), getAddressByteSize()); } else { LocTable = std::make_unique(DWARFDataExtractor( Context.getDWARFObj(), Context.getDWARFObj().getLocSection(), - isLittleEndian, getAddressByteSize())); + isLittleEndian), getAddressByteSize()); } // Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for --- a/llvm/unittests/DebugInfo/DWARF/DWARFListTableTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFListTableTest.cpp @@ -18,8 +18,7 @@ namespace { TEST(DWARFListTableHeader, TruncatedLength) { static const char SecData[] = "\x33\x22\x11"; // Truncated DWARF32 length DWARFDataExtractor Extractor(StringRef(SecData, sizeof(SecData) - 1), - /*isLittleEndian=*/true, - /*AddrSize=*/4); + /*isLittleEndian=*/true); DWARFListTableHeader Header(/*SectionName=*/".debug_rnglists", /*ListTypeString=*/"range"); uint64_t Offset = 0; @@ -39,8 +38,7 @@ TEST(DWARFListTableHeader, TruncatedLengthDWARF64) { "\xff\xff\xff\xff" // DWARF64 mark "\x55\x44\x33\x22\x11"; // Truncated DWARF64 length DWARFDataExtractor Extractor(StringRef(SecData, sizeof(SecData) - 1), - /*isLittleEndian=*/true, - /*AddrSize=*/4); + /*isLittleEndian=*/true); DWARFListTableHeader Header(/*SectionName=*/".debug_rnglists", /*ListTypeString=*/"range"); uint64_t Offset = 0; @@ -59,8 +57,7 @@ TEST(DWARFListTableHeader, TruncatedHeader) { static const char SecData[] = "\x02\x00\x00\x00" // Length "\x05\x00"; // Version DWARFDataExtractor Extractor(StringRef(SecData, sizeof(SecData) - 1), - /*isLittleEndian=*/true, - /*AddrSize=*/4); + /*isLittleEndian=*/true); DWARFListTableHeader Header(/*SectionName=*/".debug_rnglists", /*ListTypeString=*/"range"); uint64_t Offset = 0; @@ -86,8 +83,7 @@ TEST(DWARFListTableHeader, OffsetEntryCount) { "\x02" // ULEB128 ending offset "\x00"; // DW_RLE_end_of_list DWARFDataExtractor Extractor(StringRef(SecData, sizeof(SecData) - 1), - /*isLittleEndian=*/true, - /*AddrSize=*/4); + /*isLittleEndian=*/true); DWARFListTableHeader Header(/*SectionName=*/".debug_rnglists", /*ListTypeString=*/"range"); uint64_t Offset = 0; @@ -113,8 +109,7 @@ TEST(DWARFListTableHeader, AddressSize64) { "\x83\x82\x81\x80" // 64-bit ending address "\x00"; // DW_RLE_end_of_list DWARFDataExtractor Extractor(StringRef(SecData, sizeof(SecData) - 1), - /*isLittleEndian=*/true, - /*AddrSize=*/4); + /*isLittleEndian=*/true); DWARFListTableHeader Header(/*SectionName=*/".debug_rnglists", /*ListTypeString=*/"range"); uint64_t Offset = 0; @@ -123,7 +118,7 @@ TEST(DWARFListTableHeader, AddressSize64) { EXPECT_FALSE(!!E); EXPECT_EQ(Offset, 12U); EXPECT_EQ(Table.length(), sizeof(SecData) - 1); - EXPECT_EQ(Extractor.getAddressSize(), 4U); + EXPECT_EQ(Extractor.getAddressSize(), 0U); EXPECT_EQ(Table.getAddrSize(), 8U); Expected List = Table.findList(Extractor, Offset); EXPECT_TRUE(!!List); @@ -147,8 +142,7 @@ TEST(DWARFListTableHeader, AddressSize32) { "\x83\x82\x81\x80" // 32-bit ending address "\x00"; // DW_RLE_end_of_list DWARFDataExtractor Extractor(StringRef(SecData, sizeof(SecData) - 1), - /*isLittleEndian=*/true, - /*AddrSize=*/8); + /*isLittleEndian=*/true); DWARFListTableHeader Header(/*SectionName=*/".debug_rnglists", /*ListTypeString=*/"range"); uint64_t Offset = 0; @@ -157,7 +151,7 @@ TEST(DWARFListTableHeader, AddressSize32) { EXPECT_FALSE(!!E); EXPECT_EQ(Offset, 12U); EXPECT_EQ(Table.length(), sizeof(SecData) - 1); - EXPECT_EQ(Extractor.getAddressSize(), 8U); + EXPECT_EQ(Extractor.getAddressSize(), 0U); EXPECT_EQ(Table.getAddrSize(), 4U); Expected List = Table.findList(Extractor, Offset); EXPECT_TRUE(!!List);