diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1039,7 +1039,10 @@ std::vector> sequences; // The Sequences view contains only valid line sequences. Don't iterate over // the Rows directly. + SectionList &list = *GetObjectFile()->GetModule()->GetSectionList(); for (const llvm::DWARFDebugLine::Sequence &seq : line_table->Sequences) { + if (!list.ContainsFileAddressRange(seq.LowPC, seq.HighPC - seq.LowPC)) + continue; std::unique_ptr sequence = LineTable::CreateLineSequenceContainer(); for (unsigned idx = seq.FirstRowIndex; idx < seq.LastRowIndex; ++idx) { diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug_line-tombstone.s b/lldb/test/Shell/SymbolFile/DWARF/debug_line-tombstone.s --- a/lldb/test/Shell/SymbolFile/DWARF/debug_line-tombstone.s +++ b/lldb/test/Shell/SymbolFile/DWARF/debug_line-tombstone.s @@ -1,27 +1,48 @@ -# This test that we don't get confused by line tables containing a tombstone -# (-1) value, as produced by recent lld's. Line sequences with the tombstone -# value should be completely ignored. The tombstone sequence is deliberately -# longer so that any attempt at an address binary search will likely land inside -# the sequence. +# Test handling of line table tombstone strategies by various linkers. When a +# section not added to the final binary (either due to --gc-sections or comdats) +# (elf) linkers still need to resolve debug info relocations to it. This test +# simulates tombstoning behavior of bfd gold and lld linkers. +# - ld.bfd will resolve all relocations to zero +# - ld.gold (and lld before D81784) could also resolve the relocations to a +# small value (zero+relocation addend), although this is not likely to happen +# in line tables. +# - ld.lld since D81784, resolves the relocations to -1 +# These line tables should be ignored. bfd and gold tombstones can be ambiguous +# if the binary has sections in the low addresses, but we should definitely +# ignore them if they fall outside of any section. -# RUN: llvm-mc --filetype=obj --triple=x86_64-pc-linux %s -o %t -# RUN: %lldb -o "image lookup -n main -v" -o "image dump line-table main.cpp" \ -# RUN: -o exit %t | FileCheck %s +# REQUIRES: x86, lld -# CHECK-LABEL: image lookup -n main -v -# CHECK: LineEntry: [0x0000000000001000-0x0000000000001001): main.cpp:1 +# RUN: llvm-mc --filetype=obj --triple=x86_64-pc-linux %s -o %t.lld.o --defsym TOMBSTONE=-1 +# RUN: ld.lld -o %t.lld %t.lld.o --image-base=0x10000 +# RUN: %lldb -o "image lookup -n _start -v" -o "image dump line-table main.cpp" \ +# RUN: -o exit %t.lld | FileCheck %s + +# RUN: llvm-mc --filetype=obj --triple=x86_64-pc-linux %s -o %t.bfd.o --defsym TOMBSTONE=0 +# RUN: ld.lld -o %t.bfd %t.bfd.o --image-base=0x10000 +# RUN: %lldb -o "image lookup -n _start -v" -o "image dump line-table main.cpp" \ +# RUN: -o exit %t.bfd | FileCheck %s + +# RUN: llvm-mc --filetype=obj --triple=x86_64-pc-linux %s -o %t.gold.o --defsym TOMBSTONE=47 +# RUN: ld.lld -o %t.gold %t.gold.o --image-base=0x10000 +# RUN: %lldb -o "image lookup -n _start -v" -o "image dump line-table main.cpp" \ +# RUN: -o exit %t.gold | FileCheck %s + +# CHECK-LABEL: image lookup -n _start -v +# CHECK: LineEntry: [0x0000000000020000-0x0000000000020001): main.cpp:1 # CHECK-LABEL: image dump line-table main.cpp # CHECK-NEXT: Line table for main.cpp -# CHECK-NEXT: 0x0000000000001000: main.cpp:1 -# CHECK-NEXT: 0x0000000000001001: main.cpp:1 +# CHECK-NEXT: 0x0000000000020000: main.cpp:1 +# CHECK-NEXT: 0x0000000000020001: main.cpp:1 # CHECK-EMPTY: # CHECK-NEXT: exit + .globl _start .text -.space 0x1000 -main: + .p2align 16 +_start: nop -.Lmain_end: +.L_start_end: .section .debug_abbrev,"",@progbits .byte 1 # Abbreviation Code @@ -52,8 +73,8 @@ .asciz "Hand-written DWARF" # DW_AT_producer .asciz "main.cpp" # DW_AT_name .long 0 # DW_AT_stmt_list - .quad main-.text # DW_AT_low_pc - .long .Lmain_end-main # DW_AT_high_pc + .quad _start # DW_AT_low_pc + .long .L_start_end-_start # DW_AT_high_pc .Ldebug_info_end0: .section .debug_line,"",@progbits @@ -75,7 +96,7 @@ .byte 0 .Lprologue1_end: .byte 0, 9, 2 # DW_LNE_set_address - .quad -1 + .quad TOMBSTONE .byte 1 # DW_LNS_copy .byte 33 # address += 1, line += 1 .byte 33 # address += 1, line += 1 @@ -97,7 +118,7 @@ .byte 0, 1, 1 # DW_LNE_end_sequence .byte 0, 9, 2 # DW_LNE_set_address - .quad main-.text + .quad _start .byte 18 # address += 0, line += 0 .byte 2 # DW_LNS_advance_pc .uleb128 1