From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 10/47] Turn value_offset into method
Date: Thu, 09 Feb 2023 14:38:31 -0700 [thread overview]
Message-ID: <20230209-submit-value-fixups-2023-v1-10-55dc2794dbb9@tromey.com> (raw)
In-Reply-To: <20230209-submit-value-fixups-2023-v1-0-55dc2794dbb9@tromey.com>
This changes value_offset to be a method of value. Much of this patch
was written by script.
---
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 | 21 ++++++++++++---------
12 files changed, 45 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 7e3bb715a3c..1c56b353e27 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1862,7 +1862,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 2037a8fc8cc..276c171f0bc 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 9704d25be76..64c1bf03956 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -894,17 +894,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<gdb_byte>
value_contents_raw (struct value *value)
{
@@ -2922,7 +2911,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))
@@ -2955,7 +2944,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);
@@ -3024,7 +3013,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;
@@ -3557,7 +3546,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;
@@ -3754,7 +3743,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. */
@@ -3785,7 +3774,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 d0e6b0363e4..d79455cc345 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -198,6 +198,18 @@ 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. */
@@ -365,15 +377,6 @@ struct value
std::vector<range> m_optimized_out;
};
-/* 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
next prev parent reply other threads:[~2023-02-09 21:38 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-09 21:38 [PATCH 00/47] Use methods for struct value Tom Tromey
2023-02-09 21:38 ` [PATCH 01/47] Rename all fields of " Tom Tromey
2023-02-10 21:05 ` Tom Tromey
2023-02-09 21:38 ` [PATCH 02/47] Move ~value body out-of-line Tom Tromey
2023-02-09 21:38 ` [PATCH 03/47] Move struct value to value.h Tom Tromey
2023-02-09 21:38 ` [PATCH 04/47] Turn value_type into method Tom Tromey
2023-02-09 21:38 ` [PATCH 05/47] Turn deprecated_set_value_type into a method Tom Tromey
2023-02-09 21:38 ` [PATCH 06/47] Turn value_arch into method Tom Tromey
2023-02-10 2:08 ` Simon Marchi
2023-02-10 16:36 ` Tom Tromey
2023-02-09 21:38 ` [PATCH 07/47] Turn value_bitsize " Tom Tromey
2023-02-09 21:38 ` [PATCH 08/47] Turn value_bitpos " Tom Tromey
2023-02-09 21:38 ` [PATCH 09/47] Turn value_parent " Tom Tromey
2023-02-09 21:38 ` Tom Tromey [this message]
2023-02-09 21:38 ` [PATCH 11/47] Turn deprecated_value_modifiable " Tom Tromey
2023-02-09 21:38 ` [PATCH 12/47] Turn value_enclosing_type " Tom Tromey
2023-02-09 21:38 ` [PATCH 13/47] Turn some value offset functions " Tom Tromey
2023-02-09 21:38 ` [PATCH 14/47] Turn value_lazy and set_value_lazy functions into methods Tom Tromey
2023-02-09 21:38 ` [PATCH 15/47] Turn value_stack and set_value_stack " Tom Tromey
2023-02-09 21:38 ` [PATCH 16/47] Turn value_computed_closure and value_computed_funcs " Tom Tromey
2023-02-09 21:38 ` [PATCH 17/47] Convert value_lval_const and deprecated_lval_hack to methods Tom Tromey
2023-02-09 21:38 ` [PATCH 18/47] Turn value_initialized and set_value_initialized functions into methods Tom Tromey
2023-02-09 21:38 ` [PATCH 19/47] Turn value_address and set_value_address " Tom Tromey
2023-02-09 21:38 ` [PATCH 20/47] Turn more deprecated_* " Tom Tromey
2023-02-09 21:38 ` [PATCH 21/47] Turn allocate_value_lazy into a static "constructor" Tom Tromey
2023-02-09 21:38 ` [PATCH 22/47] Turn allocate_value " Tom Tromey
2023-02-09 21:38 ` [PATCH 23/47] Turn allocate_computed_value into " Tom Tromey
2023-02-09 21:38 ` [PATCH 24/47] Turn allocate_optimized_out_value " Tom Tromey
2023-02-09 21:38 ` [PATCH 25/47] Turn value_zero " Tom Tromey
2023-02-09 21:38 ` [PATCH 26/47] Turn some value_contents functions into methods Tom Tromey
2023-02-09 21:38 ` [PATCH 27/47] Turn value_fetch_lazy into a method Tom Tromey
2023-02-09 21:38 ` [PATCH 28/47] Turn allocate_value_contents " Tom Tromey
2023-02-09 21:38 ` [PATCH 29/47] Turn value_contents_eq " Tom Tromey
2023-02-10 2:18 ` Simon Marchi
2023-02-10 17:46 ` Tom Tromey
2023-02-09 21:38 ` [PATCH 30/47] Turn value_bits_synthetic_pointer " Tom Tromey
2023-02-09 21:38 ` [PATCH 31/47] Move value_ref_policy methods out-of-line Tom Tromey
2023-02-09 21:38 ` [PATCH 32/47] Turn value_incref and value_decref into methods Tom Tromey
2023-02-09 21:38 ` [PATCH 33/47] Turn remaining value_contents functions " Tom Tromey
2023-02-10 2:24 ` Simon Marchi
2023-02-10 17:46 ` Tom Tromey
2023-02-09 21:38 ` [PATCH 34/47] Fully qualify calls to copy in value.c Tom Tromey
2023-02-09 21:38 ` [PATCH 35/47] Turn value_copy into a method Tom Tromey
2023-02-10 2:42 ` Simon Marchi
2023-02-10 18:03 ` Tom Tromey
2023-02-09 21:38 ` [PATCH 36/47] Turn many optimized-out value functions into methods Tom Tromey
2023-02-09 21:38 ` [PATCH 37/47] Turn value_non_lval and value_force_lval " Tom Tromey
2023-02-09 21:38 ` [PATCH 38/47] Turn set_value_component_location into method Tom Tromey
2023-02-09 21:39 ` [PATCH 39/47] Change some code to use value methods Tom Tromey
2023-02-09 21:39 ` [PATCH 40/47] Turn some xmethod functions into methods Tom Tromey
2023-02-09 21:39 ` [PATCH 41/47] Turn preserve_one_value into method Tom Tromey
2023-02-09 21:39 ` [PATCH 42/47] Turn various value copying-related functions into methods Tom Tromey
2023-02-10 20:20 ` Tom Tromey
2023-02-09 21:39 ` [PATCH 43/47] Add value::set_modifiable Tom Tromey
2023-02-09 21:39 ` [PATCH 44/47] Make struct value data members private Tom Tromey
2023-02-09 21:39 ` [PATCH 45/47] Make ~value private Tom Tromey
2023-02-09 21:39 ` [PATCH 46/47] Introduce set_lval method on value Tom Tromey
2023-02-09 21:39 ` [PATCH 47/47] Remove deprecated_lval_hack Tom Tromey
2023-02-10 2:54 ` [PATCH 00/47] Use methods for struct value Simon Marchi
2023-02-10 18:08 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230209-submit-value-fixups-2023-v1-10-55dc2794dbb9@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).