Skip to content

Commit ea83e0b

Browse files
committed
llvm-dwarfdump: Dump address forms in their encoded length rather than always in 64 bits
Few places did this already - refactor them all into a common helper.
1 parent 1065f34 commit ea83e0b

19 files changed

+60
-47
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class DWARFFormValue {
8282
void dump(raw_ostream &OS, DIDumpOptions DumpOpts = DIDumpOptions()) const;
8383
void dumpSectionedAddress(raw_ostream &OS, DIDumpOptions DumpOpts,
8484
object::SectionedAddress SA) const;
85+
void dumpAddress(raw_ostream &OS, uint64_t Address) const;
86+
static void dumpAddress(raw_ostream &OS, uint8_t AddressSize,
87+
uint64_t Address);
8588
static void dumpAddressSection(const DWARFObject &Obj, raw_ostream &OS,
8689
DIDumpOptions DumpOpts, uint64_t SectionIndex);
8790

llvm/lib/DebugInfo/DWARF/DWARFAddressRange.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ void DWARFAddressRange::dump(raw_ostream &OS, uint32_t AddressSize,
1818
const DWARFObject *Obj) const {
1919

2020
OS << (DumpOpts.DisplayRawContents ? " " : "[");
21-
OS << format("0x%*.*" PRIx64 ", ", AddressSize * 2, AddressSize * 2, LowPC)
22-
<< format("0x%*.*" PRIx64, AddressSize * 2, AddressSize * 2, HighPC);
21+
DWARFFormValue::dumpAddress(OS, AddressSize, LowPC);
22+
OS << ", ";
23+
DWARFFormValue::dumpAddress(OS, AddressSize, HighPC);
2324
OS << (DumpOpts.DisplayRawContents ? "" : ")");
2425

2526
if (Obj)

llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
1010
#include "llvm/BinaryFormat/Dwarf.h"
11+
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
1112
#include "llvm/Support/Errc.h"
1213
#include "llvm/Support/Format.h"
1314
#include "llvm/Support/raw_ostream.h"
@@ -20,9 +21,11 @@ using namespace llvm;
2021

2122
void DWARFDebugArangeSet::Descriptor::dump(raw_ostream &OS,
2223
uint32_t AddressSize) const {
23-
OS << format("[0x%*.*" PRIx64 ", ", AddressSize * 2, AddressSize * 2, Address)
24-
<< format(" 0x%*.*" PRIx64 ")", AddressSize * 2, AddressSize * 2,
25-
getEndAddress());
24+
OS << '[';
25+
DWARFFormValue::dumpAddress(OS, AddressSize, Address);
26+
OS << ", ";
27+
DWARFFormValue::dumpAddress(OS, AddressSize, getEndAddress());
28+
OS << ')';
2629
}
2730

2831
void DWARFDebugArangeSet::clear() {

llvm/lib/DebugInfo/DWARF/DWARFDebugRnglists.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h"
1010
#include "llvm/BinaryFormat/Dwarf.h"
11+
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
1112
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
1213
#include "llvm/Support/Errc.h"
1314
#include "llvm/Support/Error.h"
@@ -201,15 +202,15 @@ void RangeListEntry::dump(
201202
CurrentBase = Value0;
202203
if (!DumpOpts.Verbose)
203204
return;
204-
OS << format(" 0x%*.*" PRIx64, AddrSize * 2, AddrSize * 2, Value0);
205+
DWARFFormValue::dumpAddress(OS << ' ', AddrSize, Value0);
205206
break;
206207
}
207208
case dwarf::DW_RLE_base_address:
208209
// In non-verbose mode we do not print anything for this entry.
209210
CurrentBase = Value0;
210211
if (!DumpOpts.Verbose)
211212
return;
212-
OS << format(" 0x%*.*" PRIx64, AddrSize * 2, AddrSize * 2, Value0);
213+
DWARFFormValue::dumpAddress(OS << ' ', AddrSize, Value0);
213214
break;
214215
case dwarf::DW_RLE_start_length:
215216
PrintRawEntry(OS, *this, AddrSize, DumpOpts);

llvm/lib/DebugInfo/DWARF/DWARFDie.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
284284
// Print the actual address rather than the offset.
285285
uint64_t LowPC, HighPC, Index;
286286
if (Die.getLowAndHighPC(LowPC, HighPC, Index))
287-
OS << format("0x%016" PRIx64, HighPC);
287+
DWARFFormValue::dumpAddress(OS, U->getAddressByteSize(), HighPC);
288288
else
289289
FormValue.dump(OS, DumpOpts);
290290
}

llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,16 @@ bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
358358
return !errorToBool(std::move(Err));
359359
}
360360

361+
void DWARFFormValue::dumpAddress(raw_ostream &OS, uint8_t AddressSize,
362+
uint64_t Address) {
363+
uint8_t HexDigits = AddressSize * 2;
364+
OS << format("0x%*.*" PRIx64, HexDigits, HexDigits, Address);
365+
}
366+
361367
void DWARFFormValue::dumpSectionedAddress(raw_ostream &OS,
362368
DIDumpOptions DumpOpts,
363369
object::SectionedAddress SA) const {
364-
OS << format("0x%016" PRIx64, SA.Address);
370+
dumpAddress(OS, U->getAddressByteSize(), SA.Address);
365371
dumpAddressSection(U->getContext().getDWARFObj(), OS, DumpOpts,
366372
SA.SectionIndex);
367373
}

llvm/test/DebugInfo/MIR/ARM/subregister-full-piece.mir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
# CHECK: DW_AT_stmt_list (0x00000000)
1414
# CHECK: DW_AT_comp_dir ("/")
1515
# CHECK: DW_AT_APPLE_optimized (true)
16-
# CHECK: DW_AT_low_pc (0x0000000000000000)
17-
# CHECK: DW_AT_high_pc (0x0000000000000008)
16+
# CHECK: DW_AT_low_pc (0x00000000)
17+
# CHECK: DW_AT_high_pc (0x00000008)
1818

1919
# CHECK: DW_TAG_subprogram
20-
# CHECK: DW_AT_low_pc (0x0000000000000000)
21-
# CHECK: DW_AT_high_pc (0x0000000000000008)
20+
# CHECK: DW_AT_low_pc (0x00000000)
21+
# CHECK: DW_AT_high_pc (0x00000008)
2222
# CHECK: DW_AT_APPLE_omit_frame_ptr (true)
2323
# CHECK: DW_AT_frame_base (DW_OP_reg13 SP)
2424
# CHECK: DW_AT_name ("f")

llvm/test/DebugInfo/MIR/Hexagon/bundled-call-pr44001.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# CHECK-LABEL: DW_TAG_GNU_call_site
66
# CHECK-NEXT: DW_AT_abstract_origin [DW_FORM_ref4] (cu + 0x[[BAR_ADDR:[0-9a-f]+]] => {0x{{0*}}[[BAR_ADDR]]} "bar")
7-
# CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000008 ".text")
7+
# CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x00000008 ".text")
88

99
--- |
1010
; ModuleID = 'bundled-call-pr44001.ll'

llvm/test/DebugInfo/Mips/dbg-call-site-low-pc.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
;; Test mips, mipsel, mips64, mips64el:
2323
; CHECK: DW_TAG_GNU_call_site
2424
; CHECK-NEXT: DW_AT_abstract_origin {{.*}} "f1"
25-
; CHECK-NEXT: DW_AT_low_pc (0x0000000000000010)
25+
; CHECK-NEXT: DW_AT_low_pc (0x{{(00000000)?}}00000010)
2626

2727
; ModuleID = 'm.c'
2828
source_filename = "m.c"

llvm/test/DebugInfo/X86/debug-loc-offset.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# Checking that we have two compile units with two sets of high/lo_pc.
3333
# CHECK: .debug_info contents
3434
# CHECK: DW_TAG_compile_unit
35-
# CHECK: DW_AT_low_pc {{.*}} (0x0000000000000020 ".text")
35+
# CHECK: DW_AT_low_pc {{.*}} (0x00000020 ".text")
3636
# CHECK: DW_AT_high_pc
3737
#
3838
# CHECK: DW_TAG_subprogram
@@ -51,7 +51,7 @@
5151
# CHECK-NOT: DW_AT_location
5252
#
5353
# CHECK: DW_TAG_compile_unit
54-
# CHECK: DW_AT_low_pc {{.*}} (0x0000000000000000 ".text")
54+
# CHECK: DW_AT_low_pc {{.*}} (0x00000000 ".text")
5555
# CHECK: DW_AT_high_pc
5656
#
5757
# CHECK: DW_TAG_subprogram

0 commit comments

Comments
 (0)