diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h @@ -58,7 +58,8 @@ /// iff it has successfully reched the end of the list. This means that one /// can attempt to parse another list after the current one (\p Offset will be /// updated to point past the end of the current list). - bool dumpLocationList(uint64_t *Offset, raw_ostream &OS, uint64_t BaseAddr, + bool dumpLocationList(uint64_t *Offset, raw_ostream &OS, + Optional BaseAddr, const MCRegisterInfo *MRI, DWARFUnit *U, DIDumpOptions DumpOpts, unsigned Indent) const; @@ -133,8 +134,7 @@ /// Dump all location lists within the given range. void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS, - uint64_t BaseAddr, const MCRegisterInfo *MRI, - DIDumpOptions DumpOpts); + const MCRegisterInfo *MRI, DIDumpOptions DumpOpts); protected: void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -306,14 +306,13 @@ if (DumpOffset) { if (DumpOffset >= Offset && DumpOffset < EndOffset) { Offset = *DumpOffset; - Loc.dumpLocationList(&Offset, OS, /*BaseAddr=*/0, MRI, nullptr, + Loc.dumpLocationList(&Offset, OS, /*BaseAddr=*/None, MRI, nullptr, DumpOpts, /*Indent=*/0); OS << "\n"; return; } } else { - Loc.dumpRange(Offset, EndOffset - Offset, OS, /*BaseAddr=*/0, MRI, - DumpOpts); + Loc.dumpRange(Offset, EndOffset - Offset, OS, MRI, DumpOpts); } Offset = EndOffset; } @@ -409,12 +408,11 @@ if (*Off) { uint64_t Offset = **Off; Loc.dumpLocationList(&Offset, OS, - /*BaseAddr=*/0, getRegisterInfo(), nullptr, DumpOpts, - /*Indent=*/0); + /*BaseAddr=*/None, getRegisterInfo(), nullptr, + DumpOpts, /*Indent=*/0); OS << "\n"; } else { - Loc.dumpRange(0, Data.getData().size(), OS, /*BaseAddr=*/0, - getRegisterInfo(), DumpOpts); + Loc.dumpRange(0, Data.getData().size(), OS, getRegisterInfo(), DumpOpts); } } diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp @@ -102,13 +102,12 @@ } bool DWARFLocationTable::dumpLocationList(uint64_t *Offset, raw_ostream &OS, - uint64_t BaseAddr, + Optional BaseAddr, const MCRegisterInfo *MRI, DWARFUnit *U, DIDumpOptions DumpOpts, unsigned Indent) const { DWARFLocationInterpreter Interp( - SectionedAddress{BaseAddr, SectionedAddress::UndefSection}, - [U](uint32_t Index) -> Optional { + BaseAddr, [U](uint32_t Index) -> Optional { if (U) return U->getAddrOffsetSectionItem(Index); return None; @@ -342,8 +341,7 @@ } void DWARFDebugLoclists::dumpRange(uint64_t StartOffset, uint64_t Size, - raw_ostream &OS, uint64_t BaseAddr, - const MCRegisterInfo *MRI, + raw_ostream &OS, const MCRegisterInfo *MRI, DIDumpOptions DumpOpts) { if (!Data.isValidOffsetForDataOfSize(StartOffset, Size)) { OS << "Invalid dump range\n"; @@ -356,7 +354,7 @@ OS << Separator; Separator = "\n"; - CanContinue = dumpLocationList(&Offset, OS, BaseAddr, MRI, nullptr, + CanContinue = dumpLocationList(&Offset, OS, /*BaseAddr=*/None, MRI, nullptr, DumpOpts, /*Indent=*/12); OS << '\n'; } diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -96,12 +96,10 @@ LLDumpOpts.Verbose = false; uint64_t Offset = *FormValue.getAsSectionOffset(); - uint64_t BaseAddr = 0; - if (Optional BA = U->getBaseAddress()) - BaseAddr = BA->Address; if (const DWARFLocationTable *LT = U->getLocationTable()) { - LT->dumpLocationList(&Offset, OS, BaseAddr, MRI, U, LLDumpOpts, Indent); + LT->dumpLocationList(&Offset, OS, U->getBaseAddress(), MRI, U, LLDumpOpts, + Indent); return; } @@ -114,6 +112,9 @@ if (Expected LL = DebugLoc.parseOneLocationList(Data, &Offset)) { + uint64_t BaseAddr = 0; + if (Optional BA = U->getBaseAddress()) + BaseAddr = BA->Address; LL->dump(OS, BaseAddr, Ctx.isLittleEndian(), Obj.getAddressSize(), MRI, U, LLDumpOpts, Indent); } else { diff --git a/llvm/test/DebugInfo/X86/dwarfdump-debug-loclists.test b/llvm/test/DebugInfo/X86/dwarfdump-debug-loclists.test --- a/llvm/test/DebugInfo/X86/dwarfdump-debug-loclists.test +++ b/llvm/test/DebugInfo/X86/dwarfdump-debug-loclists.test @@ -11,8 +11,7 @@ # CHECK: .debug_loclists contents: # CHECK-NEXT: 0x00000000: locations list header: length = 0x0000002c, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000 # CHECK-NEXT: 0x0000000c: -# CHECK-NEXT: DW_LLE_offset_pair (0x0000000000000000, 0x0000000000000010) -# CHECK-NEXT: => [0x0000000000000000, 0x0000000000000010): DW_OP_breg5 RDI+0 +# CHECK-NEXT: DW_LLE_offset_pair (0x0000000000000000, 0x0000000000000010): DW_OP_breg5 RDI+0 # CHECK-NEXT: DW_LLE_base_address (0x0000000000000500) # CHECK-NEXT: DW_LLE_offset_pair (0x0000000000000030, 0x0000000000000040) # CHECK-NEXT: => [0x0000000000000530, 0x0000000000000540): DW_OP_breg6 RBP-8, DW_OP_deref diff --git a/llvm/test/tools/llvm-dwarfdump/X86/debug_loclists.s b/llvm/test/tools/llvm-dwarfdump/X86/debug_loclists.s --- a/llvm/test/tools/llvm-dwarfdump/X86/debug_loclists.s +++ b/llvm/test/tools/llvm-dwarfdump/X86/debug_loclists.s @@ -70,6 +70,10 @@ .byte 23 # DW_FORM_sec_offset .ascii "\214\001" # DW_AT_loclists_base .byte 23 # DW_FORM_sec_offset + .byte 17 # DW_AT_low_pc + .byte 27 # DW_FORM_addrx + .byte 18 # DW_AT_high_pc + .byte 6 # DW_FORM_data4 .byte 0 # EOM(1) .byte 0 # EOM(2) .byte 2 # Abbreviation Code @@ -100,6 +104,8 @@ .byte 1 # Abbrev [1] 0xc:0x3c DW_TAG_compile_unit .long .Laddr_table_base0 # DW_AT_addr_base .long .Lloclists_table_base0 # DW_AT_loclists_base + .byte 0 # DW_AT_low_pc + .long .Lfend-.Lf0 # DW_AT_high_pc .byte 2 # Abbrev [2] 0x27:0x1c DW_TAG_subprogram .byte 0 # DW_AT_low_pc .long .Lfend-.Lf0 # DW_AT_high_pc diff --git a/llvm/test/tools/llvm-dwarfdump/X86/debug_loclists_multiple.s b/llvm/test/tools/llvm-dwarfdump/X86/debug_loclists_multiple.s --- a/llvm/test/tools/llvm-dwarfdump/X86/debug_loclists_multiple.s +++ b/llvm/test/tools/llvm-dwarfdump/X86/debug_loclists_multiple.s @@ -5,9 +5,9 @@ # CHECK: .debug_loclists contents: # CHECK: 0x00000000: locations list header: # CHECK: 0x0000000c: -# CHECK: [0x0000000000000001, 0x0000000000000002): DW_OP_consts +7, DW_OP_stack_value +# CHECK: DW_LLE_offset_pair (0x0000000000000001, 0x0000000000000002): DW_OP_consts +7, DW_OP_stack_value # CHECK: 0x00000014: locations list header: -# CHECK: [0x0000000000000005, 0x0000000000000007): DW_OP_consts +12, DW_OP_stack_value +# CHECK: DW_LLE_offset_pair (0x0000000000000005, 0x0000000000000007): DW_OP_consts +12, DW_OP_stack_value .section .debug_loclists,"",@progbits .long .Ldebug_loclist_table_end0-.Ldebug_loclist_table_start0 # Length