From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from qproxy2-pub.mail.unifiedlayer.com (qproxy2-pub.mail.unifiedlayer.com [69.89.16.161]) by sourceware.org (Postfix) with ESMTPS id 9243B383FBAB for ; Mon, 13 Feb 2023 03:16:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9243B383FBAB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from outbound-ss-761.bluehost.com (outbound-ss-761.bluehost.com [74.220.211.250]) by qproxy2.mail.unifiedlayer.com (Postfix) with ESMTP id CBB8D8047F84 for ; Mon, 13 Feb 2023 03:16:26 +0000 (UTC) Received: from cmgw11.mail.unifiedlayer.com (unknown [10.0.90.126]) by progateway8.mail.pro1.eigbox.com (Postfix) with ESMTP id BEE0610046D4D for ; Mon, 13 Feb 2023 03:15:26 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id RPJOpJ4w0jkdRRPJOpCxgg; Mon, 13 Feb 2023 03:15:26 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=LPqj/La9 c=1 sm=1 tr=0 ts=63e9ab4e a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=m04uMKEZRckA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=7d_E57ReAAAA:8 a=gLCaAbObLp3LQ_0D9LkA:9 a=QEXdDO2ut3YA:10:nop_charset_2 a=jhqOcbufqs7Y1TYCrUUU:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=b3rPfTkCBOBffpgEbZRVIvKs9nMAlvcevlLZhbPZKyI=; b=wFQZcEVSdRfmcyXMJAlC78MQgR c15eY4X4yPdvEJCLuA0PJ8hv8Y0NfUsJ9eewVKspbL5OfYs2JPGpihza3c6AzecaZJV0YtfK76/zh btdbMMLONP/A74RsD6/aEDdeW; Received: from 75-166-130-93.hlrn.qwest.net ([75.166.130.93]:37668 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pRPJO-001AGJ-Fq; Sun, 12 Feb 2023 20:15:26 -0700 From: Tom Tromey Date: Sun, 12 Feb 2023 20:15:27 -0700 Subject: [PATCH v3 11/50] Turn value_offset into method MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230209-submit-value-fixups-2023-v3-11-45e91a20c742@tromey.com> References: <20230209-submit-value-fixups-2023-v3-0-45e91a20c742@tromey.com> In-Reply-To: <20230209-submit-value-fixups-2023-v3-0-45e91a20c742@tromey.com> To: gdb-patches@sourceware.org Cc: Simon Marchi X-Mailer: b4 0.12.0 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: 75.166.130.93 X-Source-L: No X-Exim-ID: 1pRPJO-001AGJ-Fq X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-130-93.hlrn.qwest.net ([192.168.0.21]) [75.166.130.93]:37668 X-Source-Auth: tom+tromey.com X-Email-Count: 25 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3027.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This changes value_offset to be a method of value. Much of this patch was written by script. Approved-By: Simon Marchi --- gdb/ada-lang.c | 2 +- gdb/breakpoint.c | 2 +- gdb/cp-abi.h | 4 ++-- gdb/dwarf2/expr.c | 10 +++++----- gdb/findvar.c | 6 +++--- gdb/gnu-v2-abi.c | 2 +- gdb/infrun.c | 4 ++-- gdb/opencl-lang.c | 4 ++-- gdb/s390-tdep.c | 2 +- gdb/valops.c | 18 +++++++++--------- gdb/value.c | 23 ++++++----------------- gdb/value.h | 20 +++++++++++--------- 12 files changed, 44 insertions(+), 53 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index b4fcce21a73..c660e74e08c 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2838,7 +2838,7 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, ++new_offset; v->set_bitpos (v->bitpos () - HOST_CHAR_BIT); } - set_value_offset (v, new_offset); + v->set_offset (new_offset); /* Also set the parent value. This is needed when trying to assign a new value (in inferior memory). */ diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 24697691421..71a7225cf75 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1870,7 +1870,7 @@ extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) w->val_bitpos, w->val_bitsize, value_contents_for_printing (val).data (), - value_offset (val), + val->offset (), val); return bit_val; diff --git a/gdb/cp-abi.h b/gdb/cp-abi.h index 383746244a7..f7c903eca2d 100644 --- a/gdb/cp-abi.h +++ b/gdb/cp-abi.h @@ -123,12 +123,12 @@ extern struct value *value_virtual_fn_field (struct value **valuep, - If *USING_ENC is zero, then *TOP is the offset from the start of the complete object to the start of the embedded subobject VALUE represents. In other words, the enclosing object starts - at VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) + + at VALUE_ADDR (VALUE) + VALUE->offset () + value_embedded_offset (VALUE) + *TOP - If *USING_ENC is non-zero, then *TOP is the offset from the address of the complete object to the enclosing object stored in VALUE. In other words, the enclosing object starts at - VALUE_ADDR (VALUE) + VALUE_OFFSET (VALUE) + *TOP. + VALUE_ADDR (VALUE) + VALUE->offset () + *TOP. If VALUE's type and enclosing type are the same, then these two cases are equivalent. diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 2b8feffe881..ccce09350d2 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -168,10 +168,10 @@ rw_pieced_value (value *v, value *from, bool check_optimized) from_contents = nullptr; } - ULONGEST bits_to_skip = 8 * value_offset (v); + ULONGEST bits_to_skip = 8 * v->offset (); if (v->bitsize ()) { - bits_to_skip += (8 * value_offset (v->parent ()) + bits_to_skip += (8 * v->parent ()->offset () + v->bitpos ()); if (from != nullptr && (type_byte_order (from->type ()) @@ -466,7 +466,7 @@ check_pieced_synthetic_pointer (const value *value, LONGEST bit_offset, piece_closure *c = (piece_closure *) value_computed_closure (value); int i; - bit_offset += 8 * value_offset (value); + bit_offset += 8 * value->offset (); if (value->bitsize ()) bit_offset += value->bitpos (); @@ -512,7 +512,7 @@ indirect_pieced_value (value *value) return NULL; int bit_length = 8 * type->length (); - LONGEST bit_offset = 8 * value_offset (value); + LONGEST bit_offset = 8 * value->offset (); if (value->bitsize ()) bit_offset += value->bitpos (); @@ -934,7 +934,7 @@ dwarf_expr_context::fetch_result (struct type *type, struct type *subobj_type, std::move (this->m_pieces), this->m_frame); retval = allocate_computed_value (subobj_type, &pieced_value_funcs, c); - set_value_offset (retval, subobj_offset); + retval->set_offset (subobj_offset); } else { diff --git a/gdb/findvar.c b/gdb/findvar.c index 6683bf761ad..9420286e91c 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -822,9 +822,9 @@ default_value_from_register (struct gdbarch *gdbarch, struct type *type, if (type_byte_order (type) == BFD_ENDIAN_BIG && len < register_size (gdbarch, regnum)) /* Big-endian, and we want less than full size. */ - set_value_offset (value, register_size (gdbarch, regnum) - len); + value->set_offset (register_size (gdbarch, regnum) - len); else - set_value_offset (value, 0); + value->set_offset (0); return value; } @@ -842,7 +842,7 @@ read_frame_register_value (struct value *value, frame_info_ptr frame) { struct gdbarch *gdbarch = get_frame_arch (frame); LONGEST offset = 0; - LONGEST reg_offset = value_offset (value); + LONGEST reg_offset = value->offset (); int regnum = VALUE_REGNUM (value); int len = type_length_units (check_typedef (value->type ())); diff --git a/gdb/gnu-v2-abi.c b/gdb/gnu-v2-abi.c index b27649051a4..632b46f92de 100644 --- a/gdb/gnu-v2-abi.c +++ b/gdb/gnu-v2-abi.c @@ -158,7 +158,7 @@ gnuv2_virtual_fn_field (struct value **arg1p, struct fn_field * f, int j, if (entry_type->code () == TYPE_CODE_STRUCT) { /* Move the `this' pointer according to the virtual function table. */ - set_value_offset (arg1, value_offset (arg1) + arg1->set_offset (arg1->offset () + value_as_long (value_field (entry, 0))); if (!value_lazy (arg1)) diff --git a/gdb/infrun.c b/gdb/infrun.c index 9e81f83134a..9e2512e8446 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -9144,7 +9144,7 @@ siginfo_value_read (struct value *v) TARGET_OBJECT_SIGNAL_INFO, nullptr, value_contents_all_raw (v).data (), - value_offset (v), + v->offset (), v->type ()->length ()); if (transferred != v->type ()->length ()) @@ -9167,7 +9167,7 @@ siginfo_value_write (struct value *v, struct value *fromval) TARGET_OBJECT_SIGNAL_INFO, nullptr, value_contents_all_raw (fromval).data (), - value_offset (v), + v->offset (), fromval->type ()->length ()); if (transferred != fromval->type ()->length ()) diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index f66489bec0f..107a138ff7c 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -122,7 +122,7 @@ lval_func_read (struct value *v) struct lval_closure *c = (struct lval_closure *) value_computed_closure (v); struct type *type = check_typedef (v->type ()); struct type *eltype = check_typedef (c->val->type ())->target_type (); - LONGEST offset = value_offset (v); + LONGEST offset = v->offset (); LONGEST elsize = eltype->length (); int n, i, j = 0; LONGEST lowb = 0; @@ -152,7 +152,7 @@ lval_func_write (struct value *v, struct value *fromval) struct lval_closure *c = (struct lval_closure *) value_computed_closure (v); struct type *type = check_typedef (v->type ()); struct type *eltype = check_typedef (c->val->type ())->target_type (); - LONGEST offset = value_offset (v); + LONGEST offset = v->offset (); LONGEST elsize = eltype->length (); int n, i, j = 0; LONGEST lowb = 0; diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c index f33a13e8a55..9aa2c06cec1 100644 --- a/gdb/s390-tdep.c +++ b/gdb/s390-tdep.c @@ -1240,7 +1240,7 @@ s390_value_from_register (struct gdbarch *gdbarch, struct type *type, && type->length () < 8) || regnum_is_vxr_full (tdep, regnum) || (regnum >= S390_V16_REGNUM && regnum <= S390_V31_REGNUM)) - set_value_offset (value, 0); + value->set_offset (0); return value; } diff --git a/gdb/valops.c b/gdb/valops.c index e522f8466ac..dce166d2532 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -1121,7 +1121,7 @@ value_assign (struct value *toval, struct value *fromval) case lval_internalvar_component: { - LONGEST offset = value_offset (toval); + LONGEST offset = toval->offset (); /* Are we dealing with a bitfield? @@ -1132,7 +1132,7 @@ value_assign (struct value *toval, struct value *fromval) /* VALUE_INTERNALVAR below refers to the parent value, while the offset is relative to this parent value. */ gdb_assert (toval->parent ()->parent () == NULL); - offset += value_offset (toval->parent ()); + offset += toval->parent ()->offset (); } set_internalvar_component (VALUE_INTERNALVAR (toval), @@ -1154,7 +1154,7 @@ value_assign (struct value *toval, struct value *fromval) { struct value *parent = toval->parent (); - changed_addr = value_address (parent) + value_offset (toval); + changed_addr = value_address (parent) + toval->offset (); changed_len = (toval->bitpos () + toval->bitsize () + HOST_CHAR_BIT - 1) @@ -1216,7 +1216,7 @@ value_assign (struct value *toval, struct value *fromval) if (toval->bitsize ()) { struct value *parent = toval->parent (); - LONGEST offset = value_offset (parent) + value_offset (toval); + LONGEST offset = parent->offset () + toval->offset (); size_t changed_len; gdb_byte buffer[sizeof (LONGEST)]; int optim, unavail; @@ -1263,7 +1263,7 @@ value_assign (struct value *toval, struct value *fromval) } else put_frame_register_bytes (frame, value_reg, - value_offset (toval), + toval->offset (), value_contents (fromval)); } @@ -2560,7 +2560,7 @@ find_method_list (struct value **argp, const char *method, { base_offset = baseclass_offset (type, i, value_contents_for_printing (*argp).data (), - value_offset (*argp) + offset, + (*argp)->offset () + offset, value_address (*argp), *argp); } else /* Non-virtual base, simply use bit position from debug @@ -3531,7 +3531,7 @@ get_baseclass_offset (struct type *vt, struct type *cls, if (BASETYPE_VIA_VIRTUAL (vt, i)) { const gdb_byte *adr = value_contents_for_printing (v).data (); - *boffs = baseclass_offset (vt, i, adr, value_offset (v), + *boffs = baseclass_offset (vt, i, adr, v->offset (), value_as_long (v), v); *isvirt = true; } @@ -3545,7 +3545,7 @@ get_baseclass_offset (struct type *vt, struct type *cls, if (*isvirt == false) /* Add non-virtual base offset. */ { const gdb_byte *adr = value_contents_for_printing (v).data (); - *boffs += baseclass_offset (vt, i, adr, value_offset (v), + *boffs += baseclass_offset (vt, i, adr, v->offset (), value_as_long (v), v); } return true; @@ -4089,7 +4089,7 @@ value_slice (struct value *array, int lowbound, int length) } set_value_component_location (slice, array); - set_value_offset (slice, value_offset (array) + offset); + slice->set_offset (array->offset () + offset); } return slice; diff --git a/gdb/value.c b/gdb/value.c index 2a53144b161..9b9b022bf27 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1024,17 +1024,6 @@ allocate_optimized_out_value (struct type *type) /* Accessor methods. */ -LONGEST -value_offset (const struct value *value) -{ - return value->m_offset; -} -void -set_value_offset (struct value *value, LONGEST offset) -{ - value->m_offset = offset; -} - gdb::array_view value_contents_raw (struct value *value) { @@ -3086,7 +3075,7 @@ value_primitive_field (struct value *arg1, LONGEST offset, value_enclosing_type (arg1)->length ()); } v->m_type = type; - v->m_offset = value_offset (arg1); + v->m_offset = arg1->offset (); v->m_embedded_offset = offset + value_embedded_offset (arg1) + boffset; } else if (NULL != TYPE_DATA_LOCATION (type)) @@ -3119,7 +3108,7 @@ value_primitive_field (struct value *arg1, LONGEST offset, arg1, value_embedded_offset (arg1) + offset, type_length_units (type)); } - v->m_offset = (value_offset (arg1) + offset + v->m_offset = (arg1->offset () + offset + value_embedded_offset (arg1)); } set_value_component_location (v, arg1); @@ -3188,7 +3177,7 @@ value_fn_field (struct value **arg1p, struct fn_field *f, value_addr (*arg1p))); /* Move the `this' pointer according to the offset. - VALUE_OFFSET (*arg1p) += offset; */ + (*arg1p)->offset () += offset; */ } return v; @@ -3721,7 +3710,7 @@ value_from_component (struct value *whole, struct type *type, LONGEST offset) whole, value_embedded_offset (whole) + offset, type_length_units (type)); } - v->m_offset = value_offset (whole) + offset + value_embedded_offset (whole); + v->m_offset = whole->offset () + offset + value_embedded_offset (whole); set_value_component_location (v, whole); return v; @@ -3918,7 +3907,7 @@ value_fetch_lazy_bitfield (struct value *val) unpack_value_bitfield (val, val->bitpos (), val->bitsize (), value_contents_for_printing (parent).data (), - value_offset (val), parent); + val->offset (), parent); } /* Helper for value_fetch_lazy when the value is in memory. */ @@ -3962,7 +3951,7 @@ value_fetch_lazy_register (struct value *val) /* Offsets are not supported here; lazy register values must refer to the entire register. */ - gdb_assert (value_offset (val) == 0); + gdb_assert (val->offset () == 0); while (VALUE_LVAL (new_val) == lval_register && value_lazy (new_val)) { diff --git a/gdb/value.h b/gdb/value.h index 9857c4339bf..146848b40f1 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -198,6 +198,17 @@ struct value void set_parent (struct value *parent) { m_parent = value_ref_ptr::new_reference (parent); } + /* Describes offset of a value within lval of a structure in bytes. + If lval == lval_memory, this is an offset to the address. If + lval == lval_register, this is a further offset from + location.address within the registers structure. Note also the + member embedded_offset below. */ + LONGEST offset () const + { return m_offset; } + + void set_offset (LONGEST offset) + { m_offset = offset; } + /* Type of value; either not an lval, or one of the various different possible kinds of lval. */ @@ -376,15 +387,6 @@ struct value ULONGEST m_limited_length = 0; }; -/* Describes offset of a value within lval of a structure in bytes. - If lval == lval_memory, this is an offset to the address. If lval - == lval_register, this is a further offset from location.address - within the registers structure. Note also the member - embedded_offset below. */ - -extern LONGEST value_offset (const struct value *); -extern void set_value_offset (struct value *, LONGEST offset); - /* The comment from "struct value" reads: ``Is it modifiable? Only relevant if lval != not_lval.''. Shouldn't the value instead be not_lval and be done with it? */ -- 2.39.1