From 0db1684b7435201e6b30236e6334a618fcfa6771 Mon Sep 17 00:00:00 2001 From: Igor Kudrin Date: Tue, 19 May 2020 13:35:20 +0700 Subject: [PATCH] [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 --- llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h | 1 + llvm/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp | 3 ++- llvm/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp | 6 ++++-- llvm/test/DebugInfo/X86/dwp-dwarf64.s | 2 +- llvm/test/tools/llvm-dwarfdump/X86/debug_info_min_dwarf64.s | 2 +- llvm/test/tools/llvm-dwarfdump/X86/typeunit-v4-dwarf64.s | 2 +- llvm/test/tools/llvm-dwarfdump/X86/typeunit-v5-dwarf64.s | 2 +- 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h index cb9e2c3..5b3b466 100644 --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -291,6 +291,7 @@ public: return Header.getDwarfOffsetByteSize(); } uint64_t getLength() const { return Header.getLength(); } + dwarf::DwarfFormat getFormat() const { return Header.getFormat(); } uint8_t getUnitType() const { return Header.getUnitType(); } bool isTypeUnit() const { return Header.isTypeUnit(); } uint64_t getNextUnitOffset() const { return Header.getNextUnitOffset(); } diff --git a/llvm/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp index f59e492..3c3513e 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp @@ -15,8 +15,9 @@ using namespace llvm; void DWARFCompileUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) { + int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(getFormat()); OS << format("0x%08" PRIx64, getOffset()) << ": Compile Unit:" - << " length = " << format("0x%08" PRIx64, getLength()) + << " length = " << format("0x%0*" PRIx64, OffsetDumpWidth, getLength()) << " version = " << format("0x%04x", getVersion()); if (getVersion() >= 5) OS << " unit_type = " << dwarf::UnitTypeString(getUnitType()); diff --git a/llvm/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp index bb81090..1873e22 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp @@ -20,16 +20,18 @@ using namespace llvm; void DWARFTypeUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) { DWARFDie TD = getDIEForOffset(getTypeOffset() + getOffset()); const char *Name = TD.getName(DINameKind::ShortName); + int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(getFormat()); if (DumpOpts.SummarizeTypes) { OS << "name = '" << Name << "'" << " type_signature = " << format("0x%016" PRIx64, getTypeHash()) - << " length = " << format("0x%08" PRIx64, getLength()) << '\n'; + << " length = " << format("0x%0*" PRIx64, OffsetDumpWidth, getLength()) + << '\n'; return; } OS << format("0x%08" PRIx64, getOffset()) << ": Type Unit:" - << " length = " << format("0x%08" PRIx64, getLength()) + << " length = " << format("0x%0*" PRIx64, OffsetDumpWidth, getLength()) << " version = " << format("0x%04x", getVersion()); if (getVersion() >= 5) OS << " unit_type = " << dwarf::UnitTypeString(getUnitType()); diff --git a/llvm/test/DebugInfo/X86/dwp-dwarf64.s b/llvm/test/DebugInfo/X86/dwp-dwarf64.s index dbba3f7..b5b9fad 100644 --- a/llvm/test/DebugInfo/X86/dwp-dwarf64.s +++ b/llvm/test/DebugInfo/X86/dwp-dwarf64.s @@ -5,7 +5,7 @@ # CHECK: .debug_info.dwo contents: # CHECK: 0x00000000: Compile Unit: -# CHECK-SAME: length = 0x00000018 +# CHECK-SAME: length = 0x0000000000000018 # CHECK-SAME: version = 0x0004 # CHECK-SAME: abbr_offset = 0x0000 # CHECK-SAME: addr_size = 0x04 diff --git a/llvm/test/tools/llvm-dwarfdump/X86/debug_info_min_dwarf64.s b/llvm/test/tools/llvm-dwarfdump/X86/debug_info_min_dwarf64.s index 9a9c9b3..5c1d752 100644 --- a/llvm/test/tools/llvm-dwarfdump/X86/debug_info_min_dwarf64.s +++ b/llvm/test/tools/llvm-dwarfdump/X86/debug_info_min_dwarf64.s @@ -18,7 +18,7 @@ DI_4_64_start: .long 0xffffffff # DWARF64 mark .quad DI_4_64_end - DI_4_64_version # Length of Unit -# CHECK-SAME: length = 0x0000000f +# CHECK-SAME: length = 0x000000000000000f DI_4_64_version: .short 4 # DWARF version number # CHECK-SAME: version = 0x0004 diff --git a/llvm/test/tools/llvm-dwarfdump/X86/typeunit-v4-dwarf64.s b/llvm/test/tools/llvm-dwarfdump/X86/typeunit-v4-dwarf64.s index a785f8a..6b9eff3 100644 --- a/llvm/test/tools/llvm-dwarfdump/X86/typeunit-v4-dwarf64.s +++ b/llvm/test/tools/llvm-dwarfdump/X86/typeunit-v4-dwarf64.s @@ -25,7 +25,7 @@ TU_4_64_start: .long 0xffffffff # DWARF64 mark .quad TU_4_64_end-TU_4_64_version # Length of Unit -# CHECK-SAME: length = 0x00000021 +# CHECK-SAME: length = 0x0000000000000021 TU_4_64_version: .short 4 # DWARF version number # CHECK-SAME: version = 0x0004 diff --git a/llvm/test/tools/llvm-dwarfdump/X86/typeunit-v5-dwarf64.s b/llvm/test/tools/llvm-dwarfdump/X86/typeunit-v5-dwarf64.s index 1a82a05..de07dd1 100644 --- a/llvm/test/tools/llvm-dwarfdump/X86/typeunit-v5-dwarf64.s +++ b/llvm/test/tools/llvm-dwarfdump/X86/typeunit-v5-dwarf64.s @@ -25,7 +25,7 @@ TU_5_64_start: .long 0xffffffff # DWARF64 mark .quad TU_5_64_end-TU_5_64_version # Length of Unit -# CHECK-SAME: length = 0x00000022 +# CHECK-SAME: length = 0x0000000000000022 TU_5_64_version: .short 5 # DWARF version number # CHECK-SAME: version = 0x0005 -- 2.7.4