llvm.org GIT mirror llvm / 9d26b0b
Improve behavior of DebugInfoEntryMinimal::getSubprogramName() introduced in r159512. To fetch a subprogram name we should not only inspect the DIE for this subprogram, but optionally inspect its specification, or its abstract origin (even if there is no inlining), or even specification of an abstract origin. Reviewed by Benjamin Kramer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160365 91177308-0d34-0410-b5e6-96231b3b80d8 Alexey Samsonov 7 years ago
6 changed file(s) with 44 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
154154 if (specifier.needs(DILineInfoSpecifier::FunctionName)) {
155155 const DWARFDebugInfoEntryMinimal *function_die =
156156 cu->getFunctionDIEForAddress(address);
157 if (function_die)
158 functionName = function_die->getSubprogramName(cu);
157 if (function_die) {
158 if (const char *name = function_die->getSubprogramName(cu))
159 functionName = name;
160 }
159161 }
160162 if (specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
161163 // Get the line table for this compile unit.
455455 return false;
456456 }
457457
458 static inline const char*
459 getSubprogramNameFromDie(const DWARFCompileUnit *cu,
460 const DWARFDebugInfoEntryMinimal *die) {
461 const char *result = 0;
462 if (!die->isNULL() && die->getTag() == DW_TAG_subprogram) {
463 // Try to get mangled name if possible.
464 result = die->getAttributeValueAsString(cu, DW_AT_MIPS_linkage_name, 0);
465 if (result == 0)
466 result = die->getAttributeValueAsString(cu, DW_AT_linkage_name, 0);
467 if (result == 0)
468 result = die->getAttributeValueAsString(cu, DW_AT_name, 0);
469 }
470 return result;
471 }
472
473458 const char*
474459 DWARFDebugInfoEntryMinimal::getSubprogramName(
475460 const DWARFCompileUnit *cu) const {
476461 if (isNULL() || getTag() != DW_TAG_subprogram)
477462 return 0;
478 const char *name = getSubprogramNameFromDie(cu, this);
479 if (name == 0) {
480 // Try to get name from specification DIE.
481 uint32_t ref = getAttributeValueAsReference(cu, DW_AT_specification, -1U);
482 if (ref != -1U) {
483 DWARFDebugInfoEntryMinimal spec_die;
484 if (spec_die.extract(cu, &ref))
485 name = getSubprogramNameFromDie(cu, &spec_die);
486 }
487 }
488 return name;
489 }
463 // Try to get mangled name if possible.
464 if (const char *name =
465 getAttributeValueAsString(cu, DW_AT_MIPS_linkage_name, 0))
466 return name;
467 if (const char *name = getAttributeValueAsString(cu, DW_AT_linkage_name, 0))
468 return name;
469 if (const char *name = getAttributeValueAsString(cu, DW_AT_name, 0))
470 return name;
471 // Try to get name from specification DIE.
472 uint32_t spec_ref =
473 getAttributeValueAsReference(cu, DW_AT_specification, -1U);
474 if (spec_ref != -1U) {
475 DWARFDebugInfoEntryMinimal spec_die;
476 if (spec_die.extract(cu, &spec_ref)) {
477 if (const char *name = spec_die.getSubprogramName(cu))
478 return name;
479 }
480 }
481 // Try to get name from abstract origin DIE.
482 uint32_t abs_origin_ref =
483 getAttributeValueAsReference(cu, DW_AT_abstract_origin, -1U);
484 if (abs_origin_ref != -1U) {
485 DWARFDebugInfoEntryMinimal abs_origin_die;
486 if (abs_origin_die.extract(cu, &abs_origin_ref)) {
487 if (const char *name = abs_origin_die.getSubprogramName(cu))
488 return name;
489 }
490 }
491 return 0;
492 }
131131 bool addressRangeContainsAddress(const DWARFCompileUnit *cu,
132132 const uint64_t address) const;
133133
134 // If a DIE represents a subroutine, returns its mangled name
135 // (or short name, if mangled is missing). Otherwise returns null.
134 // If a DIE represents a subprogram, returns its mangled name
135 // (or short name, if mangled is missing). This name may be fetched
136 // from specification or abstract origin for this subprogram.
137 // Returns null if no name is found.
136138 const char* getSubprogramName(const DWARFCompileUnit *cu) const;
137139 };
138140
77 RUN: --address=0x4004b8 --functions | FileCheck %s -check-prefix MANY_CU_1
88 RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test2.elf-x86-64 \
99 RUN: --address=0x4004c4 --functions | FileCheck %s -check-prefix MANY_CU_2
10 RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test3.elf-x86-64 \
11 RUN: --address=0x538 --functions | FileCheck %s -check-prefix ABS_ORIGIN_1
1012
1113 MAIN: main
1214 MAIN-NEXT: dwarfdump-test.cc:16:10
2224
2325 MANY_CU_2: main
2426 MANY_CU_2-NEXT: main.cc:4:0
27
28 ABS_ORIGIN_1: C
29 ABS_ORIGIN_1-NEXT: def.cc:3:0
None config.suffixes = ['.ll', '.c', '.cpp']
0 config.suffixes = ['.ll', '.c', '.cpp', '.test']