From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway36.websitewelcome.com (gateway36.websitewelcome.com [192.185.188.18]) by sourceware.org (Postfix) with ESMTPS id 3B643385DC29 for ; Sat, 4 Apr 2020 14:43:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3B643385DC29 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 gateway36.websitewelcome.com (Postfix) with ESMTP id 0E7AC400FCE1D for ; Sat, 4 Apr 2020 09:00:22 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id Kk17jRXFGAGTXKk17jof3K; 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=7Bw34ieJijPriSjxsQG7QsNBd3MQaqFRWmIFXWD/tl0=; b=YuinGU/grM7kRljAUZ+XX4w8aS bAy59gO+FoYlLFHxwY9uvec+fNKIMu9JbJBWkI3UZDplf0owtq6GLaagMbaRRRFlKHjvEA0RzClDD l6t9OpJif18YtsWvB8NyUtFj9; 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-CT; Sat, 04 Apr 2020 08:43:25 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 07/20] Remove DW_BLOCK Date: Sat, 4 Apr 2020 08:43:07 -0600 Message-Id: <20200404144320.18851-8-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-CT 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: 18 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-17.1 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, KAM_STOCKGEN, 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 the DW_BLOCK accessor in favor of methods on struct attribute. The methods, unlike the access, check the form. Note that DW_FORM_data16 had to be handled by form_is_block, because in practice that is how we store values of this form. gdb/ChangeLog 2020-04-04 Tom Tromey * dwarf2/read.c (read_call_site_scope) (handle_data_member_location, dwarf2_add_member_fn) (mark_common_block_symbol_computed, attr_to_dynamic_prop) (partial_die_info::read, read_attribute_value) (var_decode_location, dwarf2_const_value_attr, dump_die_shallow) (dwarf2_fetch_die_loc_sect_off, dwarf2_fetch_constant_bytes) (dwarf2_symbol_mark_computed): Update. * dwarf2/attribute.h (struct attribute) : New methods. (DW_BLOCK): Remove. * dwarf2/attribute.c (attribute::form_is_block): Add DW_FORM_data16. --- gdb/ChangeLog | 15 ++++ gdb/dwarf2/attribute.c | 3 +- gdb/dwarf2/attribute.h | 15 +++- gdb/dwarf2/read.c | 155 +++++++++++++++++++++++------------------ 4 files changed, 119 insertions(+), 69 deletions(-) diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c index fcf36fc15f2..bacbd087b8a 100644 --- a/gdb/dwarf2/attribute.c +++ b/gdb/dwarf2/attribute.c @@ -94,7 +94,8 @@ attribute::form_is_block () const || form == DW_FORM_block2 || form == DW_FORM_block4 || form == DW_FORM_block - || form == DW_FORM_exprloc); + || form == DW_FORM_exprloc + || form == DW_FORM_data16); } /* See attribute.h. */ diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h index 53d6cafb407..c52212f7b00 100644 --- a/gdb/dwarf2/attribute.h +++ b/gdb/dwarf2/attribute.h @@ -50,6 +50,13 @@ struct attribute otherwise return NULL. */ const char *as_string () const; + /* Return the block value. The attribute must have block form. */ + dwarf_block *as_block () const + { + gdb_assert (form_is_block ()); + return u.blk; + } + /* 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. @@ -131,6 +138,13 @@ struct attribute string_is_canonical = 1; } + /* Set the block value for this attribute. */ + void set_block (dwarf_block *blk) + { + gdb_assert (form_is_block ()); + u.blk = blk; + } + ENUM_BITFIELD(dwarf_attribute) name : 16; ENUM_BITFIELD(dwarf_form) form : 15; @@ -155,7 +169,6 @@ struct attribute /* Get at parts of an attribute structure. */ #define DW_UNSND(attr) ((attr)->u.unsnd) -#define DW_BLOCK(attr) ((attr)->u.blk) #define DW_SND(attr) ((attr)->u.snd) #define DW_ADDR(attr) ((attr)->u.addr) #define DW_SIGNATURE(attr) ((attr)->u.signature) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 179fc3481fd..1de38ef6437 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -13155,15 +13155,16 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); } SET_FIELD_DWARF_BLOCK (call_site->target, NULL); - if (!attr || (attr->form_is_block () && DW_BLOCK (attr)->size == 0)) + if (!attr || (attr->form_is_block () && attr->as_block ()->size == 0)) /* Keep NULL DWARF_BLOCK. */; else if (attr->form_is_block ()) { struct dwarf2_locexpr_baton *dlbaton; + struct dwarf_block *block = attr->as_block (); dlbaton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton); - dlbaton->data = DW_BLOCK (attr)->data; - dlbaton->size = DW_BLOCK (attr)->size; + dlbaton->data = block->data; + dlbaton->size = block->size; dlbaton->per_cu = cu->per_cu; SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); @@ -13271,12 +13272,14 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) } else { + struct dwarf_block *block = loc->as_block (); + parameter->u.dwarf_reg = dwarf_block_to_dwarf_reg - (DW_BLOCK (loc)->data, &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size]); + (block->data, &block->data[block->size]); if (parameter->u.dwarf_reg != -1) parameter->kind = CALL_SITE_PARAMETER_DWARF_REG; - else if (dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (loc)->data, - &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size], + else if (dwarf_block_to_sp_offset (gdbarch, block->data, + &block->data[block->size], ¶meter->u.fb_offset)) parameter->kind = CALL_SITE_PARAMETER_FB_OFFSET; else @@ -13302,8 +13305,10 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) objfile_name (objfile)); continue; } - parameter->value = DW_BLOCK (attr)->data; - parameter->value_size = DW_BLOCK (attr)->size; + + struct dwarf_block *block = attr->as_block (); + parameter->value = block->data; + parameter->value_size = block->size; /* Parameters are not pre-cleared by memset above. */ parameter->data_value = NULL; @@ -13322,8 +13327,9 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) objfile_name (objfile)); else { - parameter->data_value = DW_BLOCK (attr)->data; - parameter->data_value_size = DW_BLOCK (attr)->size; + block = attr->as_block (); + parameter->data_value = block->data; + parameter->data_value_size = block->size; } } } @@ -14085,7 +14091,7 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, else if (attr->form_is_section_offset ()) dwarf2_complex_location_expr_complaint (); else if (attr->form_is_block ()) - *offset = decode_locdesc (DW_BLOCK (attr), cu); + *offset = decode_locdesc (attr->as_block (), cu); else dwarf2_complex_location_expr_complaint (); @@ -14660,19 +14666,21 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); if (attr != nullptr) { - if (attr->form_is_block () && DW_BLOCK (attr)->size > 0) + if (attr->form_is_block () && attr->as_block ()->size > 0) { - if (DW_BLOCK (attr)->data[0] == DW_OP_constu) + struct dwarf_block *block = attr->as_block (); + + if (block->data[0] == DW_OP_constu) { /* Old-style GCC. */ - fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; + fnp->voffset = decode_locdesc (block, cu) + 2; } - else if (DW_BLOCK (attr)->data[0] == DW_OP_deref - || (DW_BLOCK (attr)->size > 1 - && DW_BLOCK (attr)->data[0] == DW_OP_deref_size - && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) + else if (block->data[0] == DW_OP_deref + || (block->size > 1 + && block->data[0] == DW_OP_deref_size + && block->data[1] == cu->header.addr_size)) { - fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); + fnp->voffset = decode_locdesc (block, cu); if ((fnp->voffset % cu->header.addr_size) != 0) dwarf2_complex_location_expr_complaint (); else @@ -15888,7 +15896,7 @@ mark_common_block_symbol_computed (struct symbol *sym, baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size; } else - baton->size += DW_BLOCK (member_loc)->size; + baton->size += member_loc->as_block ()->size; ptr = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, baton->size); baton->data = ptr; @@ -15908,8 +15916,9 @@ mark_common_block_symbol_computed (struct symbol *sym, { /* We have to copy the data here, because DW_OP_call4 will only use a DW_AT_location attribute. */ - memcpy (ptr, DW_BLOCK (member_loc)->data, DW_BLOCK (member_loc)->size); - ptr += DW_BLOCK (member_loc)->size; + struct dwarf_block *block = member_loc->as_block (); + memcpy (ptr, block->data, block->size); + ptr += block->size; } *ptr++ = DW_OP_plus; @@ -17001,8 +17010,10 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, baton = XOBNEW (obstack, struct dwarf2_property_baton); baton->property_type = default_type; baton->locexpr.per_cu = cu->per_cu; - baton->locexpr.size = DW_BLOCK (attr)->size; - baton->locexpr.data = DW_BLOCK (attr)->data; + + struct dwarf_block *block = attr->as_block (); + baton->locexpr.size = block->size; + baton->locexpr.data = block->data; switch (attr->name) { case DW_AT_string_length: @@ -17047,8 +17058,9 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, baton = XOBNEW (obstack, struct dwarf2_property_baton); baton->property_type = die_type (target_die, target_cu); baton->locexpr.per_cu = cu->per_cu; - baton->locexpr.size = DW_BLOCK (target_attr)->size; - baton->locexpr.data = DW_BLOCK (target_attr)->data; + struct dwarf_block *block = target_attr->as_block (); + baton->locexpr.size = block->size; + baton->locexpr.data = block->data; baton->locexpr.is_reference = true; prop->data.baton = baton; prop->kind = PROP_LOCEXPR; @@ -17940,7 +17952,7 @@ partial_die_info::read (const struct die_reader_specs *reader, /* Support the .debug_loc offsets. */ if (attr.form_is_block ()) { - d.locdesc = DW_BLOCK (&attr); + d.locdesc = attr.as_block (); } else if (attr.form_is_section_offset ()) { @@ -18409,7 +18421,7 @@ read_attribute_value (const struct die_reader_specs *reader, info_ptr += 2; blk->data = read_n_bytes (abfd, info_ptr, blk->size); info_ptr += blk->size; - DW_BLOCK (attr) = blk; + attr->set_block (blk); break; case DW_FORM_block4: blk = dwarf_alloc_block (cu); @@ -18417,7 +18429,7 @@ read_attribute_value (const struct die_reader_specs *reader, info_ptr += 4; blk->data = read_n_bytes (abfd, info_ptr, blk->size); info_ptr += blk->size; - DW_BLOCK (attr) = blk; + attr->set_block (blk); break; case DW_FORM_data2: DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); @@ -18436,7 +18448,7 @@ read_attribute_value (const struct die_reader_specs *reader, blk->size = 16; blk->data = read_n_bytes (abfd, info_ptr, 16); info_ptr += 16; - DW_BLOCK (attr) = blk; + attr->set_block (blk); break; case DW_FORM_sec_offset: DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr, &bytes_read); @@ -18486,7 +18498,7 @@ read_attribute_value (const struct die_reader_specs *reader, info_ptr += bytes_read; blk->data = read_n_bytes (abfd, info_ptr, blk->size); info_ptr += blk->size; - DW_BLOCK (attr) = blk; + attr->set_block (blk); break; case DW_FORM_block1: blk = dwarf_alloc_block (cu); @@ -18494,7 +18506,7 @@ read_attribute_value (const struct die_reader_specs *reader, info_ptr += 1; blk->data = read_n_bytes (abfd, info_ptr, blk->size); info_ptr += blk->size; - DW_BLOCK (attr) = blk; + attr->set_block (blk); break; case DW_FORM_data1: DW_UNSND (attr) = read_1_byte (abfd, info_ptr); @@ -19954,7 +19966,7 @@ var_decode_location (struct attribute *attr, struct symbol *sym, /* A DW_AT_location attribute with no contents indicates that a variable has been optimized away. */ - if (attr->form_is_block () && DW_BLOCK (attr)->size == 0) + if (attr->form_is_block () && attr->as_block ()->size == 0) { SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT; return; @@ -19965,32 +19977,36 @@ var_decode_location (struct attribute *attr, struct symbol *sym, specified. If this is just a DW_OP_addr, DW_OP_addrx, or DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */ - if (attr->form_is_block () - && ((DW_BLOCK (attr)->data[0] == DW_OP_addr - && DW_BLOCK (attr)->size == 1 + cu_header->addr_size) - || ((DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index - || DW_BLOCK (attr)->data[0] == DW_OP_addrx) - && (DW_BLOCK (attr)->size - == 1 + leb128_size (&DW_BLOCK (attr)->data[1]))))) - { - unsigned int dummy; - - if (DW_BLOCK (attr)->data[0] == DW_OP_addr) - SET_SYMBOL_VALUE_ADDRESS - (sym, cu->header.read_address (objfile->obfd, - DW_BLOCK (attr)->data + 1, - &dummy)); - else - SET_SYMBOL_VALUE_ADDRESS - (sym, read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1, + if (attr->form_is_block ()) + { + struct dwarf_block *block = attr->as_block (); + + if ((block->data[0] == DW_OP_addr + && block->size == 1 + cu_header->addr_size) + || ((block->data[0] == DW_OP_GNU_addr_index + || block->data[0] == DW_OP_addrx) + && (block->size + == 1 + leb128_size (&block->data[1])))) + { + unsigned int dummy; + + if (block->data[0] == DW_OP_addr) + SET_SYMBOL_VALUE_ADDRESS + (sym, cu->header.read_address (objfile->obfd, + block->data + 1, &dummy)); - SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC; - fixup_symbol_section (sym, objfile); - SET_SYMBOL_VALUE_ADDRESS - (sym, - SYMBOL_VALUE_ADDRESS (sym) - + objfile->section_offsets[SYMBOL_SECTION (sym)]); - return; + else + SET_SYMBOL_VALUE_ADDRESS + (sym, read_addr_index_from_leb128 (cu, block->data + 1, + &dummy)); + SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC; + fixup_symbol_section (sym, objfile); + SET_SYMBOL_VALUE_ADDRESS + (sym, + SYMBOL_VALUE_ADDRESS (sym) + + objfile->section_offsets[SYMBOL_SECTION (sym)]); + return; + } } /* NOTE drow/2002-01-30: It might be worthwhile to have a static @@ -20515,7 +20531,7 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type, case DW_FORM_block: case DW_FORM_exprloc: case DW_FORM_data16: - blk = DW_BLOCK (attr); + blk = attr->as_block (); if (TYPE_LENGTH (type) != blk->size) dwarf2_const_value_length_mismatch_complaint (name, blk->size, TYPE_LENGTH (type)); @@ -21380,11 +21396,11 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) case DW_FORM_block: case DW_FORM_block1: fprintf_unfiltered (f, "block: size %s", - pulongest (DW_BLOCK (&die->attrs[i])->size)); + pulongest (die->attrs[i].as_block ()->size)); break; case DW_FORM_exprloc: fprintf_unfiltered (f, "expression: size %s", - pulongest (DW_BLOCK (&die->attrs[i])->size)); + pulongest (die->attrs[i].as_block ()->size)); break; case DW_FORM_data16: fprintf_unfiltered (f, "constant of 16 bytes"); @@ -21722,8 +21738,9 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off, "is neither DW_FORM_block* nor DW_FORM_exprloc"), sect_offset_str (sect_off), objfile_name (objfile)); - retval.data = DW_BLOCK (attr)->data; - retval.size = DW_BLOCK (attr)->size; + struct dwarf_block *block = attr->as_block (); + retval.data = block->data; + retval.size = block->size; } retval.per_cu = cu->per_cu; @@ -21837,8 +21854,11 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off, case DW_FORM_block: case DW_FORM_exprloc: case DW_FORM_data16: - result = DW_BLOCK (attr)->data; - *len = DW_BLOCK (attr)->size; + { + struct dwarf_block *block = attr->as_block (); + result = block->data; + *len = block->size; + } break; /* The DW_AT_const_value attributes are supposed to carry the @@ -22618,8 +22638,9 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym, info_buffer for SYM's objfile; right now we never release that buffer, but when we do clean up properly this may need to change. */ - baton->size = DW_BLOCK (attr)->size; - baton->data = DW_BLOCK (attr)->data; + struct dwarf_block *block = attr->as_block (); + baton->size = block->size; + baton->data = block->data; } else { -- 2.17.2