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.
This commit is contained in:
David Blaikie 2020-10-04 15:42:03 -07:00
parent 1065f3439b
commit ea83e0b17e
19 changed files with 60 additions and 47 deletions

View File

@ -82,6 +82,9 @@ public:
void dump(raw_ostream &OS, DIDumpOptions DumpOpts = DIDumpOptions()) const;
void dumpSectionedAddress(raw_ostream &OS, DIDumpOptions DumpOpts,
object::SectionedAddress SA) const;
void dumpAddress(raw_ostream &OS, uint64_t Address) const;
static void dumpAddress(raw_ostream &OS, uint8_t AddressSize,
uint64_t Address);
static void dumpAddressSection(const DWARFObject &Obj, raw_ostream &OS,
DIDumpOptions DumpOpts, uint64_t SectionIndex);

View File

@ -18,8 +18,9 @@ void DWARFAddressRange::dump(raw_ostream &OS, uint32_t AddressSize,
const DWARFObject *Obj) const {
OS << (DumpOpts.DisplayRawContents ? " " : "[");
OS << format("0x%*.*" PRIx64 ", ", AddressSize * 2, AddressSize * 2, LowPC)
<< format("0x%*.*" PRIx64, AddressSize * 2, AddressSize * 2, HighPC);
DWARFFormValue::dumpAddress(OS, AddressSize, LowPC);
OS << ", ";
DWARFFormValue::dumpAddress(OS, AddressSize, HighPC);
OS << (DumpOpts.DisplayRawContents ? "" : ")");
if (Obj)

View File

@ -8,6 +8,7 @@
#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
@ -20,9 +21,11 @@ using namespace llvm;
void DWARFDebugArangeSet::Descriptor::dump(raw_ostream &OS,
uint32_t AddressSize) const {
OS << format("[0x%*.*" PRIx64 ", ", AddressSize * 2, AddressSize * 2, Address)
<< format(" 0x%*.*" PRIx64 ")", AddressSize * 2, AddressSize * 2,
getEndAddress());
OS << '[';
DWARFFormValue::dumpAddress(OS, AddressSize, Address);
OS << ", ";
DWARFFormValue::dumpAddress(OS, AddressSize, getEndAddress());
OS << ')';
}
void DWARFDebugArangeSet::clear() {

View File

@ -8,6 +8,7 @@
#include "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
@ -201,7 +202,7 @@ void RangeListEntry::dump(
CurrentBase = Value0;
if (!DumpOpts.Verbose)
return;
OS << format(" 0x%*.*" PRIx64, AddrSize * 2, AddrSize * 2, Value0);
DWARFFormValue::dumpAddress(OS << ' ', AddrSize, Value0);
break;
}
case dwarf::DW_RLE_base_address:
@ -209,7 +210,7 @@ void RangeListEntry::dump(
CurrentBase = Value0;
if (!DumpOpts.Verbose)
return;
OS << format(" 0x%*.*" PRIx64, AddrSize * 2, AddrSize * 2, Value0);
DWARFFormValue::dumpAddress(OS << ' ', AddrSize, Value0);
break;
case dwarf::DW_RLE_start_length:
PrintRawEntry(OS, *this, AddrSize, DumpOpts);

View File

@ -284,7 +284,7 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
// Print the actual address rather than the offset.
uint64_t LowPC, HighPC, Index;
if (Die.getLowAndHighPC(LowPC, HighPC, Index))
OS << format("0x%016" PRIx64, HighPC);
DWARFFormValue::dumpAddress(OS, U->getAddressByteSize(), HighPC);
else
FormValue.dump(OS, DumpOpts);
}

View File

@ -358,10 +358,16 @@ bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
return !errorToBool(std::move(Err));
}
void DWARFFormValue::dumpAddress(raw_ostream &OS, uint8_t AddressSize,
uint64_t Address) {
uint8_t HexDigits = AddressSize * 2;
OS << format("0x%*.*" PRIx64, HexDigits, HexDigits, Address);
}
void DWARFFormValue::dumpSectionedAddress(raw_ostream &OS,
DIDumpOptions DumpOpts,
object::SectionedAddress SA) const {
OS << format("0x%016" PRIx64, SA.Address);
dumpAddress(OS, U->getAddressByteSize(), SA.Address);
dumpAddressSection(U->getContext().getDWARFObj(), OS, DumpOpts,
SA.SectionIndex);
}

View File

@ -13,12 +13,12 @@
# CHECK: DW_AT_stmt_list (0x00000000)
# CHECK: DW_AT_comp_dir ("/")
# CHECK: DW_AT_APPLE_optimized (true)
# CHECK: DW_AT_low_pc (0x0000000000000000)
# CHECK: DW_AT_high_pc (0x0000000000000008)
# CHECK: DW_AT_low_pc (0x00000000)
# CHECK: DW_AT_high_pc (0x00000008)
# CHECK: DW_TAG_subprogram
# CHECK: DW_AT_low_pc (0x0000000000000000)
# CHECK: DW_AT_high_pc (0x0000000000000008)
# CHECK: DW_AT_low_pc (0x00000000)
# CHECK: DW_AT_high_pc (0x00000008)
# CHECK: DW_AT_APPLE_omit_frame_ptr (true)
# CHECK: DW_AT_frame_base (DW_OP_reg13 SP)
# CHECK: DW_AT_name ("f")

View File

@ -4,7 +4,7 @@
# CHECK-LABEL: DW_TAG_GNU_call_site
# CHECK-NEXT: DW_AT_abstract_origin [DW_FORM_ref4] (cu + 0x[[BAR_ADDR:[0-9a-f]+]] => {0x{{0*}}[[BAR_ADDR]]} "bar")
# CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000008 ".text")
# CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x00000008 ".text")
--- |
; ModuleID = 'bundled-call-pr44001.ll'

View File

@ -22,7 +22,7 @@
;; Test mips, mipsel, mips64, mips64el:
; CHECK: DW_TAG_GNU_call_site
; CHECK-NEXT: DW_AT_abstract_origin {{.*}} "f1"
; CHECK-NEXT: DW_AT_low_pc (0x0000000000000010)
; CHECK-NEXT: DW_AT_low_pc (0x{{(00000000)?}}00000010)
; ModuleID = 'm.c'
source_filename = "m.c"

View File

@ -32,7 +32,7 @@
# Checking that we have two compile units with two sets of high/lo_pc.
# CHECK: .debug_info contents
# CHECK: DW_TAG_compile_unit
# CHECK: DW_AT_low_pc {{.*}} (0x0000000000000020 ".text")
# CHECK: DW_AT_low_pc {{.*}} (0x00000020 ".text")
# CHECK: DW_AT_high_pc
#
# CHECK: DW_TAG_subprogram
@ -51,7 +51,7 @@
# CHECK-NOT: DW_AT_location
#
# CHECK: DW_TAG_compile_unit
# CHECK: DW_AT_low_pc {{.*}} (0x0000000000000000 ".text")
# CHECK: DW_AT_low_pc {{.*}} (0x00000000 ".text")
# CHECK: DW_AT_high_pc
#
# CHECK: DW_TAG_subprogram

View File

@ -20,7 +20,7 @@
; DWARF4: DW_AT_GNU_dwo_name{{.*}}test.dwo
; DWARF4: DW_AT_GNU_addr_base{{.*}}0x00000000
; DWARF4: DW_TAG_GNU_call_site
; DWARF4: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000002) address = 0x0000000000000018 ".text")
; DWARF4: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000002) address = 0x00000018 ".text")
; DWARF4: .debug_addr contents:
; DWARF4-NEXT: Addrs: [
; DWARF4-NEXT: 0x00000000
@ -35,8 +35,8 @@
; DWARF5-NOT: DW_TAG_{{.*}}
; DWARF5: DW_AT_dwo_name{{.*}}test.dwo
; DWARF5: DW_AT_addr_base{{.*}}0x00000008
; DWARF5: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x0000000000000000 ".text")
; DWARF5: DW_AT_call_return_pc [DW_FORM_addrx] (indexed (00000002) address = 0x0000000000000018 ".text")
; DWARF5: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x00000000 ".text")
; DWARF5: DW_AT_call_return_pc [DW_FORM_addrx] (indexed (00000002) address = 0x00000018 ".text")
; DWARF5: .debug_addr contents:
; DWARF5-NEXT: 0x00000000: Address table header: length = 0x00000010, format = DWARF32, version = 0x0005, addr_size = 0x04, seg_size = 0x00
; DWARF5-NEXT: Addrs: [

View File

@ -26,8 +26,8 @@ b:
// DWARF: .debug_info contents:
// DWARF: DW_TAG_compile_unit
// DWARF-NOT: DW_TAG_
// DWARF: DW_AT_low_pc {{.*}}(0x0000000000000000)
// DWARF: DW_AT_high_pc {{.*}}(0x0000000000000004)
// DWARF: DW_AT_low_pc {{.*}}(0x00000000)
// DWARF: DW_AT_high_pc {{.*}}(0x00000004)
// DWARF: DW_TAG_label
// DWARF-NEXT: DW_AT_name {{.*}}("a")

View File

@ -20,8 +20,8 @@ b:
// DWARF: .debug_info contents:
// DWARF: DW_TAG_compile_unit
// DWARF-NOT: DW_TAG_
// DWARF: DW_AT_low_pc (0x0000000000000000)
// DWARF: DW_AT_high_pc (0x0000000000000004)
// DWARF: DW_AT_low_pc (0x00000000)
// DWARF: DW_AT_high_pc (0x00000004)
// DWARF: DW_TAG_label
// DWARF-NEXT: DW_AT_name ("b")

View File

@ -21,8 +21,8 @@ a:
// DWARF: .debug_info contents:
// DWARF: DW_TAG_compile_unit
// DWARF-NOT: DW_TAG_
// DWARF: DW_AT_low_pc (0x0000000000000000)
// DWARF: DW_AT_high_pc (0x0000000000000004)
// DWARF: DW_AT_low_pc (0x00000000)
// DWARF: DW_AT_high_pc (0x00000004)
// DWARF: DW_TAG_label
// DWARF-NEXT: DW_AT_name ("a")

View File

@ -37,8 +37,8 @@ _x: .long 1
// We don't check the leading addresses these are at.
// CHECK: DW_TAG_compile_unit
// CHECK: DW_AT_stmt_list (0x00000000)
// CHECK: DW_AT_low_pc (0x0000000000000000)
// CHECK: DW_AT_high_pc (0x0000000000000008)
// CHECK: DW_AT_low_pc (0x00000000)
// CHECK: DW_AT_high_pc (0x00000008)
// We don't check the file name as it is a temp directory
// CHECK: DW_AT_name
// We don't check the DW_AT_comp_dir which is the current working directory
@ -49,19 +49,19 @@ _x: .long 1
// CHECK: DW_AT_name ("bar")
// CHECK: DW_AT_decl_file ([[FILE:".*gen-dwarf.s"]])
// CHECK: DW_AT_decl_line (5)
// CHECK: DW_AT_low_pc (0x0000000000000000)
// CHECK: DW_AT_low_pc (0x00000000)
// CHECK: DW_TAG_label
// CHECK: DW_AT_name ("foo")
// CHECK: DW_AT_decl_file ([[FILE]])
// CHECK: DW_AT_decl_line (9)
// CHECK: DW_AT_low_pc (0x0000000000000007)
// CHECK: DW_AT_low_pc (0x00000007)
// CHECK: DW_TAG_label
// CHECK: DW_AT_name ("baz")
// CHECK: DW_AT_decl_file ([[FILE]])
// CHECK: DW_AT_decl_line (10)
// CHECK: DW_AT_low_pc (0x0000000000000007)
// CHECK: DW_AT_low_pc (0x00000007)
// CHECK: NULL

View File

@ -78,8 +78,8 @@ attributes #2 = { nounwind }
; CHECK-LABEL: DW_TAG_compile_unit
; CHECK-LABEL: DW_TAG_subprogram
; CHECK-NEXT: DW_AT_low_pc (0x0000000000000002)
; CHECK-NEXT: DW_AT_high_pc (0x0000000000000039)
; CHECK-NEXT: DW_AT_low_pc (0x00000002)
; CHECK-NEXT: DW_AT_high_pc (0x00000039)
; CHECK-NEXT: DW_AT_frame_base (DW_OP_WASM_location 0x0 0x1, DW_OP_stack_value)
; CHECK-NEXT: DW_AT_name ("foo")
; CHECK-NEXT: DW_AT_decl_file ("/s/llvm-upstream{{(/|\\)}}debugtest.c")
@ -102,8 +102,8 @@ attributes #2 = { nounwind }
; CHECK-NEXT: DW_AT_type (0x00000073 "int")
; CHECK-LABEL: DW_TAG_lexical_block
; CHECK-NEXT: DW_AT_low_pc (0x000000000000001c)
; CHECK-NEXT: DW_AT_high_pc (0x000000000000002d)
; CHECK-NEXT: DW_AT_low_pc (0x0000001c)
; CHECK-NEXT: DW_AT_high_pc (0x0000002d)
; CHECK-LABEL: DW_TAG_variable
; CHECK-NEXT: DW_AT_location (DW_OP_fbreg +4)

View File

@ -10,8 +10,8 @@
; CHECK-NEXT: DW_AT_stmt_list (0x00000000)
; CHECK-NEXT: DW_AT_comp_dir ("/usr/local/google/home/sbc/dev/wasm/simple")
; CHECK-NEXT: DW_AT_GNU_pubnames (true)
; CHECK-NEXT: DW_AT_low_pc (0x0000000000000002)
; CHECK-NEXT: DW_AT_high_pc (0x0000000000000004)
; CHECK-NEXT: DW_AT_low_pc (0x00000002)
; CHECK-NEXT: DW_AT_high_pc (0x00000004)
; CHECK: 0x00000026: DW_TAG_variable
; CHECK-NEXT: DW_AT_name ("foo")
@ -44,8 +44,8 @@
; CHECK-NEXT: DW_AT_prototyped (true)
; CHECK: 0x0000005a: DW_TAG_subprogram
; CHECK-NEXT: DW_AT_low_pc (0x0000000000000002)
; CHECK-NEXT: DW_AT_high_pc (0x0000000000000004)
; CHECK-NEXT: DW_AT_low_pc (0x00000002)
; CHECK-NEXT: DW_AT_high_pc (0x00000004)
; CHECK-NEXT: DW_AT_frame_base (DW_OP_WASM_location 0x3 0x0, DW_OP_stack_value)
; CHECK-NEXT: DW_AT_name ("f2")
; CHECK-NEXT: DW_AT_decl_file ("/usr/local/google/home/sbc/dev/wasm/simple{{[/\\]}}test.c")

View File

@ -5,13 +5,13 @@
# CHECK-NEXT: DW_AT_external (true)
# CHECK-NEXT: DW_AT_name ("fn4")
# CHECK-NEXT: DW_AT_linkage_name ("test")
# CHECK-NEXT: DW_AT_low_pc (0x0000000000000000)
# CHECK-NEXT: DW_AT_high_pc (0x0000000000000000)
# CHECK-NEXT: DW_AT_low_pc (0x00000000)
# CHECK-NEXT: DW_AT_high_pc (0x00000000)
# CHECK-NEXT: DW_AT_frame_base (DW_OP_call_frame_cfa)
# CHECK-NEXT: DW_AT_GNU_all_call_sites (true)
# CHECK: DW_TAG_GNU_call_site
# CHECK-NEXT: DW_AT_low_pc (0x0000000000000000)
# CHECK-NEXT: DW_AT_low_pc (0x00000000)
# CHECK-NEXT: DW_AT_abstract_origin (0x00000021 "test")
# CHECK: DW_TAG_GNU_call_site_parameter

View File

@ -13,11 +13,10 @@
# CHECK: DW_AT_ranges [DW_FORM_sec_offset] (0x00000000
# CHECK-NEXT: [0x00000042, 0x00000048))
# CHECK: DW_TAG_subprogram
# FIXME: Print address using unit's address size.
# CHECK: DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff (dead code))
# CHECK: DW_AT_low_pc [DW_FORM_addr] (0xffffffff (dead code))
# CHECK: DW_AT_high_pc [DW_FORM_data4] (0x00000006)
# CHECK: DW_TAG_subprogram
# CHECK: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000042)
# CHECK: DW_AT_low_pc [DW_FORM_addr] (0x00000042)
# CHECK: DW_AT_high_pc [DW_FORM_data4] (0x00000006)
# CHECK: DW_TAG_compile_unit
# CHECK: DW_AT_addr_base
@ -28,10 +27,10 @@
# CHECK-NEXT: [0x00000042, 0x00000048)
# CHECK-NEXT: [0x00000042, 0x00000048))
# CHECK: DW_TAG_subprogram
# CHECK: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x00000000ffffffff (dead code))
# CHECK: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0xffffffff (dead code))
# CHECK: DW_AT_high_pc [DW_FORM_data4] (0x00000006)
# CHECK: DW_TAG_subprogram
# CHECK: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000001) address = 0x0000000000000042)
# CHECK: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000001) address = 0x00000042)
# CHECK: DW_AT_high_pc [DW_FORM_data4] (0x00000006)
# CHECK: DW_TAG_compile_unit
# CHECK: DW_AT_ranges [DW_FORM_sec_offset] (0x00000018