[dwarfdump] Resolve also variable specifications/abstract_origins.

DW_AT_specification and DW_AT_abstract_origin resolving was only performed
on subroutine DIEs because it used the getSubroutineName method. Introduce
a more generic getName() and use it to dump the reference attributes.

Testcases have been updated to check the printed names instead of the offsets
except when the name could be ambiguous.

Reviewers: dblaikie, samsonov

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D5625

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219506 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Frederic Riss 2014-10-10 15:51:02 +00:00
parent d62c4bac66
commit dd2cb9cae7
11 changed files with 68 additions and 55 deletions

View File

@ -66,11 +66,15 @@ class DIInliningInfo {
}
};
/// A DINameKind is passed to name search methods to specify a
/// preference regarding the type of name resolution the caller wants.
enum class DINameKind { None, ShortName, LinkageName };
/// DILineInfoSpecifier - controls which fields of DILineInfo container
/// should be filled with data.
struct DILineInfoSpecifier {
enum class FileLineInfoKind { None, Default, AbsoluteFilePath };
enum class FunctionNameKind { None, ShortName, LinkageName };
typedef DINameKind FunctionNameKind;
FileLineInfoKind FLIKind;
FunctionNameKind FNKind;

View File

@ -18,7 +18,6 @@
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
using namespace dwarf;
typedef DILineInfoSpecifier::FunctionNameKind FunctionNameKind;
// Small helper to extract a DIE pointed by a reference
// attribute. It looks up the Unit containing the DIE and calls
@ -129,8 +128,7 @@ void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS,
uint32_t Ref = formValue.getAsReference(u).getValue();
DWARFDebugInfoEntryMinimal DIE;
if (const DWARFUnit *RefU = findUnitAndExtractFast(DIE, u, &Ref))
if (const char *Ref = DIE.getSubroutineName(RefU,
FunctionNameKind::LinkageName))
if (const char *Ref = DIE.getName(RefU, DINameKind::LinkageName))
OS << " \"" << Ref << '\"';
}
@ -331,11 +329,19 @@ bool DWARFDebugInfoEntryMinimal::addressRangeContainsAddress(
const char *
DWARFDebugInfoEntryMinimal::getSubroutineName(const DWARFUnit *U,
FunctionNameKind Kind) const {
if (!isSubroutineDIE() || Kind == FunctionNameKind::None)
DINameKind Kind) const {
if (!isSubroutineDIE())
return nullptr;
return getName(U, Kind);
}
const char *
DWARFDebugInfoEntryMinimal::getName(const DWARFUnit *U,
DINameKind Kind) const {
if (Kind == DINameKind::None)
return nullptr;
// Try to get mangled name only if it was asked for.
if (Kind == FunctionNameKind::LinkageName) {
if (Kind == DINameKind::LinkageName) {
if (const char *name =
getAttributeValueAsString(U, DW_AT_MIPS_linkage_name, nullptr))
return name;
@ -351,7 +357,7 @@ DWARFDebugInfoEntryMinimal::getSubroutineName(const DWARFUnit *U,
if (spec_ref != -1U) {
DWARFDebugInfoEntryMinimal spec_die;
if (const DWARFUnit *RefU = findUnitAndExtractFast(spec_die, U, &spec_ref)) {
if (const char *name = spec_die.getSubroutineName(RefU, Kind))
if (const char *name = spec_die.getName(RefU, Kind))
return name;
}
}
@ -362,7 +368,7 @@ DWARFDebugInfoEntryMinimal::getSubroutineName(const DWARFUnit *U,
DWARFDebugInfoEntryMinimal abs_origin_die;
if (const DWARFUnit *RefU = findUnitAndExtractFast(abs_origin_die, U,
&abs_origin_ref)) {
if (const char *name = abs_origin_die.getSubroutineName(RefU, Kind))
if (const char *name = abs_origin_die.getName(RefU, Kind))
return name;
}
}

View File

@ -125,9 +125,12 @@ public:
/// returns its mangled name (or short name, if mangled is missing).
/// This name may be fetched from specification or abstract origin
/// for this subprogram. Returns null if no name is found.
const char *
getSubroutineName(const DWARFUnit *U,
DILineInfoSpecifier::FunctionNameKind Kind) const;
const char *getSubroutineName(const DWARFUnit *U, DINameKind Kind) const;
/// Return the DIE name resolving DW_AT_sepcification or
/// DW_AT_abstract_origin references if necessary.
/// Returns null if no name is found.
const char *getName(const DWARFUnit *U, DINameKind Kind) const;
/// Retrieves values of DW_AT_call_file, DW_AT_call_line and
/// DW_AT_call_column from DIE (or zeroes if they are missing).

View File

@ -14,7 +14,7 @@
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "C"
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: [[C_DTOR_DECL:.*]]: DW_TAG_subprogram
; CHECK: DW_TAG_subprogram
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "~C"
@ -22,7 +22,7 @@
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_MIPS_linkage_name {{.*}} "_ZN1CD1Ev"
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: [[D1_THIS_ABS:.*]]: DW_TAG_formal_parameter
; CHECK: DW_TAG_formal_parameter
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "this"
@ -36,7 +36,7 @@
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: DW_TAG_formal_parameter
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_abstract_origin {{.*}} {[[D1_THIS_ABS]]}
; CHECK: DW_AT_abstract_origin {{.*}} "this"
; FIXME: D2 is actually inlined into D1 but doesn't show up here, possibly due
; to there being no work in D2 (calling another member function from the dtor

View File

@ -53,7 +53,7 @@
; CHECK: DW_AT_abstract_origin {{.*}} "_ZN17nsAutoRefCntD1Ev"
; CHECK: DW_TAG_formal_parameter
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_abstract_origin {{.*}} {[[D1_THIS_ABS]]}
; CHECK: DW_AT_abstract_origin {{.*}} {[[D1_THIS_ABS]]} "this"
; CHECK: DW_TAG_inlined_subroutine
; CHECK-NEXT: DW_AT_abstract_origin {{.*}} "_ZN17nsAutoRefCntD2Ev"

View File

@ -9,18 +9,18 @@
; CHECK: DW_AT_abstract_origin {{.*}} "foo"
; CHECK: DW_TAG_formal_parameter
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_abstract_origin {{.*}}{[[ABS_SP:.*]]}
; CHECK: DW_AT_abstract_origin {{.*}} "sp"
; CHECK: DW_TAG_formal_parameter
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_abstract_origin {{.*}}{[[ABS_NUMS:.*]]}
; CHECK: DW_AT_abstract_origin {{.*}} "nums"
; CHECK: DW_TAG_subprogram
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "foo"
; CHECK: [[ABS_SP]]: DW_TAG_formal_parameter
; CHECK: DW_TAG_formal_parameter
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "sp"
; CHECK: [[ABS_NUMS]]: DW_TAG_formal_parameter
; CHECK: DW_TAG_formal_parameter
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "nums"
@ -34,9 +34,9 @@
;CHECK: DW_TAG_formal_parameter
;FIXME: Linux shouldn't drop this parameter either...
;CHECK-NOT: DW_TAG
;DARWIN: DW_AT_abstract_origin {{.*}}{[[ABS_SP]]}
;DARWIN: DW_AT_abstract_origin {{.*}} "sp"
;DARWIN: DW_TAG_formal_parameter
;CHECK: DW_AT_abstract_origin {{.*}}{[[ABS_NUMS]]}
;CHECK: DW_AT_abstract_origin {{.*}} "nums"
;CHECK-NOT: DW_TAG_formal_parameter
%struct.S1 = type { float*, i32 }

View File

@ -97,7 +97,7 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
; PRESENT: .debug_info contents:
; PRESENT: DW_TAG_class_type
; PRESENT-NEXT: DW_AT_name {{.*}} "C"
; PRESENT: 0x[[DECL_A:[0-9a-f]+]]: DW_TAG_member
; PRESENT: DW_TAG_member
; PRESENT-NEXT: DW_AT_name {{.*}} "a"
; PRESENT: DW_AT_external
; PRESENT: DW_AT_declaration
@ -108,14 +108,14 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
; PRESENT: DW_AT_declaration
; PRESENT: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_private)
; PRESENT: DW_AT_const_value {{.*}} (1)
; PRESENT: 0x[[DECL_B:[0-9a-f]+]]: DW_TAG_member
; PRESENT: DW_TAG_member
; PRESENT-NEXT: DW_AT_name {{.*}} "b"
; PRESENT: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_protected)
; PRESENT: DW_TAG_member
; PRESENT-NEXT: DW_AT_name {{.*}} "const_b"
; PRESENT: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_protected)
; PRESENT: DW_AT_const_value [DW_FORM_udata] (1078523331)
; PRESENT: 0x[[DECL_C:[0-9a-f]+]]: DW_TAG_member
; PRESENT: DW_TAG_member
; PRESENT-NEXT: DW_AT_name {{.*}} "c"
; PRESENT: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_public)
; PRESENT: DW_TAG_member
@ -131,15 +131,15 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
; PRESENT: NULL
; Definitions point back to their declarations, and have a location.
; PRESENT: DW_TAG_variable
; PRESENT-NEXT: DW_AT_specification {{.*}} {0x[[DECL_A]]}
; PRESENT-NEXT: DW_AT_specification {{.*}} "a"
; PRESENT-NEXT: DW_AT_location
; PRESENT-NEXT: DW_AT_linkage_name {{.*}} "_ZN1C1aE"
; PRESENT: DW_TAG_variable
; PRESENT-NEXT: DW_AT_specification {{.*}} {0x[[DECL_B]]}
; PRESENT-NEXT: DW_AT_specification {{.*}} "b"
; PRESENT-NEXT: DW_AT_location
; PRESENT-NEXT: DW_AT_linkage_name {{.*}} "_ZN1C1bE"
; PRESENT: DW_TAG_variable
; PRESENT-NEXT: DW_AT_specification {{.*}} {0x[[DECL_C]]}
; PRESENT-NEXT: DW_AT_specification {{.*}} "c"
; PRESENT-NEXT: DW_AT_location
; PRESENT-NEXT: DW_AT_linkage_name {{.*}} "_ZN1C1cE"
@ -147,7 +147,7 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
; DARWINP: .debug_info contents:
; DARWINP: DW_TAG_class_type
; DARWINP-NEXT: DW_AT_name {{.*}} "C"
; DARWINP: 0x[[DECL_A:[0-9a-f]+]]: DW_TAG_member
; DARWINP: DW_TAG_member
; DARWINP-NEXT: DW_AT_name {{.*}} "a"
; DARWINP: DW_AT_external
; DARWINP: DW_AT_declaration
@ -158,14 +158,14 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
; DARWINP: DW_AT_declaration
; DARWINP: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_private)
; DARWINP: DW_AT_const_value {{.*}} (1)
; DARWINP: 0x[[DECL_B:[0-9a-f]+]]: DW_TAG_member
; DARWINP: DW_TAG_member
; DARWINP-NEXT: DW_AT_name {{.*}} "b"
; DARWINP: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_protected)
; DARWINP: DW_TAG_member
; DARWINP-NEXT: DW_AT_name {{.*}} "const_b"
; DARWINP: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_protected)
; DARWINP: DW_AT_const_value [DW_FORM_udata] (1078523331)
; DARWINP: 0x[[DECL_C:[0-9a-f]+]]: DW_TAG_member
; DARWINP: DW_TAG_member
; DARWINP-NEXT: DW_AT_name {{.*}} "c"
; DARWINP: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_public)
; DARWINP: DW_TAG_member
@ -181,15 +181,15 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
; DARWINP: NULL
; Definitions point back to their declarations, and have a location.
; DARWINP: DW_TAG_variable
; DARWINP-NEXT: DW_AT_specification {{.*}} {0x[[DECL_A]]}
; DARWINP-NEXT: DW_AT_specification {{.*}} "a"
; DARWINP-NEXT: DW_AT_location
; DARWINP-NEXT: DW_AT_linkage_name {{.*}} "_ZN1C1aE"
; DARWINP: DW_TAG_variable
; DARWINP-NEXT: DW_AT_specification {{.*}} {0x[[DECL_B]]}
; DARWINP-NEXT: DW_AT_specification {{.*}} "b"
; DARWINP-NEXT: DW_AT_location
; DARWINP-NEXT: DW_AT_linkage_name {{.*}} "_ZN1C1bE"
; DARWINP: DW_TAG_variable
; DARWINP-NEXT: DW_AT_specification {{.*}} {0x[[DECL_C]]}
; DARWINP-NEXT: DW_AT_specification {{.*}} "c"
; DARWINP-NEXT: DW_AT_location
; DARWINP-NEXT: DW_AT_linkage_name {{.*}} "_ZN1C1cE"

View File

@ -52,7 +52,7 @@
; CHECK: [[C:0x[0-9a-f]+]]: DW_TAG_structure_type
; CHECK-NEXT: DW_AT_name {{.*}} "C"
; CHECK: [[STATIC_MEM_DECL:0x[0-9a-f]+]]: DW_TAG_member
; CHECK: DW_TAG_member
; CHECK-NEXT: DW_AT_name {{.*}} "static_member_variable"
; CHECK: DW_TAG_subprogram
@ -67,7 +67,7 @@
; CHECK-NEXT: DW_AT_name {{.*}} "int"
; CHECK: [[STATIC_MEM_VAR:0x[0-9a-f]+]]: DW_TAG_variable
; CHECK-NEXT: DW_AT_specification {{.*}} {[[STATIC_MEM_DECL]]}
; CHECK-NEXT: DW_AT_specification {{.*}} "static_member_variable"
; CHECK: [[GLOB_VAR:0x[0-9a-f]+]]: DW_TAG_variable
; CHECK-NEXT: DW_AT_name {{.*}} "global_variable"
@ -75,10 +75,10 @@
; CHECK: [[NS:0x[0-9a-f]+]]: DW_TAG_namespace
; CHECK-NEXT: DW_AT_name {{.*}} "ns"
; CHECK: [[GLOB_NS_VAR_DECL:0x[0-9a-f]+]]: DW_TAG_variable
; CHECK: DW_TAG_variable
; CHECK-NEXT: DW_AT_name {{.*}} "global_namespace_variable"
; CHECK: [[D_VAR_DECL:0x[0-9a-f]+]]: DW_TAG_variable
; CHECK: DW_TAG_variable
; CHECK-NEXT: DW_AT_name {{.*}} "d"
; CHECK: [[D:0x[0-9a-f]+]]: DW_TAG_structure_type
@ -91,10 +91,10 @@
; CHECK: DW_AT_name {{.*}} "global_namespace_function"
; CHECK: [[GLOB_NS_VAR:0x[0-9a-f]+]]: DW_TAG_variable
; CHECK-NEXT: DW_AT_specification {{.*}} {[[GLOB_NS_VAR_DECL]]}
; CHECK-NEXT: DW_AT_specification {{.*}} "_ZN2ns25global_namespace_variableE"
; CHECK: [[D_VAR:0x[0-9a-f]+]]: DW_TAG_variable
; CHECK-NEXT: DW_AT_specification {{.*}} {[[D_VAR_DECL]]}
; CHECK-NEXT: DW_AT_specification {{.*}} "_ZN2ns1dE"
; CHECK: DW_TAG_subprogram
; CHECK-NOT: DW_TAG
@ -116,7 +116,7 @@
; CHECK: [[OUTER_ANON:.*]]: DW_TAG_namespace
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK-NOT: DW_AT_name
; CHECK: [[OUTER_ANON_C_DECL:.*]]: DW_TAG_variable
; CHECK: DW_TAG_variable
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "c"
; CHECK-NOT: {{DW_TAG|NULL}}
@ -131,7 +131,7 @@
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: [[OUTER_ANON_C:.*]]: DW_TAG_variable
; CHECK-NOT: DW_TAG
; CHECK-NEXT: DW_AT_specification {{.*}} {[[OUTER_ANON_C_DECL]]}
; CHECK-NEXT: DW_AT_specification {{.*}} "_ZN5outer12_GLOBAL__N_11cE"
; CHECK: [[ANON:.*]]: DW_TAG_namespace
; CHECK-NOT: DW_AT_name
@ -139,13 +139,13 @@
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "inner"
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: [[ANON_INNER_B_DECL:.*]]: DW_TAG_variable
; CHECK: DW_TAG_variable
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "b"
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: NULL
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: [[ANON_I_DECL:.*]]: DW_TAG_variable
; CHECK: DW_TAG_variable
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "i"
; CHECK-NOT: {{DW_TAG|NULL}}
@ -153,10 +153,10 @@
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: [[ANON_INNER_B:.*]]: DW_TAG_variable
; CHECK-NOT: DW_TAG
; CHECK-NEXT: DW_AT_specification {{.*}} {[[ANON_INNER_B_DECL]]}
; CHECK-NEXT: DW_AT_specification {{.*}} "_ZN12_GLOBAL__N_15inner1bE"
; CHECK: [[ANON_I:.*]]: DW_TAG_variable
; CHECK-NOT: DW_TAG
; CHECK-NEXT: DW_AT_specification {{.*}} {[[ANON_I_DECL]]}
; CHECK-NEXT: DW_AT_specification {{.*}} "_ZN12_GLOBAL__N_11iE"
; CHECK: [[MEM_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
; CHECK-NOT: DW_TAG

View File

@ -27,7 +27,7 @@
; CHECK: DW_TAG_inlined_subroutine
; CHECK: DW_AT_abstract_origin {{.*}}[[ABS_FUNC:........]] "_Z4funci"
; CHECK: DW_TAG_formal_parameter
; CHECK: DW_AT_abstract_origin {{.*}}[[ABS_VAR:........]])
; CHECK: DW_AT_abstract_origin {{.*}}[[ABS_VAR:........]] "x"
; Check the abstract definition is in the 'b.cpp' CU and doesn't contain any
; concrete information (address range or variable location)
@ -50,7 +50,7 @@
; CHECK: DW_AT_abstract_origin {{.*}} {0x[[ABS_FUNC]]} "_Z4funci"
; CHECK: DW_TAG_formal_parameter
; CHECK: DW_AT_location
; CHECK: DW_AT_abstract_origin {{.*}} {0x[[ABS_VAR]]}
; CHECK: DW_AT_abstract_origin {{.*}} {0x[[ABS_VAR]]} "x"
@i = external global i32

View File

@ -41,13 +41,13 @@
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "x"
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: [[ABS_B:.*]]: DW_TAG_formal_parameter
; CHECK: DW_TAG_formal_parameter
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "b"
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: DW_TAG_lexical_block
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: [[ABS_S:.*]]: DW_TAG_variable
; CHECK: DW_TAG_variable
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}} "s"
@ -61,7 +61,7 @@
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: DW_TAG_formal_parameter
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_abstract_origin {{.*}} {[[ABS_B]]}
; CHECK: DW_AT_abstract_origin {{.*}} "b"
; Notice 'x's local variable 's' is missing. Not necessarily a bug here,
; since it's been optimized entirely away and it should be described in
; abstract subprogram.
@ -85,14 +85,14 @@
; fastisel succeeds).
; CHECK: DW_TAG_formal_parameter
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_abstract_origin {{.*}} {[[ABS_B]]}
; CHECK: DW_AT_abstract_origin {{.*}} "b"
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: DW_TAG_lexical_block
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK: DW_TAG_variable
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_abstract_origin {{.*}} {[[ABS_S]]}
; CHECK: DW_AT_abstract_origin {{.*}} "s"
@t = external global i32

View File

@ -19,7 +19,7 @@
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_MIPS_linkage_name {{.*}} "_ZN2ns4funcEi"
; CHECK-NOT: DW_TAG
; CHECK: [[ABS_PRM:0x.*]]: DW_TAG_formal_parameter
; CHECK: DW_TAG_formal_parameter
; CHECK: NULL
; CHECK-NOT: NULL
; CHECK: DW_TAG_subprogram
@ -27,7 +27,7 @@
; CHECK: DW_AT_abstract_origin {{.*}} "_ZN2ns4funcEi"
; CHECK-NOT: DW_TAG
; CHECK: DW_TAG_formal_parameter
; CHECK: DW_AT_abstract_origin {{.*}} {[[ABS_PRM]]}
; CHECK: DW_AT_abstract_origin {{.*}} "i"
; CHECK: NULL
; CHECK: NULL
; CHECK: NULL