]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Turn value_field into a method
authorTom Tromey <tom@tromey.com>
Fri, 6 Feb 2026 18:17:54 +0000 (11:17 -0700)
committerTom Tromey <tom@tromey.com>
Fri, 6 Feb 2026 19:15:15 +0000 (12:15 -0700)
This changes value_field to be a method of struct value.  This was
largely written by script.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/ada-tasks.c
gdb/ada-valprint.c
gdb/ada-varobj.c
gdb/f-valprint.c
gdb/gnu-v2-abi.c
gdb/gnu-v3-abi.c
gdb/rust-lang.c
gdb/value.c
gdb/value.h

index 25da78f53dde1219b6c4cada6ff8958af40c59bf..798d9c4cb325a07b25ed54081f903d89a144656b 100644 (file)
@@ -477,15 +477,15 @@ read_fat_string_value (char *dest, struct value *val, int max_len)
 
   /* Get the size of the task image by checking the value of the bounds.
      The lower bound is always 1, so we only need to read the upper bound.  */
-  bounds_val = value_ind (value_field (val, bounds_fieldno));
-  len = value_as_long (value_field (bounds_val, upper_bound_fieldno));
+  bounds_val = value_ind (val->field (bounds_fieldno));
+  len = value_as_long (bounds_val->field (upper_bound_fieldno));
 
   /* Make sure that we do not read more than max_len characters...  */
   if (len > max_len)
     len = max_len;
 
   /* Extract LEN characters from the fat string.  */
-  array_val = value_ind (value_field (val, array_fieldno));
+  array_val = value_ind (val->field (array_fieldno));
   read_memory (array_val->address (), (gdb_byte *) dest, len);
 
   /* Add the NUL character to close the string.  */
@@ -640,13 +640,11 @@ ptid_from_atcb_common (struct value *common_value)
   const struct ada_tasks_pspace_data *pspace_data
     = get_ada_tasks_pspace_data (current_program_space);
 
-  ll_value = value_field (common_value, pspace_data->atcb_fieldno.ll);
+  ll_value = common_value->field (pspace_data->atcb_fieldno.ll);
 
   if (pspace_data->atcb_fieldno.ll_lwp >= 0)
-    lwp = value_as_address (value_field (ll_value,
-                                        pspace_data->atcb_fieldno.ll_lwp));
-  thread = value_as_long (value_field (ll_value,
-                                      pspace_data->atcb_fieldno.ll_thread));
+    lwp = value_as_address (ll_value->field (pspace_data->atcb_fieldno.ll_lwp));
+  thread = value_as_long (ll_value->field (pspace_data->atcb_fieldno.ll_thread));
 
   ptid = target_get_ada_task_ptid (lwp, thread);
 
@@ -684,7 +682,7 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
 
   tcb_value = value_from_contents_and_address (pspace_data->atcb_type,
                                               NULL, task_id);
-  common_value = value_field (tcb_value, pspace_data->atcb_fieldno.common);
+  common_value = tcb_value->field (pspace_data->atcb_fieldno.common);
 
   /* Fill in the task_id.  */
 
@@ -709,8 +707,7 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
     {
       if (pspace_data->atcb_fieldno.image >= 0)
        read_fat_string_value (task_info->name,
-                              value_field (common_value,
-                                           pspace_data->atcb_fieldno.image),
+                              common_value->field (pspace_data->atcb_fieldno.image),
                               sizeof (task_info->name) - 1);
       else
        {
@@ -741,31 +738,26 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
   else
     {
       int len = value_as_long
-                 (value_field (common_value,
-                               pspace_data->atcb_fieldno.image_len));
+       (common_value->field (pspace_data->atcb_fieldno.image_len));
 
       value_as_string (task_info->name,
-                      value_field (common_value,
-                                   pspace_data->atcb_fieldno.image),
+                      common_value->field (pspace_data->atcb_fieldno.image),
                       len);
     }
 
   /* Compute the task state and priority.  */
 
   task_info->state =
-    value_as_long (value_field (common_value,
-                               pspace_data->atcb_fieldno.state));
+    value_as_long (common_value->field (pspace_data->atcb_fieldno.state));
   task_info->priority =
-    value_as_long (value_field (common_value,
-                               pspace_data->atcb_fieldno.priority));
+    value_as_long (common_value->field (pspace_data->atcb_fieldno.priority));
 
   /* If the ATCB contains some information about the parent task,
      then compute it as well.  Otherwise, zero.  */
 
   if (pspace_data->atcb_fieldno.parent >= 0)
     task_info->parent =
-      value_as_address (value_field (common_value,
-                                    pspace_data->atcb_fieldno.parent));
+      value_as_address (common_value->field (pspace_data->atcb_fieldno.parent));
 
   /* If the task is in an entry call waiting for another task,
      then determine which task it is.  */
@@ -778,10 +770,10 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
         entry of another task; then the Task_Id of the called task is
         in My_ATCB.Entry_Calls (My_ATCB.ATC_Nesting_Level).Called_Task.  */
       atc_nesting_level_value =
-       value_field (tcb_value, pspace_data->atcb_fieldno.atc_nesting_level);
+       tcb_value->field (pspace_data->atcb_fieldno.atc_nesting_level);
       entry_calls_value =
        ada_coerce_to_simple_array_ptr
-         (value_field (tcb_value, pspace_data->atcb_fieldno.entry_calls));
+       (tcb_value->field (pspace_data->atcb_fieldno.entry_calls));
       entry_calls_value_element =
        value_subscript (entry_calls_value,
                         value_as_long (atc_nesting_level_value));
@@ -789,8 +781,7 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
        ada_get_field_index (entry_calls_value_element->type (),
                             "called_task", 0);
       task_info->called_task =
-       value_as_address (value_field (entry_calls_value_element,
-                                      called_task_fieldno));
+       value_as_address (entry_calls_value_element->field (called_task_fieldno));
     }
 
   /* If the ATCB contains some information about RV callers, then
@@ -801,8 +792,7 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
       /* Get the ID of the caller task from Common_ATCB.Call.all.Self.
         If Common_ATCB.Call is null, then there is no caller.  */
       const CORE_ADDR call =
-       value_as_address (value_field (common_value,
-                                      pspace_data->atcb_fieldno.call));
+       value_as_address (common_value->field (pspace_data->atcb_fieldno.call));
       struct value *call_val;
 
       if (call != 0)
@@ -812,14 +802,13 @@ read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
                                             NULL, call);
          task_info->caller_task =
            value_as_address
-             (value_field (call_val, pspace_data->atcb_fieldno.call_self));
+           (call_val->field (pspace_data->atcb_fieldno.call_self));
        }
     }
 
   task_info->base_cpu
     = (pspace_data->cpu_id_offset
-      + value_as_long (value_field (common_value,
-                                   pspace_data->atcb_fieldno.base_cpu)));
+       + value_as_long (common_value->field (pspace_data->atcb_fieldno.base_cpu)));
 
   /* And finally, compute the task ptid.  Note that there is not point
      in computing it if the task is no longer alive, in which case
@@ -899,10 +888,9 @@ read_known_tasks_list (struct ada_tasks_inferior_data *data)
       /* Read the chain.  */
       tcb_value = value_from_contents_and_address (pspace_data->atcb_type,
                                                   NULL, task_id);
-      common_value = value_field (tcb_value, pspace_data->atcb_fieldno.common);
+      common_value = tcb_value->field (pspace_data->atcb_fieldno.common);
       task_id = value_as_address
-                 (value_field (common_value,
-                               pspace_data->atcb_fieldno.activation_link));
+       (common_value->field (pspace_data->atcb_fieldno.activation_link));
     }
 
   return true;
index 66b083ef5edc03eb26a488394caafda951d9f347..639f4549f90821fdb83545b53d2f76d76da87e3d 100644 (file)
@@ -411,8 +411,8 @@ print_variant_part (struct value *value, int field_num,
   if (which < 0)
     return 0;
 
-  struct value *variant_field = value_field (value, field_num);
-  struct value *active_component = value_field (variant_field, which);
+  struct value *variant_field = value->field (field_num);
+  struct value *active_component = variant_field->field (which);
   return print_field_values (active_component, outer_value, stream, recurse,
                             options, comma_needed, language);
 }
@@ -520,7 +520,7 @@ print_field_values (struct value *value, struct value *outer_value,
 
          opts.deref_ref = false;
 
-         struct value *v = value_field (value, i);
+         struct value *v = value->field (i);
          common_val_print (v, stream, recurse + 1, &opts, language);
        }
       annotate_field_end ();
index 574429348a74744f0b789ed5eb4cdc012e43988c..453453bc4ee057d60d2a51e24d2d837a4d0bb7f1 100644 (file)
@@ -100,7 +100,7 @@ ada_varobj_struct_elt (struct value *parent_value,
 
   if (parent_value)
     {
-      value = value_field (parent_value, fieldno);
+      value = parent_value->field (fieldno);
       type = value->type ();
     }
   else
index e91ae972e3ed3f69036d559b5c3701c06182f8e9..c66e90c04029104a1911e100e272a046f5383b8f 100644 (file)
@@ -559,7 +559,7 @@ f_language::value_print_inner (struct value *val, struct ui_file *stream,
                  field = value_of_variable (sym.symbol, sym.block);
                }
              else
-               field = value_field (val, index);
+               field = val->field (index);
 
              if (printed_field > 0)
                gdb_puts (", ", stream);
index 55b01d982df3139916857340624d488ca47ce575..e5dcbd69c0bf302fbbf40c814be0c4db28baeeb1 100644 (file)
@@ -157,7 +157,7 @@ gnuv2_virtual_fn_field (struct value **arg1p, struct fn_field * f, int j,
     {
       /* Move the `this' pointer according to the virtual function table.  */
       arg1->set_offset (arg1->offset ()
-                       + value_as_long (value_field (entry, 0)));
+                       + value_as_long (entry->field (0)));
 
       if (!arg1->lazy ())
        {
@@ -165,7 +165,7 @@ gnuv2_virtual_fn_field (struct value **arg1p, struct fn_field * f, int j,
          arg1->fetch_lazy ();
        }
 
-      vfn = value_field (entry, 2);
+      vfn = entry->field (2);
     }
   else if (entry_type->code () == TYPE_CODE_PTR)
     vfn = entry;
@@ -231,10 +231,10 @@ gnuv2_value_rtti_type (struct value *v, int *full, LONGEST *top, int *using_enc)
   /* We can't use value_ind here, because it would want to use RTTI, and
      we'd waste a bunch of time figuring out we already know the type.
      Besides, we don't care about the type, just the actual pointer.  */
-  if (value_field (v, known_type_vptr_fieldno)->address () == 0)
+  if (v->field (known_type_vptr_fieldno)->address () == 0)
     return NULL;
 
-  vtbl = value_as_address (value_field (v, known_type_vptr_fieldno));
+  vtbl = value_as_address (v->field (known_type_vptr_fieldno));
 
   /* Try to find a symbol that is the vtable.  */
   bound_minimal_symbol minsym = lookup_minimal_symbol_by_pc (vtbl);
index 4a4ed899a06c5df5ce7dbddc609a66742022d445..3d519eaa971f613e2bf2cff88b9dbd5fc9f2fa8b 100644 (file)
@@ -376,7 +376,7 @@ gnuv3_rtti_type (struct value *value,
   /* Get the offset from VALUE to the top of the complete object.
      NOTE: this is the reverse of the meaning of *TOP_P.  */
   offset_to_top
-    = value_as_long (value_field (vtable, vtable_field_offset_to_top));
+    = value_as_long (vtable->field (vtable_field_offset_to_top));
 
   if (full_p)
     *full_p = (- offset_to_top == value->embedded_offset ()
@@ -402,7 +402,7 @@ gnuv3_get_virtual_fn (struct gdbarch *gdbarch, struct value *container,
   gdb_assert (vtable != NULL);
 
   /* Fetch the appropriate function pointer from the vtable.  */
-  vfn = value_subscript (value_field (vtable, vtable_field_virtual_functions),
+  vfn = value_subscript (vtable->field (vtable_field_virtual_functions),
                         vtable_index);
 
   /* If this architecture uses function descriptors directly in the vtable,
@@ -515,7 +515,7 @@ gnuv3_baseclass_offset (struct type *type, int index,
 
   vtable = gnuv3_get_vtable (gdbarch, type, address + embedded_offset);
   gdb_assert (vtable != NULL);
-  vbase_array = value_field (vtable, vtable_field_vcall_and_vbase_offsets);
+  vbase_array = vtable->field (vtable_field_vcall_and_vbase_offsets);
   base_offset = value_as_long (value_subscript (vbase_array, cur_base_offset));
   return base_offset;
 }
@@ -865,7 +865,7 @@ compute_vtable_size (vtable_hash_t &offset_hash, struct value *value)
 
   /* Recurse into base classes.  */
   for (i = 0; i < TYPE_N_BASECLASSES (type); ++i)
-    compute_vtable_size (offset_hash, value_field (value, i));
+    compute_vtable_size (offset_hash, value->field (i));
 }
 
 /* Helper for gnuv3_print_vtable that prints a single vtable.  */
@@ -883,8 +883,7 @@ print_one_vtable (struct gdbarch *gdbarch, struct value *value,
   vtable = gnuv3_get_vtable (gdbarch, type,
                             value->address ()
                             + value->embedded_offset ());
-  vt_addr = value_field (vtable,
-                        vtable_field_virtual_functions)->address ();
+  vt_addr = vtable->field (vtable_field_virtual_functions)->address ();
 
   gdb_printf (_("vtable for '%s' @ %s (subobject @ %s):\n"),
              TYPE_SAFE_NAME (type),
@@ -901,8 +900,7 @@ print_one_vtable (struct gdbarch *gdbarch, struct value *value,
 
       gdb_printf ("[%d]: ", i);
 
-      vfn = value_subscript (value_field (vtable,
-                                         vtable_field_virtual_functions),
+      vfn = value_subscript (vtable->field (vtable_field_virtual_functions),
                             i);
 
       if (gdbarch_vtable_function_descriptors (gdbarch))
@@ -1119,7 +1117,7 @@ gnuv3_get_typeid (struct value *value)
       if (vtable == NULL)
        error (_("cannot find typeinfo for object of type '%s'"),
               name);
-      typeinfo_value = value_field (vtable, vtable_field_type_info);
+      typeinfo_value = vtable->field (vtable_field_type_info);
       result = value_ind (value_cast (make_pointer_type (typeinfo_type),
                                      typeinfo_value));
     }
index 1695fd73344cbae8a7971a0ba7616e931a14635f..9f5c01afda4917870eba964fe9cbc50990ebb695 100644 (file)
@@ -260,7 +260,7 @@ rust_get_trait_object_pointer (struct value *value)
        return NULL;
     }
 
-  CORE_ADDR vtable = value_as_address (value_field (value, vtable_field));
+  CORE_ADDR vtable = value_as_address (value->field (vtable_field));
   struct symbol *symbol = find_symbol_at_address (vtable);
   if (symbol == NULL || symbol->subclass != SYMBOL_RUST_VTABLE)
     return NULL;
@@ -268,7 +268,7 @@ rust_get_trait_object_pointer (struct value *value)
   struct rust_vtable_symbol *vtable_sym
     = static_cast<struct rust_vtable_symbol *> (symbol);
   struct type *pointer_type = lookup_pointer_type (vtable_sym->concrete_type);
-  return value_cast (pointer_type, value_field (value, 1 - vtable_field));
+  return value_cast (pointer_type, value->field (1 - vtable_field));
 }
 
 /* Find and possibly rewrite the unsized part of a slice-like type.
@@ -620,7 +620,7 @@ rust_language::val_print_struct
          gdb_puts (": ", stream);
        }
 
-      common_val_print (value_field (val, i), stream, recurse + 1, &opts,
+      common_val_print (val->field (i), stream, recurse + 1, &opts,
                        this);
     }
 
@@ -700,7 +700,7 @@ rust_language::print_enum (struct value *val, struct ui_file *stream,
                    styled_string (variable_name_style.style (),
                                   variant_type->field (j).name ()));
 
-      common_val_print (value_field (val, j), stream, recurse + 1, &opts,
+      common_val_print (val->field (j), stream, recurse + 1, &opts,
                        this);
     }
 
@@ -1326,7 +1326,7 @@ rust_compute_range (struct type *type, struct value *range,
   if (strcmp (type->field (0).name (), "start") == 0)
     {
       *kind = RANGE_HIGH_BOUND_DEFAULT;
-      *low = value_as_long (value_field (range, 0));
+      *low = value_as_long (range->field (0));
       ++i;
     }
   if (type->num_fields () > i
@@ -1334,7 +1334,7 @@ rust_compute_range (struct type *type, struct value *range,
     {
       *kind = (*kind == (RANGE_LOW_BOUND_DEFAULT | RANGE_HIGH_BOUND_DEFAULT)
               ? RANGE_LOW_BOUND_DEFAULT : RANGE_STANDARD);
-      *high = value_as_long (value_field (range, i));
+      *high = value_as_long (range->field (i));
 
       if (rust_inclusive_range_type_p (type))
        ++*high;
@@ -1478,8 +1478,8 @@ rust_subscript_operation::subscript (struct expression *exp,
          addr = value_as_long (addrval);
          tem = value_at_lazy (slice, addr);
 
-         value_assign (value_field (tem, 0), value_addr (result));
-         value_assign (value_field (tem, 1),
+         value_assign (tem->field (0), value_addr (result));
+         value_assign (tem->field (1),
                        value_from_longest (usize, high - low));
 
          result = value_at_lazy (slice, addr);
index a52d4a6742cdf0e1ce4cea3aab210f8cd4b7d292..2d90780f57aea9416f68c770b46a0d6e00d7e849 100644 (file)
@@ -3138,16 +3138,6 @@ value::primitive_field (LONGEST offset, int fieldno, struct type *arg_type)
   return v;
 }
 
-/* Given a value ARG1 of a struct or union type,
-   extract and return the value of one of its (non-static) fields.
-   FIELDNO says which field.  */
-
-struct value *
-value_field (struct value *arg1, int fieldno)
-{
-  return arg1->primitive_field (0, fieldno, arg1->type ());
-}
-
 /* Return a non-virtual function as a value.
    F is the list of member functions which contains the desired method.
    J is an index into F which provides the desired method.
index 1ef3acd60549eb3edd4d4bea0cc4bbd02d9b8915..201db773a84f06029911587e562385af9733e843 100644 (file)
@@ -626,6 +626,14 @@ public:
   struct value *primitive_field (LONGEST offset, int fieldno,
                                 struct type *arg_type);
 
+  /* Given that this value is of a struct or union type, extract and
+     return the value of one of its (non-static) fields.  FIELDNO says
+     which field.  */
+  value *field (int fieldno)
+  {
+    return primitive_field (0, fieldno, type ());
+  }
+
   /* Create a new value by extracting it from this value.  TYPE is the
      type of the new value.  BIT_OFFSET and BIT_LENGTH describe the
      offset and field width of the value to extract from this value --
@@ -1331,8 +1339,6 @@ extern int find_overload_match (gdb::array_view<value *> args,
                                int *staticp, const int no_adl,
                                enum noside noside);
 
-extern struct value *value_field (struct value *arg1, int fieldno);
-
 extern struct type *value_rtti_indirect_type (struct value *, int *, LONGEST *,
                                              int *);