From patchwork Fri Aug 25 20:55:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 22359 Received: (qmail 29830 invoked by alias); 25 Aug 2017 20:55:12 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 28918 invoked by uid 89); 25 Aug 2017 20:55:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 25 Aug 2017 20:55:10 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C1FC80E7A for ; Fri, 25 Aug 2017 20:55:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7C1FC80E7A Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=keiths@redhat.com Received: from valrhona.Home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 591AB60E37 for ; Fri, 25 Aug 2017 20:55:09 +0000 (UTC) From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH] Introduce dw2_linkage_name and dw2_linkage_name_attr. Date: Fri, 25 Aug 2017 13:55:09 -0700 Message-Id: <1503694509-16630-1-git-send-email-keiths@redhat.com> X-IsSubscribed: yes The DWARF reader is littered with the following idiom to read a linkage name from the debug info: mangled = dwarf2_string_attr (die, DW_AT_linkage_name, cu); if (mangled == NULL) mangled = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu); This patch introduces functions to simplify this to: mangled = dw2_linkage_name (die, cu); or attr = dw2_linakge_name_attr (die, cu); gdb/ChangeLog * dwarf2read.c (dw2_linkage_name_attr): New function. (dw2_linkage_name): New function. (dwarf2_compute_name, dwarf2_physname, read_call_site_scope) (guess_full_die_structure_name, dwarf2_name): Use dw2_linkage_name. (anonymous_struct_prefix, dwarf2_name): Use dw2_linkage_name_attr. --- gdb/dwarf2read.c | 64 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index ead4f3c..09390ec 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -8689,6 +8689,38 @@ die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) } } +/* Return the DIE's linkage name attribute, either DW_AT_linkage_name + or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not + defined for the given DIE. */ + +static struct attribute * +dw2_linkage_name_attr (struct die_info *die, struct dwarf2_cu *cu) +{ + struct attribute *attr; + + attr = dwarf2_attr (die, DW_AT_linkage_name, cu); + if (attr == NULL) + attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); + + return attr; +} + +/* Return the DIE's linkage name as a string, either DW_AT_linkage_name + or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not + defined for the given DIE. */ + +static const char * +dw2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) +{ + const char *linkage_name; + + linkage_name = dwarf2_string_attr (die, DW_AT_linkage_name, cu); + if (linkage_name == NULL) + linkage_name = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu); + + return linkage_name; +} + /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, compute the physname for the object, which include a method's: - formal parameters (C++), @@ -8728,11 +8760,8 @@ dwarf2_compute_name (const char *name, to be able to reference. Ideally, we want the user to be able to reference this entity using either natural or linkage name, but we haven't started looking at this enhancement yet. */ - const char *linkage_name; + const char *linkage_name = dw2_linkage_name (die, cu); - linkage_name = dwarf2_string_attr (die, DW_AT_linkage_name, cu); - if (linkage_name == NULL) - linkage_name = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu); if (linkage_name != NULL) return linkage_name; } @@ -8973,9 +9002,7 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu) back_to = make_cleanup (null_cleanup, NULL); - mangled = dwarf2_string_attr (die, DW_AT_linkage_name, cu); - if (mangled == NULL) - mangled = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu); + mangled = dw2_linkage_name (die, cu); /* rustc emits invalid values for DW_AT_linkage_name. Ignore these. See https://github.com/rust-lang/rust/issues/32925. */ @@ -12010,13 +12037,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) const char *target_physname; /* Prefer the mangled name; otherwise compute the demangled one. */ - target_physname = dwarf2_string_attr (target_die, - DW_AT_linkage_name, - target_cu); - if (target_physname == NULL) - target_physname = dwarf2_string_attr (target_die, - DW_AT_MIPS_linkage_name, - target_cu); + target_physname = dw2_linkage_name (target_die, target_cu); if (target_physname == NULL) target_physname = dwarf2_physname (NULL, target_die, target_cu); if (target_physname == NULL) @@ -19882,12 +19903,8 @@ guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) { if (child->tag == DW_TAG_subprogram) { - const char *linkage_name; + const char *linkage_name = dw2_linkage_name (child, cu); - linkage_name = dwarf2_string_attr (child, DW_AT_linkage_name, cu); - if (linkage_name == NULL) - linkage_name = dwarf2_string_attr (child, DW_AT_MIPS_linkage_name, - cu); if (linkage_name != NULL) { char *actual_name @@ -19942,9 +19959,7 @@ anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) if (dwarf2_string_attr (die, DW_AT_name, cu) != NULL) return NULL; - attr = dwarf2_attr (die, DW_AT_linkage_name, cu); - if (attr == NULL) - attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); + attr = dw2_linkage_name_attr (die, cu); if (attr == NULL || DW_STRING (attr) == NULL) return NULL; @@ -20270,10 +20285,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) { char *demangled = NULL; - attr = dwarf2_attr (die, DW_AT_linkage_name, cu); - if (attr == NULL) - attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); - + attr = dw2_linkage_name_attr (die, cu); if (attr == NULL || DW_STRING (attr) == NULL) return NULL;