Skip to content

Commit 0db1684

Browse files
committed
[DebugInfo] Dump length of CUs and TUs according to the DWARF format (3/8).
The patch changes dumping of the unit_length field in a unit header so that it is printed as a 16-digit hex value if the unit is in the DWARF64 format. Differential Revision: https://reviews.llvm.org/D79997
1 parent f92a554 commit 0db1684

File tree

7 files changed

+11
-7
lines changed

7 files changed

+11
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ class DWARFUnit {
291291
return Header.getDwarfOffsetByteSize();
292292
}
293293
uint64_t getLength() const { return Header.getLength(); }
294+
dwarf::DwarfFormat getFormat() const { return Header.getFormat(); }
294295
uint8_t getUnitType() const { return Header.getUnitType(); }
295296
bool isTypeUnit() const { return Header.isTypeUnit(); }
296297
uint64_t getNextUnitOffset() const { return Header.getNextUnitOffset(); }

llvm/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
using namespace llvm;
1616

1717
void DWARFCompileUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
18+
int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(getFormat());
1819
OS << format("0x%08" PRIx64, getOffset()) << ": Compile Unit:"
19-
<< " length = " << format("0x%08" PRIx64, getLength())
20+
<< " length = " << format("0x%0*" PRIx64, OffsetDumpWidth, getLength())
2021
<< " version = " << format("0x%04x", getVersion());
2122
if (getVersion() >= 5)
2223
OS << " unit_type = " << dwarf::UnitTypeString(getUnitType());

llvm/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ using namespace llvm;
2020
void DWARFTypeUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
2121
DWARFDie TD = getDIEForOffset(getTypeOffset() + getOffset());
2222
const char *Name = TD.getName(DINameKind::ShortName);
23+
int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(getFormat());
2324

2425
if (DumpOpts.SummarizeTypes) {
2526
OS << "name = '" << Name << "'"
2627
<< " type_signature = " << format("0x%016" PRIx64, getTypeHash())
27-
<< " length = " << format("0x%08" PRIx64, getLength()) << '\n';
28+
<< " length = " << format("0x%0*" PRIx64, OffsetDumpWidth, getLength())
29+
<< '\n';
2830
return;
2931
}
3032

3133
OS << format("0x%08" PRIx64, getOffset()) << ": Type Unit:"
32-
<< " length = " << format("0x%08" PRIx64, getLength())
34+
<< " length = " << format("0x%0*" PRIx64, OffsetDumpWidth, getLength())
3335
<< " version = " << format("0x%04x", getVersion());
3436
if (getVersion() >= 5)
3537
OS << " unit_type = " << dwarf::UnitTypeString(getUnitType());

llvm/test/DebugInfo/X86/dwp-dwarf64.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# CHECK: .debug_info.dwo contents:
66

77
# CHECK: 0x00000000: Compile Unit:
8-
# CHECK-SAME: length = 0x00000018
8+
# CHECK-SAME: length = 0x0000000000000018
99
# CHECK-SAME: version = 0x0004
1010
# CHECK-SAME: abbr_offset = 0x0000
1111
# CHECK-SAME: addr_size = 0x04

llvm/test/tools/llvm-dwarfdump/X86/debug_info_min_dwarf64.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
DI_4_64_start:
1919
.long 0xffffffff # DWARF64 mark
2020
.quad DI_4_64_end - DI_4_64_version # Length of Unit
21-
# CHECK-SAME: length = 0x0000000f
21+
# CHECK-SAME: length = 0x000000000000000f
2222
DI_4_64_version:
2323
.short 4 # DWARF version number
2424
# CHECK-SAME: version = 0x0004

llvm/test/tools/llvm-dwarfdump/X86/typeunit-v4-dwarf64.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
TU_4_64_start:
2626
.long 0xffffffff # DWARF64 mark
2727
.quad TU_4_64_end-TU_4_64_version # Length of Unit
28-
# CHECK-SAME: length = 0x00000021
28+
# CHECK-SAME: length = 0x0000000000000021
2929
TU_4_64_version:
3030
.short 4 # DWARF version number
3131
# CHECK-SAME: version = 0x0004

llvm/test/tools/llvm-dwarfdump/X86/typeunit-v5-dwarf64.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
TU_5_64_start:
2626
.long 0xffffffff # DWARF64 mark
2727
.quad TU_5_64_end-TU_5_64_version # Length of Unit
28-
# CHECK-SAME: length = 0x00000022
28+
# CHECK-SAME: length = 0x0000000000000022
2929
TU_5_64_version:
3030
.short 5 # DWARF version number
3131
# CHECK-SAME: version = 0x0005

0 commit comments

Comments
 (0)