[v3,11/50] Turn value_offset into method

Message ID 20230209-submit-value-fixups-2023-v3-11-45e91a20c742@tromey.com
State Committed
Commit 76675c4d0bc454ed1ae369f98ad848754d0e81a0
Headers
Series Use methods for struct value |

Commit Message

Tom Tromey Feb. 13, 2023, 3:15 a.m. UTC
  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>
---
 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(-)
  

Patch

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<gdb_byte>
 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?  */