From 9d26b0ba06479d9debadebce19344169f72407dd Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Tue, 17 Jul 2012 15:28:35 +0000 Subject: [PATCH] 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 --- lib/DebugInfo/DWARFContext.cpp | 6 ++- lib/DebugInfo/DWARFDebugInfoEntry.cpp | 51 +++++++++--------- lib/DebugInfo/DWARFDebugInfoEntry.h | 6 ++- .../Inputs/dwarfdump-test3.elf-x86-64 | Bin 0 -> 6794 bytes test/DebugInfo/dwarfdump-test.test | 5 ++ test/DebugInfo/lit.local.cfg | 2 +- 6 files changed, 41 insertions(+), 29 deletions(-) create mode 100755 test/DebugInfo/Inputs/dwarfdump-test3.elf-x86-64 diff --git a/lib/DebugInfo/DWARFContext.cpp b/lib/DebugInfo/DWARFContext.cpp index 6be230e73a5..08e5db22067 100644 --- a/lib/DebugInfo/DWARFContext.cpp +++ b/lib/DebugInfo/DWARFContext.cpp @@ -155,8 +155,10 @@ DILineInfo DWARFContext::getLineInfoForAddress(uint64_t address, if (specifier.needs(DILineInfoSpecifier::FunctionName)) { const DWARFDebugInfoEntryMinimal *function_die = cu->getFunctionDIEForAddress(address); - if (function_die) - functionName = function_die->getSubprogramName(cu); + if (function_die) { + if (const char *name = function_die->getSubprogramName(cu)) + functionName = name; + } } if (specifier.needs(DILineInfoSpecifier::FileLineInfo)) { // Get the line table for this compile unit. diff --git a/lib/DebugInfo/DWARFDebugInfoEntry.cpp b/lib/DebugInfo/DWARFDebugInfoEntry.cpp index 1024b452551..429a36c0871 100644 --- a/lib/DebugInfo/DWARFDebugInfoEntry.cpp +++ b/lib/DebugInfo/DWARFDebugInfoEntry.cpp @@ -456,35 +456,38 @@ DWARFDebugInfoEntryMinimal::addressRangeContainsAddress( return false; } -static inline const char* -getSubprogramNameFromDie(const DWARFCompileUnit *cu, - const DWARFDebugInfoEntryMinimal *die) { - const char *result = 0; - if (!die->isNULL() && die->getTag() == DW_TAG_subprogram) { - // Try to get mangled name if possible. - result = die->getAttributeValueAsString(cu, DW_AT_MIPS_linkage_name, 0); - if (result == 0) - result = die->getAttributeValueAsString(cu, DW_AT_linkage_name, 0); - if (result == 0) - result = die->getAttributeValueAsString(cu, DW_AT_name, 0); - } - return result; -} - const char* DWARFDebugInfoEntryMinimal::getSubprogramName( const DWARFCompileUnit *cu) const { if (isNULL() || getTag() != DW_TAG_subprogram) return 0; - const char *name = getSubprogramNameFromDie(cu, this); - if (name == 0) { - // Try to get name from specification DIE. - uint32_t ref = getAttributeValueAsReference(cu, DW_AT_specification, -1U); - if (ref != -1U) { - DWARFDebugInfoEntryMinimal spec_die; - if (spec_die.extract(cu, &ref)) - name = getSubprogramNameFromDie(cu, &spec_die); + // Try to get mangled name if possible. + if (const char *name = + getAttributeValueAsString(cu, DW_AT_MIPS_linkage_name, 0)) + return name; + if (const char *name = getAttributeValueAsString(cu, DW_AT_linkage_name, 0)) + return name; + if (const char *name = getAttributeValueAsString(cu, DW_AT_name, 0)) + return name; + // Try to get name from specification DIE. + uint32_t spec_ref = + getAttributeValueAsReference(cu, DW_AT_specification, -1U); + if (spec_ref != -1U) { + DWARFDebugInfoEntryMinimal spec_die; + if (spec_die.extract(cu, &spec_ref)) { + if (const char *name = spec_die.getSubprogramName(cu)) + return name; } } - return name; + // Try to get name from abstract origin DIE. + uint32_t abs_origin_ref = + getAttributeValueAsReference(cu, DW_AT_abstract_origin, -1U); + if (abs_origin_ref != -1U) { + DWARFDebugInfoEntryMinimal abs_origin_die; + if (abs_origin_die.extract(cu, &abs_origin_ref)) { + if (const char *name = abs_origin_die.getSubprogramName(cu)) + return name; + } + } + return 0; } diff --git a/lib/DebugInfo/DWARFDebugInfoEntry.h b/lib/DebugInfo/DWARFDebugInfoEntry.h index 1a040a53a38..d5d86b9ec0c 100644 --- a/lib/DebugInfo/DWARFDebugInfoEntry.h +++ b/lib/DebugInfo/DWARFDebugInfoEntry.h @@ -132,8 +132,10 @@ public: bool addressRangeContainsAddress(const DWARFCompileUnit *cu, const uint64_t address) const; - // If a DIE represents a subroutine, returns its mangled name - // (or short name, if mangled is missing). Otherwise returns null. + // If a DIE represents a subprogram, 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* getSubprogramName(const DWARFCompileUnit *cu) const; }; diff --git a/test/DebugInfo/Inputs/dwarfdump-test3.elf-x86-64 b/test/DebugInfo/Inputs/dwarfdump-test3.elf-x86-64 new file mode 100755 index 0000000000000000000000000000000000000000..fb3ca032f0dd19b4ca2bb09f419c9d5a4441b5d6 GIT binary patch literal 6794 zcmcgwU2Ggz6}~g$wbxnyY~lcELgk@qP}77->^3D$lhn?}@g~?YbrMlXqVepHy&LV1 zwKFzO1ft+lB}yZuynzsnS|kufh!>CdiuW@{uv+xSdc6#F#iFVz`>(X&D=9 zx>~e9D6W2uHOUIR}xr6T^j;PwoJ_2Ey`){8&mP-STh3l?>W+M{-Q@F(sT{GU_| z)M|1^RWJ?TY(w1J0slPkZRq8Snir;i5y~@c1mvsGx1o3YR6Nhu=??f!;7RegzS(0! zYnC5FB|IKCn;^8e6dsLF0^inVyu!8@%GHYPdQQ!=ZDAKHMNioC5O8Hz98#T9@oHY! zr~EbJNu@?7G8v_gkXkBcTrZd1yVr87)=OlT8`?rPYrABP z5T5mMJD+nr2MuOi*YAq3^Oc;KoH}(pWsh2;*1^UoHKAkmH-El^?C;32`}We#B9@IV zex`UEYW{c~vHhXKyAc;$Q)>a7))SYH19 z>kr1yon6YLSC1Yb+v`i;I64FE;d`hpee>zBX{MOEx%&tN>YIRPYR_NNAAM@1S08EV zm+!mg;P44*Z%s>IkL`wkyuSS|LU%%izxLn{v2Li^h4G7*?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ZT5{_wqLjO5#j zzdcfU#FTAw?g{d5s}Gt*^&HbDFpW{&md0~I!)(`n@+rTztC0pHrXSSdYM^)g9uI~X z$dP>1&+ph2#4L=lL)`(8%Lqd{A(H4&zBAQ8Nfh-4I)G4%rUhCOA(9Nro5_od3f3 zcENcqjDJpWz6#@XYS&tf#x6JPGa9QgimOE!hH+nZMiAdL1bt1m7DJvygmGGaI?f6C zJAu9QJa*ySk8PH8mZ6E(`|`ZRTkp#uiMQUD3E9q?y?w>wXM9{4lSN?@Oq@vY~{uXVsL z0&jPoTu^xQJh|K<-jnsW$xB(MR0H64M@T|N2v3kq#I3JtKZTWuyOGlxB literal 0 HcmV?d00001 diff --git a/test/DebugInfo/dwarfdump-test.test b/test/DebugInfo/dwarfdump-test.test index 84fe7f3ec82..7b01e382688 100644 --- a/test/DebugInfo/dwarfdump-test.test +++ b/test/DebugInfo/dwarfdump-test.test @@ -8,6 +8,8 @@ RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test2.elf-x86-64 \ RUN: --address=0x4004b8 --functions | FileCheck %s -check-prefix MANY_CU_1 RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test2.elf-x86-64 \ RUN: --address=0x4004c4 --functions | FileCheck %s -check-prefix MANY_CU_2 +RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test3.elf-x86-64 \ +RUN: --address=0x538 --functions | FileCheck %s -check-prefix ABS_ORIGIN_1 MAIN: main MAIN-NEXT: dwarfdump-test.cc:16:10 @@ -23,3 +25,6 @@ MANY_CU_1-NEXT: a.cc:2:0 MANY_CU_2: main MANY_CU_2-NEXT: main.cc:4:0 + +ABS_ORIGIN_1: C +ABS_ORIGIN_1-NEXT: def.cc:3:0 diff --git a/test/DebugInfo/lit.local.cfg b/test/DebugInfo/lit.local.cfg index 19eebc0ac7a..00bd9b83b52 100644 --- a/test/DebugInfo/lit.local.cfg +++ b/test/DebugInfo/lit.local.cfg @@ -1 +1 @@ -config.suffixes = ['.ll', '.c', '.cpp'] +config.suffixes = ['.ll', '.c', '.cpp', '.test']