Skip to content

Commit e64af75

Browse files
committed
[DWARF] Fix DWARFUnit::getDebugInfoSize() for 64-bit DWARF.
The calculation there was correct only for DWARF32. Differential Revision: https://reviews.llvm.org/D66421 llvm-svn: 369356
1 parent 213a5ab commit e64af75

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

llvm/include/llvm/BinaryFormat/Dwarf.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,17 @@ struct FormParams {
513513
explicit operator bool() const { return Version && AddrSize; }
514514
};
515515

516+
/// Get the byte size of the unit length field depending on the DWARF format.
517+
inline uint8_t getUnitLengthFieldByteSize(DwarfFormat Format) {
518+
switch (Format) {
519+
case DwarfFormat::DWARF32:
520+
return 4;
521+
case DwarfFormat::DWARF64:
522+
return 12;
523+
}
524+
llvm_unreachable("Invalid Format value");
525+
}
526+
516527
/// Get the fixed byte size for a given form.
517528
///
518529
/// If the form has a fixed byte size, then an Optional with a value will be

llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ class DWARFUnitHeader {
9797
return UnitType == dwarf::DW_UT_type || UnitType == dwarf::DW_UT_split_type;
9898
}
9999
uint8_t getSize() const { return Size; }
100+
uint8_t getUnitLengthFieldByteSize() const {
101+
return dwarf::getUnitLengthFieldByteSize(FormParams.Format);
102+
}
100103
uint64_t getNextUnitOffset() const {
101-
return Offset + Length +
102-
(FormParams.Format == llvm::dwarf::DwarfFormat::DWARF64 ? 4 : 0) +
103-
FormParams.getDwarfOffsetByteSize();
104+
return Offset + Length + getUnitLengthFieldByteSize();
104105
}
105106
};
106107

@@ -501,7 +502,8 @@ class DWARFUnit {
501502
private:
502503
/// Size in bytes of the .debug_info data associated with this compile unit.
503504
size_t getDebugInfoSize() const {
504-
return Header.getLength() + 4 - getHeaderSize();
505+
return Header.getLength() + Header.getUnitLengthFieldByteSize() -
506+
getHeaderSize();
505507
}
506508

507509
/// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# RUN: llvm-mc %s -filetype obj -triple x86_64-unknown-elf -o - | \
2+
# RUN: llvm-dwarfdump -debug-info - | \
3+
# RUN: FileCheck %s
4+
5+
.section .debug_abbrev,"",@progbits
6+
.byte 0x01 # Abbrev code
7+
.byte 0x11 # DW_TAG_compile_unit
8+
.byte 0x00 # DW_CHILDREN_no
9+
.byte 0x13 # DW_AT_language
10+
.byte 0x05 # DW_FORM_data2
11+
.byte 0x00 # EOM(1)
12+
.byte 0x00 # EOM(2)
13+
.byte 0x00 # EOM(3)
14+
15+
.section .debug_info,"",@progbits
16+
# CHECK: .debug_info contents:
17+
# CHECK-NEXT: 0x00000000: Compile Unit:
18+
DI_4_64_start:
19+
.long 0xffffffff # DWARF64 mark
20+
.quad DI_4_64_end - DI_4_64_version # Length of Unit
21+
# CHECK-SAME: length = 0x0000000f
22+
DI_4_64_version:
23+
.short 4 # DWARF version number
24+
# CHECK-SAME: version = 0x0004
25+
.quad .debug_abbrev # Offset Into Abbrev. Section
26+
# CHECK-SAME: abbr_offset = 0x0000
27+
.byte 8 # Address Size (in bytes)
28+
# CHECK-SAME: addr_size = 0x08
29+
# CHECK-SAME: (next unit at 0x0000001b)
30+
31+
.byte 1 # Abbreviation code
32+
# CHECK: 0x00000017: DW_TAG_compile_unit
33+
.short 4 # DW_LANG_C_plus_plus
34+
# CHECK-NEXT: DW_AT_language (DW_LANG_C_plus_plus)
35+
.byte 0 # NULL
36+
DI_4_64_end:
37+

0 commit comments

Comments
 (0)