From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway36.websitewelcome.com (gateway36.websitewelcome.com [192.185.197.22]) by sourceware.org (Postfix) with ESMTPS id A4186385E025 for ; Sun, 22 Mar 2020 18:45:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A4186385E025 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 cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway36.websitewelcome.com (Postfix) with ESMTP id A2971400C6C5E for ; Sun, 22 Mar 2020 13:01:43 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id G5bGjQ11cVQh0G5bGjeUWX; Sun, 22 Mar 2020 13:45:30 -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=8taeRwI0D5zoesOs0nbJd8ITxTMVpPxBhD3T3dXaa8s=; b=RehikiRbZbjWWFRnOUit2oNdfF TOcvm56NAU0TD0/vsLYHF4+EkhIWddjmYkUu5PYSXgLXChhNpulxOOWYCCSrnZHIlKHe7UBiLM/pc TIULAepuTq1XYzMu2GZYBngC4; Received: from 97-118-117-21.hlrn.qwest.net ([97.118.117.21]:48304 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1jG5bG-000LNS-4F; Sun, 22 Mar 2020 12:45:30 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 22/22] Change two functions to be methods on struct attribute Date: Sun, 22 Mar 2020 12:45:23 -0600 Message-Id: <20200322184523.28959-23-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200322184523.28959-1-tom@tromey.com> References: <20200322184523.28959-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: 1jG5bG-000LNS-4F X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-117-21.hlrn.qwest.net (bapiya.Home) [97.118.117.21]:48304 X-Source-Auth: tom+tromey.com X-Email-Count: 23 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-22.8 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: Sun, 22 Mar 2020 18:45:35 -0000 This changes dwarf2_get_ref_die_offset and dwarf2_get_attr_constant_value to be methods on struct attribute. 2020-03-22 Tom Tromey * dwarf2/read.c (handle_data_member_location, dwarf2_add_field) (mark_common_block_symbol_computed, read_tag_string_type) (attr_to_dynamic_prop, read_subrange_type): Update. (dwarf2_get_ref_die_offset, dwarf2_get_attr_constant_value): Move to be methods on struct attribute. (skip_one_die, process_imported_unit_die, read_namespace_alias) (read_call_site_scope, partial_die_info::read) (partial_die_info::read, lookup_die_type, follow_die_ref): Update. * dwarf2/attribute.c (attribute::get_ref_die_offset): New method, from dwarf2_get_ref_die_offset. (attribute::constant_value): New method, from dwarf2_get_attr_constant_value. * dwarf2/attribute.h (struct attribute) : Declare method. : New method. --- gdb/ChangeLog | 19 ++++++++++ gdb/dwarf2/attribute.c | 37 ++++++++++++++++++++ gdb/dwarf2/attribute.h | 12 +++++++ gdb/dwarf2/read.c | 78 ++++++++++-------------------------------- 4 files changed, 86 insertions(+), 60 deletions(-) diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c index 6efff3e2c0a..0e5a8c8f536 100644 --- a/gdb/dwarf2/attribute.c +++ b/gdb/dwarf2/attribute.c @@ -26,6 +26,8 @@ #include "defs.h" #include "dwarf2/attribute.h" +#include "dwarf2/stringify.h" +#include "complaints.h" /* See attribute.h. */ @@ -119,3 +121,38 @@ attribute::form_is_ref () const return false; } } + +/* See attribute.h. */ + +sect_offset +attribute::get_ref_die_offset () const +{ + if (form_is_ref ()) + return (sect_offset) DW_UNSND (this); + + complaint (_("unsupported die ref attribute form: '%s'"), + dwarf_form_name (form)); + return {}; +} + +/* See attribute.h. */ + +LONGEST +attribute::constant_value (int default_value) const +{ + if (form == DW_FORM_sdata || form == DW_FORM_implicit_const) + return DW_SND (this); + else if (form == DW_FORM_udata + || form == DW_FORM_data1 + || form == DW_FORM_data2 + || form == DW_FORM_data4 + || form == DW_FORM_data8) + return DW_UNSND (this); + else + { + /* For DW_FORM_data16 see attribute::form_is_constant. */ + complaint (_("Attribute value is not a constant (%s)"), + dwarf_form_name (form)); + return default_value; + } +} diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h index c2602310715..483b805433b 100644 --- a/gdb/dwarf2/attribute.h +++ b/gdb/dwarf2/attribute.h @@ -28,6 +28,7 @@ #define GDB_DWARF2_ATTRIBUTE_H #include "dwarf2.h" +#include "gdbtypes.h" /* Blocks are a bunch of untyped bytes. */ struct dwarf_block @@ -84,6 +85,17 @@ struct attribute bool form_is_block () const; + /* Return DIE offset of this attribute. Return 0 with complaint if + the attribute is not of the required kind. */ + + sect_offset get_ref_die_offset () const; + + /* Return the constant value held by this attribute. Return + DEFAULT_VALUE if the value held by the attribute is not + constant. */ + + LONGEST constant_value (int default_value) const; + ENUM_BITFIELD(dwarf_attribute) name : 16; ENUM_BITFIELD(dwarf_form) form : 15; diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 87305ec3688..73df64d15fd 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1419,10 +1419,6 @@ static void dump_die_1 (struct ui_file *, int level, int max_level, static void store_in_ref_table (struct die_info *, struct dwarf2_cu *); -static sect_offset dwarf2_get_ref_die_offset (const struct attribute *); - -static LONGEST dwarf2_get_attr_constant_value (const struct attribute *, int); - static struct die_info *follow_die_ref_or_sig (struct die_info *, const struct attribute *, struct dwarf2_cu **); @@ -8476,7 +8472,7 @@ skip_one_die (const struct die_reader_specs *reader, const gdb_byte *info_ptr, complaint (_("ignoring absolute DW_AT_sibling")); else { - sect_offset off = dwarf2_get_ref_die_offset (&attr); + sect_offset off = attr.get_ref_die_offset (); const gdb_byte *sibling_ptr = buffer + to_underlying (off); if (sibling_ptr < info_ptr) @@ -9643,7 +9639,7 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_import, cu); if (attr != NULL) { - sect_offset sect_off = dwarf2_get_ref_die_offset (attr); + sect_offset sect_off = attr->get_ref_die_offset (); bool is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz); dwarf2_per_cu_data *per_cu = dwarf2_find_containing_comp_unit (sect_off, is_dwz, @@ -10296,7 +10292,7 @@ read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu) if (attr != NULL) { struct type *type; - sect_offset sect_off = dwarf2_get_ref_die_offset (attr); + sect_offset sect_off = attr->get_ref_die_offset (); type = get_die_type_at_offset (sect_off, cu->per_cu); if (type != NULL && TYPE_CODE (type) == TYPE_CODE_NAMESPACE) @@ -13224,8 +13220,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) { parameter->kind = CALL_SITE_PARAMETER_PARAM_OFFSET; - sect_offset sect_off - = (sect_offset) dwarf2_get_ref_die_offset (origin); + sect_offset sect_off = origin->get_ref_die_offset (); if (!cu->header.offset_in_cu_p (sect_off)) { /* As DW_OP_GNU_parameter_ref uses CU-relative offset this @@ -14059,7 +14054,7 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, so if we see it, we can assume that a constant form is really a constant and not a section offset. */ if (attr->form_is_constant ()) - *offset = dwarf2_get_attr_constant_value (attr, 0); + *offset = attr->constant_value (0); else if (attr->form_is_section_offset ()) dwarf2_complex_location_expr_complaint (); else if (attr->form_is_block ()) @@ -14186,7 +14181,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die, attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu); if (attr != NULL) SET_FIELD_BITPOS (*fp, (FIELD_BITPOS (*fp) - + dwarf2_get_attr_constant_value (attr, 0))); + + attr->constant_value (0))); /* Get name of field. */ fieldname = dwarf2_name (die, cu); @@ -15860,7 +15855,7 @@ mark_common_block_symbol_computed (struct symbol *sym, if (member_loc->form_is_constant ()) { - offset = dwarf2_get_attr_constant_value (member_loc, 0); + offset = member_loc->constant_value (0); baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size; } else @@ -16452,7 +16447,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) { /* Pass 0 as the default as we know this attribute is constant and the default value will not be returned. */ - LONGEST sz = dwarf2_get_attr_constant_value (len, 0); + LONGEST sz = len->constant_value (0); prop_type = cu->per_cu->int_type (sz, true); } else @@ -16474,12 +16469,12 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) indirection. There's no need to create a dynamic property in this case. Pass 0 for the default value as we know it will not be returned in this case. */ - length = dwarf2_get_attr_constant_value (attr, 0); + length = attr->constant_value (0); } else if ((attr = dwarf2_attr (die, DW_AT_byte_size, cu)) != nullptr) { /* We don't currently support non-constant byte sizes for strings. */ - length = dwarf2_get_attr_constant_value (attr, 1); + length = attr->constant_value (1); } else { @@ -17058,7 +17053,7 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, } else if (attr->form_is_constant ()) { - prop->data.const_val = dwarf2_get_attr_constant_value (attr, 0); + prop->data.const_val = attr->constant_value (0); prop->kind = PROP_CONST; } else @@ -17236,7 +17231,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) LONGEST bias = 0; struct attribute *bias_attr = dwarf2_attr (die, DW_AT_GNU_bias, cu); if (bias_attr != nullptr && bias_attr->form_is_constant ()) - bias = dwarf2_get_attr_constant_value (bias_attr, 0); + bias = bias_attr->constant_value (0); /* Normally, the DWARF producers are expected to use a signed constant form (Eg. DW_FORM_sdata) to express negative bounds. @@ -17942,7 +17937,7 @@ partial_die_info::read (const struct die_reader_specs *reader, case DW_AT_specification: case DW_AT_extension: has_specification = 1; - spec_offset = dwarf2_get_ref_die_offset (&attr); + spec_offset = attr.get_ref_die_offset (); spec_is_dwz = (attr.form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz); break; @@ -17954,7 +17949,7 @@ partial_die_info::read (const struct die_reader_specs *reader, else { const gdb_byte *buffer = reader->buffer; - sect_offset off = dwarf2_get_ref_die_offset (&attr); + sect_offset off = attr.get_ref_die_offset (); const gdb_byte *sibling_ptr = buffer + to_underlying (off); if (sibling_ptr < info_ptr) @@ -17999,7 +17994,7 @@ partial_die_info::read (const struct die_reader_specs *reader, case DW_AT_import: if (tag == DW_TAG_imported_unit) { - d.sect_off = dwarf2_get_ref_die_offset (&attr); + d.sect_off = attr.get_ref_die_offset (); is_dwz = (attr.form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz); } @@ -20703,7 +20698,7 @@ lookup_die_type (struct die_info *die, const struct attribute *attr, if (attr->form == DW_FORM_GNU_ref_alt) { struct dwarf2_per_cu_data *per_cu; - sect_offset sect_off = dwarf2_get_ref_die_offset (attr); + sect_offset sect_off = attr->get_ref_die_offset (); per_cu = dwarf2_find_containing_comp_unit (sect_off, 1, dwarf2_per_objfile); @@ -20711,7 +20706,7 @@ lookup_die_type (struct die_info *die, const struct attribute *attr, } else if (attr->form_is_ref ()) { - sect_offset sect_off = dwarf2_get_ref_die_offset (attr); + sect_offset sect_off = attr->get_ref_die_offset (); this_type = get_die_type_at_offset (sect_off, cu->per_cu); } @@ -21513,43 +21508,6 @@ store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) *slot = die; } -/* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the - required kind. */ - -static sect_offset -dwarf2_get_ref_die_offset (const struct attribute *attr) -{ - if (attr->form_is_ref ()) - return (sect_offset) DW_UNSND (attr); - - complaint (_("unsupported die ref attribute form: '%s'"), - dwarf_form_name (attr->form)); - return {}; -} - -/* Return the constant value held by ATTR. Return DEFAULT_VALUE if - * the value held by the attribute is not constant. */ - -static LONGEST -dwarf2_get_attr_constant_value (const struct attribute *attr, int default_value) -{ - if (attr->form == DW_FORM_sdata || attr->form == DW_FORM_implicit_const) - return DW_SND (attr); - else if (attr->form == DW_FORM_udata - || attr->form == DW_FORM_data1 - || attr->form == DW_FORM_data2 - || attr->form == DW_FORM_data4 - || attr->form == DW_FORM_data8) - return DW_UNSND (attr); - else - { - /* For DW_FORM_data16 see attribute::form_is_constant. */ - complaint (_("Attribute value is not a constant (%s)"), - dwarf_form_name (attr->form)); - return default_value; - } -} - /* Follow reference or signature attribute ATTR of SRC_DIE. On entry *REF_CU is the CU of SRC_DIE. On exit *REF_CU is the CU of the result. */ @@ -21640,7 +21598,7 @@ static struct die_info * follow_die_ref (struct die_info *src_die, const struct attribute *attr, struct dwarf2_cu **ref_cu) { - sect_offset sect_off = dwarf2_get_ref_die_offset (attr); + sect_offset sect_off = attr->get_ref_die_offset (); struct dwarf2_cu *cu = *ref_cu; struct die_info *die; -- 2.17.2