Skip to content

Commit f1086fe

Browse files
committed
1. Address comment
2. Bug fix on where line table starts
1 parent 7c1904f commit f1086fe

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,16 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
894894
uint64_t PrologueLength = LineTable->Prologue.PrologueLength;
895895
uint64_t TotalLength = LineTable->Prologue.TotalLength;
896896
uint64_t LineTableEnd = LineTableStart + TotalLength + DwarfOffset;
897-
uint64_t SequencesStart = LineTableStart + PrologueLength + DwarfOffset;
897+
898+
// See DWARF definition for this, the following three do not
899+
// count toward prologue length. Calculate SequencesStart correctly
900+
// according to DWARF specification:
901+
uint64_t InitialLengthSize = DwarfOffset;
902+
// Version field is always 2 bytes
903+
uint64_t VersionSize = 2;
904+
uint64_t PrologueLengthSize = DwarfOffset;
905+
uint64_t SequencesStart = LineTableStart + InitialLengthSize + VersionSize +
906+
PrologueLengthSize + PrologueLength;
898907

899908
// Check if the offset is within the bounds of this specific line table
900909
if (*SectionOffset < SequencesStart || *SectionOffset >= LineTableEnd) {
@@ -907,7 +916,7 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
907916
break;
908917
}
909918

910-
// Check if the offset matches any of the sequence offset offsets using
919+
// Check if the offset matches any of the sequence offset.
911920
auto It =
912921
std::find_if(LineTable->Sequences.begin(), LineTable->Sequences.end(),
913922
[SectionOffset](const auto &Sequence) {

llvm/test/tools/llvm-dwarfdump/verify_stmt_seq.yaml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,24 @@
66
# RUN: not llvm-dwarfdump -verify -debug-info verify_stmt_seq.o | FileCheck %s --check-prefix=CHECK_INVALID --implicit-check-not=error:
77
# RUN: llvm-dwarfdump -debug-line -verbose -debug-info verify_stmt_seq.o | FileCheck %s --check-prefix=CHECK_DEBUG_LINE
88

9-
10-
# CHECK_INVALID: error: DW_AT_LLVM_stmt_sequence offset 0x00000000 is not within the line table bounds [0x0000002e, 0x000000fd)
9+
# CHECK_INVALID: error: DW_AT_LLVM_stmt_sequence offset 0x00000000 is not within the line table bounds [0x00000034, 0x000000fd)
1110
# CHECK_INVALID: DW_AT_LLVM_stmt_sequence [DW_FORM_sec_offset] (0x00000000)
1211

13-
# 0xd3 would be a valid offset, if the line table wan't ill formed with two rows having the same PC (0x8c).
12+
# CHECK_DEBUG_LINE: Address Line Column File ISA Discriminator OpIndex Flags
13+
# CHECK_DEBUG_LINE-NEXT: ------------------ ------ ------ ------ --- ------------- ------- -------------
14+
# CHECK_DEBUG_LINE-NEXT: 0x00000034: 05 DW_LNS_set_column (10)
15+
# CHECK_DEBUG_LINE-NEXT: 0x00000036: 0a DW_LNS_set_prologue_end
16+
# CHECK_DEBUG_LINE-NEXT: 0x00000037: 00 DW_LNE_set_address (0x0000000000000000)
17+
# CHECK_DEBUG_LINE-NEXT: 0x00000042: 14 address += 0, line += 2, op-index += 0
18+
# CHECK_DEBUG_LINE-NEXT: 0x0000000000000000 3 10 1 0 0 0 is_stmt prologue_end
19+
# CHECK_DEBUG_LINE-NEXT: 0x00000043: 05 DW_LNS_set_column (3)
20+
# CHECK_DEBUG_LINE-NEXT: 0x00000045: 06 DW_LNS_negate_stmt
21+
# CHECK_DEBUG_LINE-NEXT: 0x00000046: 4a address += 4, line += 0, op-index += 0
22+
# CHECK_DEBUG_LINE-NEXT: 0x0000000000000004 3 3 1 0 0 0
23+
# CHECK_DEBUG_LINE-NEXT: 0x00000047: 00 DW_LNE_end_sequence
24+
# CHECK_DEBUG_LINE-NEXT: 0x0000000000000004 3 3 1 0 0 0 end_sequence
25+
26+
# 0xd3 would be a valid offset, if the line table wasn't ill formed with two rows having the same PC (0x8c).
1427
# CHECK_INVALID: error: DW_AT_LLVM_stmt_sequence offset 0x000000d3 does not point to a valid sequence offset in the line table
1528
# CHECK_INVALID: DW_AT_LLVM_stmt_sequence [DW_FORM_sec_offset] (0x000000d3)
1629

@@ -25,13 +38,16 @@
2538

2639
# CHECK_INVALID: error: DIE has invalid DW_AT_LLVM_stmt_sequence encoding
2740
# CHECK_INVALID: DW_AT_LLVM_stmt_sequence [DW_FORM_data4] (0x000000a7)
28-
2941
# CHECK_INVALID: error: DW_AT_LLVM_stmt_sequence offset 0x000000ab does not point to a valid sequence offset in the line table
3042
# CHECK_INVALID: DW_AT_LLVM_stmt_sequence [DW_FORM_sec_offset] (0x000000ab)
3143

3244
# CHECK_INVALID: error: DW_AT_LLVM_stmt_sequence offset is beyond .debug_line bounds: 0x00eeeee7
3345
# CHECK_INVALID: DW_AT_LLVM_stmt_sequence [DW_FORM_sec_offset] (0x00eeeee7)
3446

47+
# CHECK_DEBUG_LINE: 0x000000f8: 02 DW_LNS_advance_pc (addr += 4, op-index += 0)
48+
# CHECK_DEBUG_LINE-NEXT: 0x000000fa: 00 DW_LNE_end_sequence
49+
# CHECK_DEBUG_LINE-NEXT: 0x0000000000000094 30 86 1 0 0 0 is_stmt end_sequence
50+
3551
# CHECK_INVALID: error: Aggregated error counts:
3652
# CHECK_INVALID-NEXT: error: DW_AT_LLVM_stmt_sequence offset out of bounds occurred 1 time(s).
3753
# CHECK_INVALID-NEXT: error: DW_AT_LLVM_stmt_sequence offset out of line table bounds occurred 1 time(s).

0 commit comments

Comments
 (0)