Turn value_offset into method

This changes value_offset to be a method of value.  Much of this patch
was written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
Tom Tromey
2023-01-31 10:05:01 -07:00
parent fac7bdaaab
commit 76675c4d0b
12 changed files with 44 additions and 53 deletions

View File

@ -2838,7 +2838,7 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
++new_offset; ++new_offset;
v->set_bitpos (v->bitpos () - HOST_CHAR_BIT); 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 /* Also set the parent value. This is needed when trying to
assign a new value (in inferior memory). */ assign a new value (in inferior memory). */

View File

@ -1870,7 +1870,7 @@ extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val)
w->val_bitpos, w->val_bitpos,
w->val_bitsize, w->val_bitsize,
value_contents_for_printing (val).data (), value_contents_for_printing (val).data (),
value_offset (val), val->offset (),
val); val);
return bit_val; return bit_val;

View File

@ -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 - If *USING_ENC is zero, then *TOP is the offset from the start
of the complete object to the start of the embedded subobject of the complete object to the start of the embedded subobject
VALUE represents. In other words, the enclosing object starts 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 value_embedded_offset (VALUE) + *TOP
- If *USING_ENC is non-zero, then *TOP is the offset from the - If *USING_ENC is non-zero, then *TOP is the offset from the
address of the complete object to the enclosing object stored address of the complete object to the enclosing object stored
in VALUE. In other words, the enclosing object starts at 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 If VALUE's type and enclosing type are the same, then these two
cases are equivalent. cases are equivalent.

View File

@ -168,10 +168,10 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
from_contents = nullptr; from_contents = nullptr;
} }
ULONGEST bits_to_skip = 8 * value_offset (v); ULONGEST bits_to_skip = 8 * v->offset ();
if (v->bitsize ()) if (v->bitsize ())
{ {
bits_to_skip += (8 * value_offset (v->parent ()) bits_to_skip += (8 * v->parent ()->offset ()
+ v->bitpos ()); + v->bitpos ());
if (from != nullptr if (from != nullptr
&& (type_byte_order (from->type ()) && (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); piece_closure *c = (piece_closure *) value_computed_closure (value);
int i; int i;
bit_offset += 8 * value_offset (value); bit_offset += 8 * value->offset ();
if (value->bitsize ()) if (value->bitsize ())
bit_offset += value->bitpos (); bit_offset += value->bitpos ();
@ -512,7 +512,7 @@ indirect_pieced_value (value *value)
return NULL; return NULL;
int bit_length = 8 * type->length (); int bit_length = 8 * type->length ();
LONGEST bit_offset = 8 * value_offset (value); LONGEST bit_offset = 8 * value->offset ();
if (value->bitsize ()) if (value->bitsize ())
bit_offset += value->bitpos (); 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); std::move (this->m_pieces), this->m_frame);
retval = allocate_computed_value (subobj_type, retval = allocate_computed_value (subobj_type,
&pieced_value_funcs, c); &pieced_value_funcs, c);
set_value_offset (retval, subobj_offset); retval->set_offset (subobj_offset);
} }
else else
{ {

View File

@ -822,9 +822,9 @@ default_value_from_register (struct gdbarch *gdbarch, struct type *type,
if (type_byte_order (type) == BFD_ENDIAN_BIG if (type_byte_order (type) == BFD_ENDIAN_BIG
&& len < register_size (gdbarch, regnum)) && len < register_size (gdbarch, regnum))
/* Big-endian, and we want less than full size. */ /* 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 else
set_value_offset (value, 0); value->set_offset (0);
return value; return value;
} }
@ -842,7 +842,7 @@ read_frame_register_value (struct value *value, frame_info_ptr frame)
{ {
struct gdbarch *gdbarch = get_frame_arch (frame); struct gdbarch *gdbarch = get_frame_arch (frame);
LONGEST offset = 0; LONGEST offset = 0;
LONGEST reg_offset = value_offset (value); LONGEST reg_offset = value->offset ();
int regnum = VALUE_REGNUM (value); int regnum = VALUE_REGNUM (value);
int len = type_length_units (check_typedef (value->type ())); int len = type_length_units (check_typedef (value->type ()));

View File

@ -158,7 +158,7 @@ gnuv2_virtual_fn_field (struct value **arg1p, struct fn_field * f, int j,
if (entry_type->code () == TYPE_CODE_STRUCT) if (entry_type->code () == TYPE_CODE_STRUCT)
{ {
/* Move the `this' pointer according to the virtual function table. */ /* 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))); + value_as_long (value_field (entry, 0)));
if (!value_lazy (arg1)) if (!value_lazy (arg1))

View File

@ -9144,7 +9144,7 @@ siginfo_value_read (struct value *v)
TARGET_OBJECT_SIGNAL_INFO, TARGET_OBJECT_SIGNAL_INFO,
nullptr, nullptr,
value_contents_all_raw (v).data (), value_contents_all_raw (v).data (),
value_offset (v), v->offset (),
v->type ()->length ()); v->type ()->length ());
if (transferred != 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, TARGET_OBJECT_SIGNAL_INFO,
nullptr, nullptr,
value_contents_all_raw (fromval).data (), value_contents_all_raw (fromval).data (),
value_offset (v), v->offset (),
fromval->type ()->length ()); fromval->type ()->length ());
if (transferred != fromval->type ()->length ()) if (transferred != fromval->type ()->length ())

View File

@ -122,7 +122,7 @@ lval_func_read (struct value *v)
struct lval_closure *c = (struct lval_closure *) value_computed_closure (v); struct lval_closure *c = (struct lval_closure *) value_computed_closure (v);
struct type *type = check_typedef (v->type ()); struct type *type = check_typedef (v->type ());
struct type *eltype = check_typedef (c->val->type ())->target_type (); struct type *eltype = check_typedef (c->val->type ())->target_type ();
LONGEST offset = value_offset (v); LONGEST offset = v->offset ();
LONGEST elsize = eltype->length (); LONGEST elsize = eltype->length ();
int n, i, j = 0; int n, i, j = 0;
LONGEST lowb = 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 lval_closure *c = (struct lval_closure *) value_computed_closure (v);
struct type *type = check_typedef (v->type ()); struct type *type = check_typedef (v->type ());
struct type *eltype = check_typedef (c->val->type ())->target_type (); struct type *eltype = check_typedef (c->val->type ())->target_type ();
LONGEST offset = value_offset (v); LONGEST offset = v->offset ();
LONGEST elsize = eltype->length (); LONGEST elsize = eltype->length ();
int n, i, j = 0; int n, i, j = 0;
LONGEST lowb = 0; LONGEST lowb = 0;

View File

@ -1240,7 +1240,7 @@ s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
&& type->length () < 8) && type->length () < 8)
|| regnum_is_vxr_full (tdep, regnum) || regnum_is_vxr_full (tdep, regnum)
|| (regnum >= S390_V16_REGNUM && regnum <= S390_V31_REGNUM)) || (regnum >= S390_V16_REGNUM && regnum <= S390_V31_REGNUM))
set_value_offset (value, 0); value->set_offset (0);
return value; return value;
} }

View File

@ -1121,7 +1121,7 @@ value_assign (struct value *toval, struct value *fromval)
case lval_internalvar_component: case lval_internalvar_component:
{ {
LONGEST offset = value_offset (toval); LONGEST offset = toval->offset ();
/* Are we dealing with a bitfield? /* 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 /* VALUE_INTERNALVAR below refers to the parent value, while
the offset is relative to this parent value. */ the offset is relative to this parent value. */
gdb_assert (toval->parent ()->parent () == NULL); gdb_assert (toval->parent ()->parent () == NULL);
offset += value_offset (toval->parent ()); offset += toval->parent ()->offset ();
} }
set_internalvar_component (VALUE_INTERNALVAR (toval), set_internalvar_component (VALUE_INTERNALVAR (toval),
@ -1154,7 +1154,7 @@ value_assign (struct value *toval, struct value *fromval)
{ {
struct value *parent = toval->parent (); struct value *parent = toval->parent ();
changed_addr = value_address (parent) + value_offset (toval); changed_addr = value_address (parent) + toval->offset ();
changed_len = (toval->bitpos () changed_len = (toval->bitpos ()
+ toval->bitsize () + toval->bitsize ()
+ HOST_CHAR_BIT - 1) + HOST_CHAR_BIT - 1)
@ -1216,7 +1216,7 @@ value_assign (struct value *toval, struct value *fromval)
if (toval->bitsize ()) if (toval->bitsize ())
{ {
struct value *parent = toval->parent (); struct value *parent = toval->parent ();
LONGEST offset = value_offset (parent) + value_offset (toval); LONGEST offset = parent->offset () + toval->offset ();
size_t changed_len; size_t changed_len;
gdb_byte buffer[sizeof (LONGEST)]; gdb_byte buffer[sizeof (LONGEST)];
int optim, unavail; int optim, unavail;
@ -1263,7 +1263,7 @@ value_assign (struct value *toval, struct value *fromval)
} }
else else
put_frame_register_bytes (frame, value_reg, put_frame_register_bytes (frame, value_reg,
value_offset (toval), toval->offset (),
value_contents (fromval)); value_contents (fromval));
} }
@ -2560,7 +2560,7 @@ find_method_list (struct value **argp, const char *method,
{ {
base_offset = baseclass_offset (type, i, base_offset = baseclass_offset (type, i,
value_contents_for_printing (*argp).data (), value_contents_for_printing (*argp).data (),
value_offset (*argp) + offset, (*argp)->offset () + offset,
value_address (*argp), *argp); value_address (*argp), *argp);
} }
else /* Non-virtual base, simply use bit position from debug 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)) if (BASETYPE_VIA_VIRTUAL (vt, i))
{ {
const gdb_byte *adr = value_contents_for_printing (v).data (); 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); value_as_long (v), v);
*isvirt = true; *isvirt = true;
} }
@ -3545,7 +3545,7 @@ get_baseclass_offset (struct type *vt, struct type *cls,
if (*isvirt == false) /* Add non-virtual base offset. */ if (*isvirt == false) /* Add non-virtual base offset. */
{ {
const gdb_byte *adr = value_contents_for_printing (v).data (); 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); value_as_long (v), v);
} }
return true; return true;
@ -4089,7 +4089,7 @@ value_slice (struct value *array, int lowbound, int length)
} }
set_value_component_location (slice, array); set_value_component_location (slice, array);
set_value_offset (slice, value_offset (array) + offset); slice->set_offset (array->offset () + offset);
} }
return slice; return slice;

View File

@ -1024,17 +1024,6 @@ allocate_optimized_out_value (struct type *type)
/* Accessor methods. */ /* 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> gdb::array_view<gdb_byte>
value_contents_raw (struct value *value) value_contents_raw (struct value *value)
{ {
@ -3086,7 +3075,7 @@ value_primitive_field (struct value *arg1, LONGEST offset,
value_enclosing_type (arg1)->length ()); value_enclosing_type (arg1)->length ());
} }
v->m_type = type; 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; v->m_embedded_offset = offset + value_embedded_offset (arg1) + boffset;
} }
else if (NULL != TYPE_DATA_LOCATION (type)) 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, arg1, value_embedded_offset (arg1) + offset,
type_length_units (type)); type_length_units (type));
} }
v->m_offset = (value_offset (arg1) + offset v->m_offset = (arg1->offset () + offset
+ value_embedded_offset (arg1)); + value_embedded_offset (arg1));
} }
set_value_component_location (v, arg1); set_value_component_location (v, arg1);
@ -3188,7 +3177,7 @@ value_fn_field (struct value **arg1p, struct fn_field *f,
value_addr (*arg1p))); value_addr (*arg1p)));
/* Move the `this' pointer according to the offset. /* Move the `this' pointer according to the offset.
VALUE_OFFSET (*arg1p) += offset; */ (*arg1p)->offset () += offset; */
} }
return v; return v;
@ -3721,7 +3710,7 @@ value_from_component (struct value *whole, struct type *type, LONGEST offset)
whole, value_embedded_offset (whole) + offset, whole, value_embedded_offset (whole) + offset,
type_length_units (type)); 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); set_value_component_location (v, whole);
return v; return v;
@ -3918,7 +3907,7 @@ value_fetch_lazy_bitfield (struct value *val)
unpack_value_bitfield (val, val->bitpos (), val->bitsize (), unpack_value_bitfield (val, val->bitpos (), val->bitsize (),
value_contents_for_printing (parent).data (), value_contents_for_printing (parent).data (),
value_offset (val), parent); val->offset (), parent);
} }
/* Helper for value_fetch_lazy when the value is in memory. */ /* 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 /* Offsets are not supported here; lazy register values must
refer to the entire register. */ 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)) while (VALUE_LVAL (new_val) == lval_register && value_lazy (new_val))
{ {

View File

@ -198,6 +198,17 @@ struct value
void set_parent (struct value *parent) void set_parent (struct value *parent)
{ m_parent = value_ref_ptr::new_reference (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 /* Type of value; either not an lval, or one of the various
different possible kinds of lval. */ different possible kinds of lval. */
@ -376,15 +387,6 @@ struct value
ULONGEST m_limited_length = 0; 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 /* The comment from "struct value" reads: ``Is it modifiable? Only
relevant if lval != not_lval.''. Shouldn't the value instead be relevant if lval != not_lval.''. Shouldn't the value instead be
not_lval and be done with it? */ not_lval and be done with it? */