Turn some value offset functions into method

This changes various offset-related functions to be methods 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:40:38 -07:00
parent 463b870d01
commit 391f86284f
13 changed files with 72 additions and 88 deletions

View file

@ -199,8 +199,8 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
if (check_typedef (v0->type ())->length ()
!= check_typedef (v1->type ())->length ())
break;
if (!value_contents_eq (v0, value_embedded_offset (v0),
v1, value_embedded_offset (v1),
if (!value_contents_eq (v0, v0->embedded_offset (),
v1, v1->embedded_offset (),
check_typedef (v0->type ())->length ()))
break;
}

View file

@ -124,7 +124,7 @@ extern struct value *value_virtual_fn_field (struct value **valuep,
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_embedded_offset (VALUE) + *TOP
VALUE->embedded_offset () + *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

View file

@ -282,7 +282,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
opts->deref_ref = false;
v = value_field_bitfield (type, i, valaddr,
value_embedded_offset (val), val);
val->embedded_offset (), val);
common_val_print (v, stream, recurse + 1,
opts, current_language);
@ -321,7 +321,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
{
CORE_ADDR addr;
i_offset += value_embedded_offset (val);
i_offset += val->embedded_offset ();
addr = extract_typed_address (valaddr + i_offset, i_type);
print_function_pointer_address (opts,
type->arch (),
@ -432,7 +432,7 @@ cp_print_value (struct value *val, struct ui_file *stream,
try
{
boffset = baseclass_offset (type, i, valaddr,
value_embedded_offset (val),
val->embedded_offset (),
address, val);
}
catch (const gdb_exception_error &ex)

View file

@ -81,7 +81,7 @@ d_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
switch (type->code ())
{
case TYPE_CODE_STRUCT:
ret = dynamic_array_type (type, value_embedded_offset (val),
ret = dynamic_array_type (type, val->embedded_offset (),
value_address (val),
stream, recurse, val, options);
if (ret == 0)

View file

@ -576,7 +576,7 @@ coerce_pieced_ref (const value *value)
{
struct type *type = check_typedef (value->type ());
if (value_bits_synthetic_pointer (value, value_embedded_offset (value),
if (value_bits_synthetic_pointer (value, value->embedded_offset (),
TARGET_CHAR_BIT * type->length ()))
{
const piece_closure *closure

View file

@ -965,7 +965,7 @@ structop_base_operation::evaluate_funcall
``this'' changes. */
vals[0] = value_from_longest (lookup_pointer_type (temp->type ()),
value_address (temp)
+ value_embedded_offset (temp));
+ temp->embedded_offset ());
}
/* Take out `this' if needed. */

View file

@ -4008,7 +4008,7 @@ is_unique_ancestor (struct type *base, struct value *val)
return is_unique_ancestor_worker (base, val->type (), &offset,
value_contents_for_printing (val).data (),
value_embedded_offset (val),
val->embedded_offset (),
value_address (val), val) == 1;
}

View file

@ -326,7 +326,7 @@ gnuv3_rtti_type (struct value *value,
/* Find the linker symbol for this vtable. */
vtable_symbol
= lookup_minimal_symbol_by_pc (value_address (vtable)
+ value_embedded_offset (vtable)).minsym;
+ vtable->embedded_offset ()).minsym;
if (! vtable_symbol)
return NULL;
@ -371,7 +371,7 @@ gnuv3_rtti_type (struct value *value,
= value_as_long (value_field (vtable, vtable_field_offset_to_top));
if (full_p)
*full_p = (- offset_to_top == value_embedded_offset (value)
*full_p = (- offset_to_top == value->embedded_offset ()
&& (value->enclosing_type ()->length ()
>= run_time_type->length ()));
if (top_p)
@ -804,7 +804,7 @@ hash_value_and_voffset (const void *p)
{
const struct value_and_voffset *o = (const struct value_and_voffset *) p;
return value_address (o->value) + value_embedded_offset (o->value);
return value_address (o->value) + o->value->embedded_offset ();
}
/* Equality function for value_and_voffset. */
@ -815,8 +815,8 @@ eq_value_and_voffset (const void *a, const void *b)
const struct value_and_voffset *ova = (const struct value_and_voffset *) a;
const struct value_and_voffset *ovb = (const struct value_and_voffset *) b;
return (value_address (ova->value) + value_embedded_offset (ova->value)
== value_address (ovb->value) + value_embedded_offset (ovb->value));
return (value_address (ova->value) + ova->value->embedded_offset ()
== value_address (ovb->value) + ovb->value->embedded_offset ());
}
/* Comparison function for value_and_voffset. */
@ -826,9 +826,9 @@ compare_value_and_voffset (const struct value_and_voffset *va,
const struct value_and_voffset *vb)
{
CORE_ADDR addra = (value_address (va->value)
+ value_embedded_offset (va->value));
+ va->value->embedded_offset ());
CORE_ADDR addrb = (value_address (vb->value)
+ value_embedded_offset (vb->value));
+ vb->value->embedded_offset ());
return addra < addrb;
}
@ -908,7 +908,7 @@ print_one_vtable (struct gdbarch *gdbarch, struct value *value,
vtable = gnuv3_get_vtable (gdbarch, type,
value_address (value)
+ value_embedded_offset (value));
+ value->embedded_offset ());
vt_addr = value_address (value_field (vtable,
vtable_field_virtual_functions));
@ -916,7 +916,7 @@ print_one_vtable (struct gdbarch *gdbarch, struct value *value,
TYPE_SAFE_NAME (type),
paddress (gdbarch, vt_addr),
paddress (gdbarch, (value_address (value)
+ value_embedded_offset (value))));
+ value->embedded_offset ())));
for (i = 0; i <= max_voffset; ++i)
{
@ -1138,7 +1138,7 @@ gnuv3_get_typeid (struct value *value)
&& gnuv3_dynamic_class (type))
{
struct value *vtable, *typeinfo_value;
CORE_ADDR address = value_address (value) + value_embedded_offset (value);
CORE_ADDR address = value_address (value) + value->embedded_offset ();
vtable = gnuv3_get_vtable (gdbarch, type, address);
if (vtable == NULL)

View file

@ -104,7 +104,7 @@ go_language::value_print_inner (struct value *val, struct ui_file *stream,
case GO_TYPE_STRING:
if (! options->raw)
{
print_go_string (type, value_embedded_offset (val),
print_go_string (type, val->embedded_offset (),
value_address (val),
stream, recurse, val, options);
return;

View file

@ -507,7 +507,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
to its representation. */
|| (val_print_scalar_type_p (arg->val->type ())
&& !value_bytes_available (arg->val,
value_embedded_offset (arg->val),
arg->val->embedded_offset (),
arg->val->type ()->length ()))))
return;

View file

@ -275,9 +275,9 @@ value_cast_structs (struct type *type, struct value *v2)
if (v)
{
/* Downcasting is possible (t1 is superclass of v2). */
CORE_ADDR addr2 = value_address (v2) + value_embedded_offset (v2);
CORE_ADDR addr2 = value_address (v2) + v2->embedded_offset ();
addr2 -= value_address (v) + value_embedded_offset (v);
addr2 -= value_address (v) + v->embedded_offset ();
return value_at (type, addr2);
}
}
@ -328,7 +328,7 @@ value_cast_pointers (struct type *type, struct value *arg2,
arg2 = value_copy (arg2);
arg2->deprecated_set_type (type);
arg2->set_enclosing_type (type);
set_value_pointed_to_offset (arg2, 0); /* pai: chk_val */
arg2->set_pointed_to_offset (0); /* pai: chk_val */
return arg2;
}
@ -650,7 +650,7 @@ value_cast (struct type *type, struct value *arg2)
arg2 = value_copy (arg2);
arg2->deprecated_set_type (to_type);
arg2->set_enclosing_type (to_type);
set_value_pointed_to_offset (arg2, 0); /* pai: chk_val */
arg2->set_pointed_to_offset (0); /* pai: chk_val */
return arg2;
}
else if (VALUE_LVAL (arg2) == lval_memory)
@ -884,7 +884,7 @@ value_dynamic_cast (struct type *type, struct value *arg)
else if (using_enc)
addr += top;
else
addr += top + value_embedded_offset (arg);
addr += top + arg->embedded_offset ();
/* dynamic_cast<void *> means to return a pointer to the
most-derived object. */
@ -903,7 +903,7 @@ value_dynamic_cast (struct type *type, struct value *arg)
result = NULL;
if (dynamic_cast_check_1 (resolved_type->target_type (),
value_contents_for_printing (tem).data (),
value_embedded_offset (tem),
tem->embedded_offset (),
value_address (tem), tem,
rtti_type, addr,
arg_type,
@ -919,7 +919,7 @@ value_dynamic_cast (struct type *type, struct value *arg)
if (is_public_ancestor (arg_type, rtti_type)
&& dynamic_cast_check_2 (resolved_type->target_type (),
value_contents_for_printing (tem).data (),
value_embedded_offset (tem),
tem->embedded_offset (),
value_address (tem), tem,
rtti_type, &result) == 1)
return value_cast (type,
@ -1353,7 +1353,7 @@ value_assign (struct value *toval, struct value *fromval)
if (type->code () == TYPE_CODE_PTR)
{
val->set_enclosing_type (fromval->enclosing_type ());
set_value_pointed_to_offset (val, value_pointed_to_offset (fromval));
val->set_pointed_to_offset (fromval->pointed_to_offset ());
}
return val;
@ -1556,7 +1556,7 @@ value_addr (struct value *arg1)
if (TYPE_IS_REFERENCE (type))
{
if (value_bits_synthetic_pointer (arg1, value_embedded_offset (arg1),
if (value_bits_synthetic_pointer (arg1, arg1->embedded_offset (),
TARGET_CHAR_BIT * type->length ()))
arg1 = coerce_ref (arg1);
else
@ -1592,14 +1592,14 @@ value_addr (struct value *arg1)
/* Get target memory address. */
arg2 = value_from_pointer (lookup_pointer_type (arg1->type ()),
(value_address (arg1)
+ value_embedded_offset (arg1)));
+ arg1->embedded_offset ()));
/* This may be a pointer to a base subobject; so remember the
full derived object's type ... */
arg2->set_enclosing_type (lookup_pointer_type (arg1->enclosing_type ()));
/* ... and also the relative position of the subobject in the full
object. */
set_value_pointed_to_offset (arg2, value_embedded_offset (arg1));
arg2->set_pointed_to_offset (arg1->embedded_offset ());
return arg2;
}
@ -1671,7 +1671,7 @@ value_ind (struct value *arg1)
{
/* Retrieve the enclosing object pointed to. */
base_addr = (value_as_address (arg1)
- value_pointed_to_offset (arg1));
- arg1->pointed_to_offset ());
}
arg2 = value_at_lazy (enc_type, base_addr);
enc_type = arg2->type ();
@ -2076,7 +2076,7 @@ struct_field_searcher::search (struct value *arg1, LONGEST offset,
int found_baseclass = (m_looking_for_baseclass
&& TYPE_BASECLASS_NAME (type, i) != NULL
&& (strcmp_iw (m_name, basetype->name ()) == 0));
LONGEST boffset = value_embedded_offset (arg1) + offset;
LONGEST boffset = arg1->embedded_offset () + offset;
if (BASETYPE_VIA_VIRTUAL (type, i))
{
@ -2084,7 +2084,7 @@ struct_field_searcher::search (struct value *arg1, LONGEST offset,
boffset = baseclass_offset (type, i,
value_contents_for_printing (arg1).data (),
value_embedded_offset (arg1) + offset,
arg1->embedded_offset () + offset,
value_address (arg1),
arg1);
@ -2092,7 +2092,7 @@ struct_field_searcher::search (struct value *arg1, LONGEST offset,
by the user program. Make sure that it still points to a
valid memory location. */
boffset += value_embedded_offset (arg1) + offset;
boffset += arg1->embedded_offset () + offset;
if (boffset < 0
|| boffset >= arg1->enclosing_type ()->length ())
{
@ -2109,7 +2109,7 @@ struct_field_searcher::search (struct value *arg1, LONGEST offset,
{
v2 = value_copy (arg1);
v2->deprecated_set_type (basetype);
set_value_embedded_offset (v2, boffset);
v2->set_embedded_offset (boffset);
}
if (found_baseclass)
@ -3978,11 +3978,11 @@ value_full_object (struct value *argp,
object, adjusting for the embedded offset of argp if that's what
value_rtti_type used for its computation. */
new_val = value_at_lazy (real_type, value_address (argp) - top +
(using_enc ? 0 : value_embedded_offset (argp)));
(using_enc ? 0 : argp->embedded_offset ()));
new_val->deprecated_set_type (argp->type ());
set_value_embedded_offset (new_val, (using_enc
? top + value_embedded_offset (argp)
: top));
new_val->set_embedded_offset ((using_enc
? top + argp->embedded_offset ()
: top));
return new_val;
}

View file

@ -1406,30 +1406,6 @@ value_bits_synthetic_pointer (const struct value *value,
length);
}
LONGEST
value_embedded_offset (const struct value *value)
{
return value->m_embedded_offset;
}
void
set_value_embedded_offset (struct value *value, LONGEST val)
{
value->m_embedded_offset = val;
}
LONGEST
value_pointed_to_offset (const struct value *value)
{
return value->m_pointed_to_offset;
}
void
set_value_pointed_to_offset (struct value *value, LONGEST val)
{
value->m_pointed_to_offset = val;
}
const struct lval_funcs *
value_computed_funcs (const struct value *v)
{
@ -1619,7 +1595,7 @@ value_copy (const value *arg)
val->m_bitpos = arg->m_bitpos;
val->m_bitsize = arg->m_bitsize;
val->m_lazy = arg->m_lazy;
val->m_embedded_offset = value_embedded_offset (arg);
val->m_embedded_offset = arg->embedded_offset ();
val->m_pointed_to_offset = arg->m_pointed_to_offset;
val->m_modifiable = arg->m_modifiable;
val->m_stack = arg->m_stack;
@ -1691,8 +1667,8 @@ value_non_lval (struct value *arg)
copy (value_contents_all (arg), value_contents_all_raw (val));
val->m_type = arg->m_type;
set_value_embedded_offset (val, value_embedded_offset (arg));
set_value_pointed_to_offset (val, value_pointed_to_offset (arg));
val->set_embedded_offset (arg->embedded_offset ());
val->set_pointed_to_offset (arg->pointed_to_offset ());
return val;
}
return arg;
@ -3023,7 +2999,7 @@ value_primitive_field (struct value *arg1, LONGEST offset,
v->m_bitpos = bitpos % container_bitsize;
else
v->m_bitpos = bitpos % 8;
v->m_offset = (value_embedded_offset (arg1)
v->m_offset = (arg1->embedded_offset ()
+ offset
+ (bitpos - v->m_bitpos) / 8);
v->set_parent (arg1);
@ -3047,7 +3023,7 @@ value_primitive_field (struct value *arg1, LONGEST offset,
if (BASETYPE_VIA_VIRTUAL (arg_type, fieldno))
boffset = baseclass_offset (arg_type, fieldno,
value_contents (arg1).data (),
value_embedded_offset (arg1),
arg1->embedded_offset (),
value_address (arg1),
arg1);
else
@ -3063,7 +3039,7 @@ value_primitive_field (struct value *arg1, LONGEST offset,
}
v->m_type = type;
v->m_offset = arg1->offset ();
v->m_embedded_offset = offset + value_embedded_offset (arg1) + boffset;
v->m_embedded_offset = offset + arg1->embedded_offset () + boffset;
}
else if (NULL != TYPE_DATA_LOCATION (type))
{
@ -3091,12 +3067,12 @@ value_primitive_field (struct value *arg1, LONGEST offset,
else
{
v = allocate_value (type);
value_contents_copy_raw (v, value_embedded_offset (v),
arg1, value_embedded_offset (arg1) + offset,
value_contents_copy_raw (v, v->embedded_offset (),
arg1, arg1->embedded_offset () + offset,
type_length_units (type));
}
v->m_offset = (arg1->offset () + offset
+ value_embedded_offset (arg1));
+ arg1->embedded_offset ());
}
set_value_component_location (v, arg1);
return v;
@ -3693,11 +3669,11 @@ value_from_component (struct value *whole, struct type *type, LONGEST offset)
else
{
v = allocate_value (type);
value_contents_copy (v, value_embedded_offset (v),
whole, value_embedded_offset (whole) + offset,
value_contents_copy (v, v->embedded_offset (),
whole, whole->embedded_offset () + offset,
type_length_units (type));
}
v->m_offset = whole->offset () + offset + value_embedded_offset (whole);
v->m_offset = whole->offset () + offset + whole->embedded_offset ();
set_value_component_location (v, whole);
return v;
@ -3721,14 +3697,14 @@ value_from_component_bitsize (struct value *whole, struct type *type,
struct value *v = allocate_value (type);
LONGEST dst_offset = TARGET_CHAR_BIT * value_embedded_offset (v);
LONGEST dst_offset = TARGET_CHAR_BIT * v->embedded_offset ();
if (is_scalar_type (type) && type_byte_order (type) == BFD_ENDIAN_BIG)
dst_offset += TARGET_CHAR_BIT * type->length () - bit_length;
value_contents_copy_raw_bitwise (v, dst_offset,
whole,
TARGET_CHAR_BIT
* value_embedded_offset (whole)
* whole->embedded_offset ()
+ bit_offset,
bit_length);
return v;
@ -3773,7 +3749,7 @@ readjust_indirect_value_type (struct value *value, struct type *enc_type,
/* Add embedding info. */
value->set_enclosing_type (enc_type);
set_value_embedded_offset (value, value_pointed_to_offset (original_value));
value->set_embedded_offset (original_value->pointed_to_offset ());
/* We may be pointing to an object of some derived type. */
return value_full_object (value, NULL, 0, 0, 0);
@ -3989,8 +3965,8 @@ value_fetch_lazy_register (struct value *val)
/* Copy the contents and the unavailability/optimized-out
meta-data from NEW_VAL to VAL. */
set_value_lazy (val, 0);
value_contents_copy (val, value_embedded_offset (val),
new_val, value_embedded_offset (new_val),
value_contents_copy (val, val->embedded_offset (),
new_val, new_val->embedded_offset (),
type_length_units (type));
if (frame_debug)

View file

@ -215,6 +215,19 @@ struct value
int deprecated_modifiable () const
{ return m_modifiable; }
LONGEST pointed_to_offset () const
{ return m_pointed_to_offset; }
void set_pointed_to_offset (LONGEST val)
{ m_pointed_to_offset = val; }
LONGEST embedded_offset () const
{ return m_embedded_offset; }
void set_embedded_offset (LONGEST val)
{ m_embedded_offset = val; }
/* If a value represents a C++ object, then the `type' field gives the
object's compile-time type. If the object actually belongs to some
class derived from `type', perhaps with other base classes and
@ -455,11 +468,6 @@ extern struct type *value_actual_type (struct value *value,
int resolve_simple_types,
int *real_type_found);
extern LONGEST value_pointed_to_offset (const struct value *value);
extern void set_value_pointed_to_offset (struct value *value, LONGEST val);
extern LONGEST value_embedded_offset (const struct value *value);
extern void set_value_embedded_offset (struct value *value, LONGEST val);
/* For lval_computed values, this structure holds functions used to
retrieve and set the value (or portions of the value).