Index: include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h +++ include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h @@ -126,16 +126,16 @@ bool IsLittleEndian; public: - void parse(DataExtractor data, unsigned Version); + void parse(const DWARFDataExtractor &data, unsigned Version); void dump(raw_ostream &OS, uint64_t BaseAddr, const MCRegisterInfo *RegInfo, Optional Offset) const; /// Return the location list at the given offset or nullptr. LocationList const *getLocationListAtOffset(uint64_t Offset) const; - static Expected parseOneLocationList(const DataExtractor &Data, - uint64_t *Offset, - unsigned Version); + static Expected + parseOneLocationList(const DWARFDataExtractor &Data, uint64_t *Offset, + unsigned Version); }; } // end namespace llvm Index: lib/DebugInfo/DWARF/DWARFContext.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFContext.cpp +++ lib/DebugInfo/DWARF/DWARFContext.cpp @@ -299,10 +299,7 @@ } Header.dump(OS, DumpOpts); - DataExtractor LocData(Data.getData().drop_front(Offset), - Data.isLittleEndian(), Header.getAddrSize()); - - Loclists.parse(LocData, Header.getVersion()); + Loclists.parse(Data, Header.getVersion()); Loclists.dump(OS, 0, MRI, DumpOffset); } @@ -729,7 +726,8 @@ // Assume all compile units have the same address byte size. // FIXME: We don't need AddressSize for split DWARF since relocatable // addresses cannot appear there. At the moment DWARFExpression requires it. - DataExtractor LocData(DObj->getLocDWOSection().Data, isLittleEndian(), 4); + DWARFDataExtractor LocData(*DObj, DObj->getLocDWOSection(), isLittleEndian(), + 4); // Use version 4. DWO does not support the DWARF v5 .debug_loclists yet and // that means we are parsing the new style .debug_loc (pre-standatized version // of the .debug_loclists). Index: lib/DebugInfo/DWARF/DWARFDebugLoc.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFDebugLoc.cpp +++ lib/DebugInfo/DWARF/DWARFDebugLoc.cpp @@ -134,7 +134,7 @@ } Expected -DWARFDebugLoclists::parseOneLocationList(const DataExtractor &Data, +DWARFDebugLoclists::parseOneLocationList(const DWARFDataExtractor &Data, uint64_t *Offset, unsigned Version) { LocationList LL; LL.Offset = *Offset; @@ -155,8 +155,7 @@ E.Value1 = Data.getULEB128(C); break; case dwarf::DW_LLE_start_length: - // TODO: Read this as a relocated address. - E.Value0 = Data.getAddress(C); + E.Value0 = Data.getRelocatedAddress(C); E.Value1 = Data.getULEB128(C); break; case dwarf::DW_LLE_offset_pair: @@ -164,7 +163,7 @@ E.Value1 = Data.getULEB128(C); break; case dwarf::DW_LLE_base_address: - E.Value0 = Data.getAddress(C); + E.Value0 = Data.getRelocatedAddress(C); break; default: cantFail(C.takeError()); @@ -186,7 +185,8 @@ return LL; } -void DWARFDebugLoclists::parse(DataExtractor data, unsigned Version) { +void DWARFDebugLoclists::parse(const DWARFDataExtractor &data, + unsigned Version) { IsLittleEndian = data.isLittleEndian(); AddressSize = data.getAddressSize(); Index: lib/DebugInfo/DWARF/DWARFDie.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFDie.cpp +++ lib/DebugInfo/DWARF/DWARFDie.cpp @@ -117,13 +117,15 @@ } bool UseLocLists = !U->isDWOUnit(); - StringRef LoclistsSectionData = - UseLocLists ? Obj.getLoclistsSection().Data : U->getLocSectionData(); - - if (!LoclistsSectionData.empty()) { - DataExtractor Data(LoclistsSectionData, Ctx.isLittleEndian(), - Obj.getAddressSize()); - + auto Data = [&] { + if (UseLocLists) + return DWARFDataExtractor(Obj, Obj.getLoclistsSection(), + Ctx.isLittleEndian(), Obj.getAddressSize()); + return DWARFDataExtractor(U->getLocSectionData(), Ctx.isLittleEndian(), + Obj.getAddressSize()); + }(); + + if (!Data.getData().empty()) { // Old-style location list were used in DWARF v4 (.debug_loc.dwo section). // Modern locations list (.debug_loclists) are used starting from v5. // Ideally we should take the version from the .debug_loclists section Index: test/tools/llvm-dwarfdump/X86/debug_loclists.s =================================================================== --- test/tools/llvm-dwarfdump/X86/debug_loclists.s +++ test/tools/llvm-dwarfdump/X86/debug_loclists.s @@ -43,14 +43,12 @@ .byte 1 # Loc expr size .byte 81 # super-register DW_OP_reg1 .byte 8 # DW_LLE_start_length - # TODO: Make it possible to use .Lf2 here. - .quad 2 # starting offset + .quad .Lf2 # starting offset .uleb128 .Lf3-.Lf2 # length .byte 1 # Loc expr size .byte 82 # super-register DW_OP_reg2 .byte 6 # DW_LLE_base_address - # TODO: Make it possible to use .Lf3 here. - .quad 3 # base address + .quad .Lf3 # base address .byte 4 # DW_LLE_offset_pair .uleb128 .Lf3-.Lf3 # starting offset .uleb128 .Lf4-.Lf3 # ending offset