From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway22.websitewelcome.com (gateway22.websitewelcome.com [192.185.47.48]) by sourceware.org (Postfix) with ESMTPS id 099D4385DC3B for ; Sat, 4 Apr 2020 14:43:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 099D4385DC3B 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 cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 994F51920AA for ; Sat, 4 Apr 2020 09:43:25 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id Kk17jRXF3AGTXKk17jof38; Sat, 04 Apr 2020 09:43:25 -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=rY0CAZJsXauRR+Awqv1D7uzdLT5+5sNOAEUHmS5ia1w=; b=BIoms3Fit6eWUPMyGo6I2aMr6+ JeauukX6VKEkUO81OjmMY6KIVuQmqpn1yJp2MJQL233w+wxZxltAbKF/3r0Vxxyiwpm7XBGuEbtZG I/HaveBCS6b4/5gOkN0hu33dN; Received: from 174-16-110-145.hlrn.qwest.net ([174.16.110.145]:58434 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1jKk17-003j51-5P; Sat, 04 Apr 2020 08:43:25 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 06/20] Remove DW_STRING and DW_STRING_IS_CANONICAL Date: Sat, 4 Apr 2020 08:43:06 -0600 Message-Id: <20200404144320.18851-7-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200404144320.18851-1-tom@tromey.com> References: <20200404144320.18851-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: 174.16.110.145 X-Source-L: No X-Exim-ID: 1jKk17-003j51-5P X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-110-145.hlrn.qwest.net (bapiya.Home) [174.16.110.145]:58434 X-Source-Auth: tom+tromey.com X-Email-Count: 17 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-17.9 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, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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, 04 Apr 2020 14:43:28 -0000 This removes DW_STRING and DW_STRING_IS_CANONICAL, replacing them with accessor methods on struct attribute. The new code ensures that a string value will only ever be used when the form allows it. gdb/ChangeLog 2020-04-04 Tom Tromey * dwarf2/read.c (read_cutu_die_from_dwo) (read_attribute_reprocess, read_attribute_value, read_attribute) (dwarf2_const_value_attr, dwarf2_name, dump_die_shallow) (dwarf2_fetch_constant_bytes): Update. * dwarf2/attribute.h (struct attribute) : Declare. : New methods. : Update comment. : Add assert. (DW_STRING, DW_STRING_IS_CANONICAL): Remove. * dwarf2/attribute.c (attribute::form_is_string): New method. (attribute::string): Use it. --- gdb/ChangeLog | 14 ++++++++++ gdb/dwarf2/attribute.c | 26 ++++++++++++------ gdb/dwarf2/attribute.h | 29 ++++++++++++++++---- gdb/dwarf2/read.c | 62 ++++++++++++++++++------------------------ 4 files changed, 81 insertions(+), 50 deletions(-) diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c index 3acc13ce151..fcf36fc15f2 100644 --- a/gdb/dwarf2/attribute.c +++ b/gdb/dwarf2/attribute.c @@ -61,18 +61,26 @@ attribute::as_address () const /* See attribute.h. */ +bool +attribute::form_is_string () const +{ + return (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); +} + +/* See attribute.h. */ + const char * attribute::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) + if (form_is_string ()) return u.str; return nullptr; } diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h index 69f280e94b3..53d6cafb407 100644 --- a/gdb/dwarf2/attribute.h +++ b/gdb/dwarf2/attribute.h @@ -89,6 +89,9 @@ struct attribute bool form_is_block () const; + /* Check if the attribute's form is a string form. */ + bool form_is_string () const; + /* Return DIE offset of this attribute. Return 0 with complaint if the attribute is not of the required kind. */ @@ -107,16 +110,34 @@ struct attribute flag indicates whether the value has been canonicalized. */ bool canonical_string_p () const { + gdb_assert (form_is_string ()); return string_is_canonical; } + /* Initialize this attribute to hold a non-canonical string + value. */ + void set_string_noncanonical (const char *str) + { + gdb_assert (form_is_string ()); + u.str = str; + string_is_canonical = 0; + } + + /* Set the canonical string value for this attribute. */ + void set_string_canonical (const char *str) + { + gdb_assert (form_is_string ()); + u.str = str; + string_is_canonical = 1; + } + ENUM_BITFIELD(dwarf_attribute) name : 16; ENUM_BITFIELD(dwarf_form) form : 15; - /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This - field should be in u.str (existing only for DW_STRING) but it is kept - here for better struct attribute alignment. */ + /* Has u.str already been updated by dwarf2_canonicalize_name? This + field should be in u.str but it is kept here for better struct + attribute alignment. */ unsigned int string_is_canonical : 1; union @@ -133,8 +154,6 @@ struct attribute /* Get at parts of an attribute structure. */ -#define DW_STRING(attr) ((attr)->u.str) -#define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) #define DW_UNSND(attr) ((attr)->u.unsnd) #define DW_BLOCK(attr) ((attr)->u.blk) #define DW_SND(attr) ((attr)->u.snd) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 1aa381b0483..179fc3481fd 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -6502,8 +6502,7 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu, comp_dir = XOBNEW (&cu->comp_unit_obstack, struct attribute); comp_dir->name = DW_AT_comp_dir; comp_dir->form = DW_FORM_string; - DW_STRING_IS_CANONICAL (comp_dir) = 0; - DW_STRING (comp_dir) = stub_comp_dir; + comp_dir->set_string_noncanonical (stub_comp_dir); } /* Set up for reading the DWO CU/TU. */ @@ -18350,16 +18349,13 @@ read_attribute_reprocess (const struct die_reader_specs *reader, case DW_FORM_GNU_str_index: { unsigned int str_index = DW_UNSND (attr); + gdb_assert (!attr->canonical_string_p ()); if (reader->dwo_file != NULL) - { - DW_STRING (attr) = read_dwo_str_index (reader, str_index); - DW_STRING_IS_CANONICAL (attr) = 0; - } + attr->set_string_noncanonical (read_dwo_str_index (reader, + str_index)); else - { - DW_STRING (attr) = read_stub_str_index (cu, str_index); - DW_STRING_IS_CANONICAL (attr) = 0; - } + attr->set_string_noncanonical (read_stub_str_index (cu, + str_index)); break; } default: @@ -18447,17 +18443,17 @@ read_attribute_value (const struct die_reader_specs *reader, info_ptr += bytes_read; break; case DW_FORM_string: - DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); - DW_STRING_IS_CANONICAL (attr) = 0; + attr->set_string_noncanonical (read_direct_string (abfd, info_ptr, + &bytes_read)); info_ptr += bytes_read; break; case DW_FORM_strp: if (!cu->per_cu->is_dwz) { - DW_STRING (attr) = read_indirect_string (dwarf2_per_objfile, - abfd, info_ptr, cu_header, - &bytes_read); - DW_STRING_IS_CANONICAL (attr) = 0; + attr->set_string_noncanonical + (read_indirect_string (dwarf2_per_objfile, + abfd, info_ptr, cu_header, + &bytes_read)); info_ptr += bytes_read; break; } @@ -18465,10 +18461,9 @@ read_attribute_value (const struct die_reader_specs *reader, case DW_FORM_line_strp: if (!cu->per_cu->is_dwz) { - DW_STRING (attr) - = dwarf2_per_objfile->read_line_string (info_ptr, cu_header, - &bytes_read); - DW_STRING_IS_CANONICAL (attr) = 0; + attr->set_string_noncanonical + (dwarf2_per_objfile->read_line_string (info_ptr, cu_header, + &bytes_read)); info_ptr += bytes_read; break; } @@ -18479,8 +18474,8 @@ read_attribute_value (const struct die_reader_specs *reader, LONGEST str_offset = cu_header->read_offset (abfd, info_ptr, &bytes_read); - DW_STRING (attr) = dwz->read_string (objfile, str_offset); - DW_STRING_IS_CANONICAL (attr) = 0; + attr->set_string_noncanonical + (dwz->read_string (objfile, str_offset)); info_ptr += bytes_read; } break; @@ -18644,6 +18639,7 @@ read_attribute (const struct die_reader_specs *reader, const gdb_byte *info_ptr, bool *need_reprocess) { attr->name = abbrev->name; + attr->string_is_canonical = 0; return read_attribute_value (reader, attr, abbrev->form, abbrev->implicit_const, info_ptr, need_reprocess); @@ -20509,7 +20505,7 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type, case DW_FORM_strx: case DW_FORM_GNU_str_index: case DW_FORM_GNU_strp_alt: - /* DW_STRING is already allocated on the objfile obstack, point + /* The string is already allocated on the objfile obstack, point directly to it. */ *bytes = (const gdb_byte *) attr->as_string (); break; @@ -21300,8 +21296,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) if (demangled == nullptr) return nullptr; - DW_STRING (attr) = objfile->intern (demangled.get ()); - DW_STRING_IS_CANONICAL (attr) = 1; + attr->set_string_canonical (objfile->intern (demangled.get ())); } /* Strip any leading namespaces/classes, keep only the @@ -21320,13 +21315,8 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) } if (!attr->canonical_string_p ()) - { - DW_STRING (attr) = dwarf2_canonicalize_name (attr_name, cu, - objfile); - DW_STRING_IS_CANONICAL (attr) = 1; - } - - /* We might have changed it just above. */ + attr->set_string_canonical (dwarf2_canonicalize_name (attr_name, cu, + objfile)); return attr->as_string (); } @@ -21439,9 +21429,9 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) case DW_FORM_GNU_str_index: case DW_FORM_GNU_strp_alt: fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", - DW_STRING (&die->attrs[i]) - ? DW_STRING (&die->attrs[i]) : "", - die->attrs[i].canonical_string_p () ? "is" : "not"); + die->attrs[i].as_string () + ? die->attrs[i].as_string () : "", + die->attrs[i].canonical_string_p () ? "is" : "not"); break; case DW_FORM_flag: if (DW_UNSND (&die->attrs[i])) @@ -21833,7 +21823,7 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off, case DW_FORM_strx: case DW_FORM_GNU_str_index: case DW_FORM_GNU_strp_alt: - /* DW_STRING is already allocated on the objfile obstack, point + /* The string is already allocated on the objfile obstack, point directly to it. */ { const char *attr_name = attr->as_string (); -- 2.17.2