From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [192.185.149.4]) by sourceware.org (Postfix) with ESMTPS id E9B46385E038 for ; Sat, 28 Mar 2020 19:22:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E9B46385E038 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 8D3F9288FD for ; Sat, 28 Mar 2020 14:22:10 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id IH22jVDvJSl8qIH22j1uE9; Sat, 28 Mar 2020 14:22:10 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=h2yIjf4hHC4KRGgnqRodQ7Cx0yJF/lWhXFNorI+sEWU=; b=XuLQ1orPpqr2UJjOl3zA5Mu/Do FHA9788gooV0MwbJLOWpsp2vzHpEZnQMw7slGpbAIuInBT1k/54GeueYfjMWAdQjLBt16V16aApeR aWcEHd7guKMqE7NDykXKuJZxV; Received: from 97-118-117-21.hlrn.qwest.net ([97.118.117.21]:55190 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1jIH22-003oZR-AW; Sat, 28 Mar 2020 13:22:10 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 01/20] Add attribute::value_as_string method Date: Sat, 28 Mar 2020 13:21:49 -0600 Message-Id: <20200328192208.11324-2-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200328192208.11324-1-tom@tromey.com> References: <20200328192208.11324-1-tom@tromey.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.118.117.21 X-Source-L: No X-Exim-ID: 1jIH22-003oZR-AW X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-117-21.hlrn.qwest.net (bapiya.Home) [97.118.117.21]:55190 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-21.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, URIBL_CSS, URIBL_CSS_A autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Mar 2020 19:22:12 -0000 The full DIE reader checks that an attribute has a "string" form in some spots, but the partial DIE reader does not. This patch brings the two readers in sync for one specific case, namely when examining the linkage name. This avoids regressions in an existing DWARF test case. A full fix for this problem would be preferable. An accessor like DW_STRING should always check the form. However, I haven't attempted that in this series. Also the fact that the partial and full readers can disagree like this is a design flaw. gdb/ChangeLog 2020-03-25 Tom Tromey * dwarf2/read.c (partial_die_info::read) : Use value_as_string. (dwarf2_string_attr): Use value_as_string. * dwarf2/attribute.h (struct attribute) : Declare method. * dwarf2/attribute.c (attribute::value_as_string): New method. --- gdb/ChangeLog | 9 +++++++++ gdb/dwarf2/attribute.c | 18 ++++++++++++++++++ gdb/dwarf2/attribute.h | 4 ++++ gdb/dwarf2/read.c | 15 +++------------ 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c index 0e5a8c8f536..a4a6db76c8f 100644 --- a/gdb/dwarf2/attribute.c +++ b/gdb/dwarf2/attribute.c @@ -61,6 +61,24 @@ attribute::value_as_address () const /* See attribute.h. */ +const char * +attribute::value_as_string () const +{ + if (form == DW_FORM_strp || form == DW_FORM_line_strp + || form == DW_FORM_string + || form == DW_FORM_strx + || form == DW_FORM_strx1 + || form == DW_FORM_strx2 + || form == DW_FORM_strx3 + || form == DW_FORM_strx4 + || form == DW_FORM_GNU_str_index + || form == DW_FORM_GNU_strp_alt) + return DW_STRING (this); + return nullptr; +} + +/* See attribute.h. */ + bool attribute::form_is_block () const { diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h index 69b33513ad6..a9cabd69f9f 100644 --- a/gdb/dwarf2/attribute.h +++ b/gdb/dwarf2/attribute.h @@ -46,6 +46,10 @@ struct attribute attribute's form into account. */ CORE_ADDR value_as_address () const; + /* If the attribute has a string form, return the string value; + otherwise return NULL. */ + const char *value_as_string () const; + /* Return non-zero if ATTR's value is a section offset --- classes lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. You may use DW_UNSND (attr) to retrieve such offsets. diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 8c5046ef41c..98323f8920b 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -17896,7 +17896,7 @@ partial_die_info::read (const struct die_reader_specs *reader, /* Note that both forms of linkage name might appear. We assume they will be the same, and we only store the last one we see. */ - linkage_name = DW_STRING (&attr); + linkage_name = attr.value_as_string (); break; case DW_AT_low_pc: has_low_pc_attr = 1; @@ -18949,17 +18949,8 @@ dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *c if (attr != NULL) { - if (attr->form == DW_FORM_strp || attr->form == DW_FORM_line_strp - || attr->form == DW_FORM_string - || attr->form == DW_FORM_strx - || attr->form == DW_FORM_strx1 - || attr->form == DW_FORM_strx2 - || attr->form == DW_FORM_strx3 - || attr->form == DW_FORM_strx4 - || attr->form == DW_FORM_GNU_str_index - || attr->form == DW_FORM_GNU_strp_alt) - str = DW_STRING (attr); - else + str = attr->value_as_string (); + if (str == nullptr) complaint (_("string type expected for attribute %s for " "DIE at %s in module %s"), dwarf_attr_name (name), sect_offset_str (die->sect_off), -- 2.17.2