Skip to content

Commit

Permalink
[llvm-dwarfdump] Print type names in DW_AT_type DIEs
Browse files Browse the repository at this point in the history
This patch adds printing for DW_AT_type DIEs like it is already the case
for DW_AT_specification DIEs. This is a rather naive approach and only a
start. We should have pretty printers for different languages.

Differential revision: https://reviews.llvm.org/D36993

llvm-svn: 315297
  • Loading branch information
JDevlieghere committed Oct 10, 2017
1 parent 2152467 commit 2eb95c3
Show file tree
Hide file tree
Showing 22 changed files with 138 additions and 76 deletions.
62 changes: 62 additions & 0 deletions llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,64 @@ static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue,
}
}

/// Dump the name encoded in the type tag.
static void dumpTypeTagName(raw_ostream &OS, dwarf::Tag T) {
StringRef TagStr = TagString(T);
if (!TagStr.startswith("DW_TAG_") || !TagStr.endswith("_type"))
return;
OS << TagStr.substr(7, TagStr.size() - 12) << " ";
}

/// Recursively dump the DIE type name when applicable.
static void dumpTypeName(raw_ostream &OS, const DWARFDie &Die) {
DWARFDie D = Die.getAttributeValueAsReferencedDie(DW_AT_type);

if (!D.isValid())
return;

if (const char *Name = D.getName(DINameKind::LinkageName)) {
OS << Name;
return;
}

// FIXME: We should have pretty printers per language. Currently we print
// everything as if it was C++ and fall back to the TAG type name.
const dwarf::Tag T = D.getTag();
switch (T) {
case DW_TAG_array_type:
case DW_TAG_pointer_type:
case DW_TAG_ptr_to_member_type:
case DW_TAG_reference_type:
case DW_TAG_rvalue_reference_type:
break;
default:
dumpTypeTagName(OS, T);
}

// Follow the DW_AT_type if possible.
dumpTypeName(OS, D);

switch (T) {
case DW_TAG_array_type:
OS << "[]";
break;
case DW_TAG_pointer_type:
OS << '*';
break;
case DW_TAG_ptr_to_member_type:
OS << '*';
break;
case DW_TAG_reference_type:
OS << '&';
break;
case DW_TAG_rvalue_reference_type:
OS << "&&";
break;
default:
break;
}
}

static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
uint32_t *OffsetPtr, dwarf::Attribute Attr,
dwarf::Form Form, unsigned Indent,
Expand Down Expand Up @@ -188,6 +246,10 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
if (const char *Name = Die.getAttributeValueAsReferencedDie(Attr).getName(
DINameKind::LinkageName))
OS << " \"" << Name << '\"';
} else if (Attr == DW_AT_type) {
OS << " \"";
dumpTypeName(OS, Die);
OS << '"';
} else if (Attr == DW_AT_APPLE_property_attribute) {
if (Optional<uint64_t> OptVal = formValue.getAsUnsignedConstant())
dumpApplePropertyAttribute(OS, *OptVal);
Expand Down
10 changes: 5 additions & 5 deletions llvm/test/DebugInfo/AMDGPU/pointer-address-space.ll
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@
; CHECK: DW_AT_name {{.*}}"FuncVar0"
; CHECK-NEXT: DW_AT_decl_file
; CHECK-NEXT: DW_AT_decl_line
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[a-f0-9]+}} => {0x[[NONE:[a-f0-9]+]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[a-f0-9]+}} => {0x[[NONE:[a-f0-9]+]]}

; CHECK: DW_AT_name {{.*}}"FuncVar1"
; CHECK-NEXT: DW_AT_decl_file
; CHECK-NEXT: DW_AT_decl_line
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[a-f0-9]+}} => {0x[[NONE]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[a-f0-9]+}} => {0x[[NONE]]}

; CHECK: DW_AT_name {{.*}}"FuncVar2"
; CHECK-NEXT: DW_AT_decl_file
; CHECK-NEXT: DW_AT_decl_line
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[a-f0-9]+}} => {0x[[LOCAL:[a-f0-9]+]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[a-f0-9]+}} => {0x[[LOCAL:[a-f0-9]+]]}

; CHECK: DW_AT_name {{.*}}"FuncVar3"
; CHECK-NEXT: DW_AT_decl_file
; CHECK-NEXT: DW_AT_decl_line
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[a-f0-9]+}} => {0x[[PRIVATE:[a-f0-9]+]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[a-f0-9]+}} => {0x[[PRIVATE:[a-f0-9]+]]}

; CHECK: DW_AT_name {{.*}}"FuncVar4"
; CHECK-NEXT: DW_AT_decl_file
; CHECK-NEXT: DW_AT_decl_line
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[a-f0-9]+}} => {0x[[NONE]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[a-f0-9]+}} => {0x[[NONE]]}

; CHECK: 0x[[NONE]]: DW_TAG_pointer_type
; CHECK-NEXT: DW_AT_type
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/Generic/cross-cu-inlining.ll
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
; CHECK: DW_TAG_compile_unit
; CHECK: DW_AT_name {{.*}} "a.cpp"
; CHECK: DW_TAG_subprogram
; CHECK: DW_AT_type [DW_FORM_ref_addr] (0x00000000[[INT:.*]])
; CHECK: DW_AT_type [DW_FORM_ref_addr] (0x00000000[[INT:[a-f0-9]+]]
; CHECK: 0x[[INLINED:[0-9a-f]*]]:{{.*}}DW_TAG_inlined_subroutine
; CHECK: DW_AT_abstract_origin {{.*}}[[ABS_FUNC:........]] "_Z4funci"
; CHECK: DW_TAG_formal_parameter
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/Generic/enum-types.ll
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
; CHECK: DW_TAG_subprogram
; CHECK: DW_AT_MIPS_linkage_name {{.*}} "_Z4topA2EA"
; CHECK: DW_TAG_formal_parameter
; CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x{{.*}} => {0x[[ENUM]]})
; CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x{{.*}} => {0x[[ENUM]]}

; CHECK: DW_TAG_compile_unit
; CHECK: DW_TAG_subprogram
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/Generic/member-pointers.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
; RUN: llvm-dwarfdump -v -debug-info %t | FileCheck %s
; CHECK: DW_TAG_ptr_to_member_type
; CHECK: DW_TAG_ptr_to_member_type
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE:0x[0-9a-f]+]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE:0x[0-9a-f]+]]}
; CHECK: [[TYPE]]: DW_TAG_subroutine_type
; CHECK: DW_TAG_formal_parameter
; CHECK-NEXT: DW_AT_type
Expand Down
10 changes: 5 additions & 5 deletions llvm/test/DebugInfo/Generic/tu-composite.ll
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@
; CHECK-NEXT: DW_AT_name [DW_FORM_strp] {{.*}}= "virt<bar>")
; Make sure we correctly handle type of a template_type being a type identifier.
; CHECK: DW_TAG_template_type_parameter
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE2]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE2]]}
; CHECK-NEXT: DW_AT_name [DW_FORM_strp] {{.*}}= "T")
; Make sure we correctly handle derived-from of a typedef being a type identifier.
; CHECK: DW_TAG_typedef
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE2]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE2]]}
; CHECK: DW_AT_name [DW_FORM_strp] {{.*}}= "baz2")
; Make sure we correctly handle derived-from of a pointer type being a type identifier.
; CHECK: DW_TAG_pointer_type
; CHECK: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE]]})
; CHECK: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE]]}
; CHECK: DW_TAG_typedef
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE2]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE2]]}
; CHECK: DW_AT_name [DW_FORM_strp] {{.*}}= "baz")
; Make sure we correctly handle derived-from of an array type being a type identifier.
; CHECK: DW_TAG_array_type
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE2]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE2]]}
; IR generated from clang -g with the following source:
; struct C {
; virtual void foo();
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/Generic/tu-member-pointer.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
; RUN: %llc_dwarf -filetype=obj -O0 < %s > %t
; RUN: llvm-dwarfdump -v -debug-info %t | FileCheck %s
; CHECK: DW_TAG_ptr_to_member_type
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE:0x[0-9a-f]+]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} => {[[TYPE:0x[0-9a-f]+]]}
; CHECK: [[TYPE]]: DW_TAG_base_type
; IR generated from clang -g with the following source:
; struct Foo {
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/X86/default-subrange-array.ll
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ source_filename = "test/DebugInfo/X86/default-subrange-array.ll"
; CHECK: DW_TAG_class_type
; CHECK: DW_TAG_member
; CHECK-NEXT: DW_AT_name {{.*}} "x"
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] {{.*}} => {[[ARRAY:0x[0-9a-f]+]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] {{.*}} => {[[ARRAY:0x[0-9a-f]+]]}

; CHECK: [[ARRAY]]: DW_TAG_array_type
; CHECK-NEXT: DW_AT_type
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/DebugInfo/X86/empty-array.ll
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ source_filename = "test/DebugInfo/X86/empty-array.ll"
; CHECK: DW_TAG_class_type
; CHECK: DW_TAG_member
; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x{{[0-9a-f]*}}] = "x")
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[ARRAY:0x[0-9a-f]*]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[ARRAY:0x[0-9a-f]*]]}

; CHECK: [[ARRAY]]: DW_TAG_array_type [{{.*}}] *
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASETYPE:0x[0-9a-f]*]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASETYPE:0x[0-9a-f]*]]}

; CHECK: DW_TAG_subrange_type
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASE2:0x[0-9a-f]*]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASE2:0x[0-9a-f]*]]}
; CHECK-NOT: DW_AT_upper_bound

; CHECK: [[BASETYPE]]: DW_TAG_base_type
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/X86/fission-cu.ll
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ source_filename = "test/DebugInfo/X86/fission-cu.ll"
; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x1f1f859683d49324)
; CHECK: DW_TAG_variable
; CHECK: DW_AT_name [DW_FORM_GNU_str_index] ( indexed (00000003) string = "a")
; CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[TYPE:0x[0-9a-f]*]]})
; CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[TYPE:0x[0-9a-f]*]]}
; CHECK: DW_AT_external [DW_FORM_flag_present] (true)
; CHECK: DW_AT_decl_file [DW_FORM_data1] (0x01)
; CHECK: DW_AT_decl_line [DW_FORM_data1] (1)
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/DebugInfo/X86/nondefault-subrange-array.ll
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ source_filename = "test/DebugInfo/X86/nondefault-subrange-array.ll"
; CHECK: DW_TAG_class_type
; CHECK: DW_TAG_member
; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x{{[0-9a-f]*}}] = "x")
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[ARRAY:0x[0-9a-f]*]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[ARRAY:0x[0-9a-f]*]]}

; CHECK: [[ARRAY]]: DW_TAG_array_type [{{.*}}] *
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASE:0x[0-9a-f]*]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASE:0x[0-9a-f]*]]}

; CHECK: DW_TAG_subrange_type
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASE2:0x[0-9a-f]*]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASE2:0x[0-9a-f]*]]}
; CHECK-NEXT: DW_AT_lower_bound [DW_FORM_data8] (0xfffffffffffffffd)
; CHECK-NEXT: DW_AT_count [DW_FORM_data1] (0x2a)

Expand Down
4 changes: 2 additions & 2 deletions llvm/test/DebugInfo/X86/ref_addr_relocation.ll
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
; CHECK-DWARF: 0x[[ADDR:.*]]: DW_TAG_structure_type
; CHECK-DWARF: DW_TAG_compile_unit
; CHECK-DWARF: DW_TAG_variable
; CHECK-DWARF: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[ADDR]])
; CHECK-DWARF: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[ADDR]]

; CHECK-DWARF2: DW_TAG_compile_unit
; CHECK-DWARF2: DW_TAG_variable
; CHECK-DWARF2: DW_AT_type [DW_FORM_ref4] {{.*}} => {[[ADDR:.*]]})
; CHECK-DWARF2: DW_AT_type [DW_FORM_ref4] {{.*}} => {[[ADDR:.*]]}
; CHECK-DWARF2: [[ADDR]]: DW_TAG_structure_type

source_filename = "test/DebugInfo/X86/ref_addr_relocation.ll"
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/DebugInfo/X86/subrange-type.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

; Make sure that the base type from the subrange type has a name.
; CHECK: DW_TAG_subrange_type
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]+}} => {[[SUBTYPE:0x[0-9a-f]*]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]+}} => {[[SUBTYPE:0x[0-9a-f]*]]}
; CHECK: [[SUBTYPE]]: DW_TAG_base_type
; CHECK-NEXT: DW_AT_name

Expand Down
4 changes: 2 additions & 2 deletions llvm/test/DebugInfo/dwarfdump-type-units.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ CHECK: debug_info contents:

CHECK: DW_TAG_variable
CHECK-NEXT: DW_AT_name {{.*}}"f"
CHECK: DW_AT_type [DW_FORM_ref_sig8] ([[FOO_SIG:0x[0-9a-f]*]])
CHECK: DW_AT_type [DW_FORM_ref_sig8] ([[FOO_SIG:0x[0-9a-f]*]]

CHECK: DW_TAG_variable
CHECK-NEXT: DW_AT_name {{.*}}"b"
CHECK: DW_AT_type [DW_FORM_ref_sig8] ([[BAR_SIG:0x[0-9a-f]*]])
CHECK: DW_AT_type [DW_FORM_ref_sig8] ([[BAR_SIG:0x[0-9a-f]*]]


CHECK: debug_types contents:
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Linker/Inputs/type-unique-simple2-a.ll
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

; CHECK: DW_TAG_compile_unit
; CHECK: DW_TAG_formal_parameter
; CHECK: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[INT]])
; CHECK: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[INT]]
; CHECK: DW_TAG_variable
; CHECK: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[BASE]])
; CHECK: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[BASE]]

; Make sure llvm-link only generates a single copy of the struct.
; LINK: DW_TAG_structure_type
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Linker/type-unique-simple-a.ll
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

; CHECK: DW_TAG_compile_unit
; CHECK: DW_TAG_formal_parameter
; CHECK: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[INT]])
; CHECK: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[INT]]
; CHECK: DW_TAG_variable
; CHECK: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[BASE]])
; CHECK: DW_AT_type [DW_FORM_ref_addr] {{.*}}[[BASE]]

; Make sure llvm-link only generates a single copy of the struct.
; LINK: DW_TAG_structure_type
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Linker/type-unique-type-array-a.ll
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
; CHECK: DW_AT_name {{.*}} "testA"
; CHECK: DW_TAG_formal_parameter
; CHECK: DW_TAG_formal_parameter
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{.*}} => {0x[[STRUCT:.*]]})
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{.*}} => {0x[[STRUCT:.*]]}
; CHECK: 0x[[STRUCT]]: DW_TAG_structure_type
; CHECK-NEXT: DW_AT_name {{.*}} "SA"

Expand Down
Loading

0 comments on commit 2eb95c3

Please sign in to comment.