Skip to content

Commit f92a554

Browse files
committed
[DebugInfo] Dump form values according to the DWARF format (2/8).
The patch changes dumping of DWARF form values which sizes depend on the DWARF format so that they are printed as 16-digit hex values for DWARF64. Differential Revision: https://reviews.llvm.org/D79997
1 parent 69dfa07 commit f92a554

File tree

7 files changed

+18
-13
lines changed

7 files changed

+18
-13
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFFormValue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class DWARFFormValue {
5555
};
5656

5757
dwarf::Form Form; /// Form for this value.
58+
dwarf::DwarfFormat Format =
59+
dwarf::DWARF32; /// Remember the DWARF format at extract time.
5860
ValueType Value; /// Contains all data for the form.
5961
const DWARFUnit *U = nullptr; /// Remember the DWARFUnit at extract time.
6062
const DWARFContext *C = nullptr; /// Context for extract time.

llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
241241
Ctx = &CU->getContext();
242242
C = Ctx;
243243
U = CU;
244+
Format = FP.Format;
244245
bool Indirect = false;
245246
bool IsBlock = false;
246247
Value.data = nullptr;
@@ -386,6 +387,7 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
386387
raw_ostream &AddrOS = DumpOpts.ShowAddresses
387388
? WithColor(OS, HighlightColor::Address).get()
388389
: nulls();
390+
int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(Format);
389391
switch (Form) {
390392
case DW_FORM_addr:
391393
dumpSectionedAddress(AddrOS, DumpOpts, {Value.uval, Value.SectionIndex});
@@ -481,12 +483,13 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
481483
break;
482484
case DW_FORM_strp:
483485
if (DumpOpts.Verbose)
484-
OS << format(" .debug_str[0x%8.8" PRIx64 "] = ", UValue);
486+
OS << format(" .debug_str[0x%0*" PRIx64 "] = ", OffsetDumpWidth, UValue);
485487
dumpString(OS);
486488
break;
487489
case DW_FORM_line_strp:
488490
if (DumpOpts.Verbose)
489-
OS << format(" .debug_line_str[0x%8.8" PRIx64 "] = ", UValue);
491+
OS << format(" .debug_line_str[0x%0*" PRIx64 "] = ", OffsetDumpWidth,
492+
UValue);
490493
dumpString(OS);
491494
break;
492495
case DW_FORM_strx:
@@ -551,7 +554,7 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
551554
break;
552555

553556
case DW_FORM_sec_offset:
554-
AddrOS << format("0x%08" PRIx64, UValue);
557+
AddrOS << format("0x%0*" PRIx64, OffsetDumpWidth, UValue);
555558
break;
556559

557560
default:

llvm/test/DebugInfo/X86/dwarfdump-header-64.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ LH_5_end:
159159
# CHECK: seg_select_size: 0
160160
# CHECK: prologue_length: 0x00000044
161161
# CHECK: max_ops_per_inst: 1
162-
# CHECK: include_directories[ 0] = .debug_str[0x00000028] = "Directory5a"
163-
# CHECK: include_directories[ 1] = .debug_str[0x00000034] = "Directory5b"
162+
# CHECK: include_directories[ 0] = .debug_str[0x0000000000000028] = "Directory5a"
163+
# CHECK: include_directories[ 1] = .debug_str[0x0000000000000034] = "Directory5b"
164164
# CHECK-NOT: include_directories
165165
# CHECK: file_names[ 0]:
166166
# CHECK-NEXT: name: "File5a"

llvm/test/DebugInfo/X86/dwarfdump-rnglists-dwarf64.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@ Range1_end:
188188
# CHECK: Compile Unit:
189189
# CHECK-NOT: Compile Unit:
190190
# CHECK: DW_TAG_compile_unit
191-
# CHECK-NEXT: DW_AT_rnglists_base [DW_FORM_sec_offset] (0x00000014)
192-
# CHECK-NEXT: DW_AT_ranges [DW_FORM_sec_offset] (0x00000024
191+
# CHECK-NEXT: DW_AT_rnglists_base [DW_FORM_sec_offset] (0x0000000000000014)
192+
# CHECK-NEXT: DW_AT_ranges [DW_FORM_sec_offset] (0x0000000000000024
193193
# CHECK-NEXT: [0x00000014, 0x0000001e) ".text"
194194
# CHECK-NEXT: [0x0000002a, 0x00000034) ".text")
195195

196196
# CHECK: Compile Unit:
197197
# CHECK-NOT: Compile Unit:
198198
# CHECK: DW_TAG_compile_unit
199-
# CHECK-NEXT: DW_AT_rnglists_base [DW_FORM_sec_offset] (0x00000014)
199+
# CHECK-NEXT: DW_AT_rnglists_base [DW_FORM_sec_offset] (0x0000000000000014)
200200
# CHECK-NEXT: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x1) rangelist = 0x00000034
201201
# CHECK-NEXT: [0x0000002a, 0x00000034) ".text")
202202

llvm/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ TU_5_end:
238238
# COMMON: DW_TAG_compile_unit
239239
# COMMON-NEXT: DW_AT_producer [DW_FORM_strx] (indexed (00000000) string = "Handmade DWARF producer")
240240
# COMMON-NEXT: DW_AT_name [DW_FORM_strx] (indexed (00000001) string = "Compile_Unit_2")
241-
# COMMON-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000038)
241+
# COMMON-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x0000000000000038)
242242
# COMMON-NEXT: DW_AT_comp_dir [DW_FORM_strx] (indexed (00000002) string = "/home/test/CU2")
243243
#
244244
# The type unit

llvm/test/DebugInfo/X86/dwarfdump-str-offsets.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ TU_split_5_end:
377377
# COMMON: DW_TAG_compile_unit
378378
# COMMON-NEXT: DW_AT_producer [DW_FORM_strx] (indexed (00000000) string = "Handmade DWARF producer")
379379
# COMMON-NEXT: DW_AT_name [DW_FORM_strx] (indexed (00000001) string = "Compile_Unit_2")
380-
# COMMON-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000038)
380+
# COMMON-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x0000000000000038)
381381
# COMMON-NEXT: DW_AT_comp_dir [DW_FORM_strx] (indexed (00000002) string = "/home/test/CU2")
382382
#
383383
# The split CU

llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,15 @@ INSTANTIATE_TEST_CASE_P(
384384
testing::Values(DumpValueParams{DW_FORM_strp, DumpTestSample32, DWARF32,
385385
" .debug_str[0x00112233] = "},
386386
DumpValueParams{DW_FORM_strp, DumpTestSample64, DWARF64,
387-
" .debug_str[0x11223344556677] = "},
387+
" .debug_str[0x0011223344556677] = "},
388388
DumpValueParams{DW_FORM_line_strp, DumpTestSample32,
389389
DWARF32, " .debug_line_str[0x00112233] = "},
390390
DumpValueParams{DW_FORM_line_strp, DumpTestSample64,
391391
DWARF64,
392-
" .debug_line_str[0x11223344556677] = "},
392+
" .debug_line_str[0x0011223344556677] = "},
393393
DumpValueParams{DW_FORM_sec_offset, DumpTestSample32,
394394
DWARF32, "0x00112233"},
395395
DumpValueParams{DW_FORM_sec_offset, DumpTestSample64,
396-
DWARF64, "0x11223344556677"}), );
396+
DWARF64, "0x0011223344556677"}), );
397397

398398
} // end anonymous namespace

0 commit comments

Comments
 (0)