]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: remove embedded_offset argument that is always 0
authorAndrew Burgess <aburgess@redhat.com>
Fri, 8 May 2026 20:25:11 +0000 (21:25 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Fri, 15 May 2026 11:37:33 +0000 (12:37 +0100)
For the background and motivation for this patch you should read the
previous commit.

The goal of this commit started as similar to the previous one; rename
the embedded_offset argument to generic_val_print_ref.  To do this I
started tracing back which values are passed into this function so I
could make sure the new argument name matched the usage.

But it turns out that the only value that is ever passed to this
function is zero.

I believe that, like the last commit, the embedded_offset is actually
representing the offset of a field within a value.  However, in all of
the use cases, the "field" being accessed is the entire value, hence
why we always pass 0, we are asking about the whole value starting
from the very beginning.

Given this, I couldn't bring myself to rename the argument.  Let's just
remove it.  It turns out that there's a bunch of functions in
valprint.c that take an argument called embedded_offset, which are
always zero.

This commit removes the argument, and updates the code to assume zero.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/valprint.c

index ca4a064a7c56391d54b621c0c681b6ab6fcaff98..482069fbbaa402f199e5d66382566f006dce3e04 100644 (file)
@@ -59,7 +59,6 @@ static void set_output_radix_1 (int, unsigned);
 
 static void val_print_type_code_flags (struct type *type,
                                       struct value *original_value,
-                                      int embedded_offset,
                                       struct ui_file *stream);
 
 /* Start print_max at this value.  */
@@ -561,14 +560,13 @@ generic_value_print_ptr (struct value *val, struct ui_file *stream,
 
 static void
 print_ref_address (struct type *type, const gdb_byte *address_buffer,
-                 int embedded_offset, struct ui_file *stream)
+                  struct ui_file *stream)
 {
   struct gdbarch *gdbarch = type->arch ();
 
   if (address_buffer != NULL)
     {
-      CORE_ADDR address
-       = extract_typed_address (address_buffer + embedded_offset, type);
+      CORE_ADDR address = extract_typed_address (address_buffer, type);
 
       gdb_printf (stream, "@");
       fputs_styled (paddress (gdbarch, address), address_style.style (),
@@ -598,15 +596,15 @@ get_value_addr_contents (struct value *deref_val)
 
 static void
 generic_val_print_ref (struct type *type,
-                      int embedded_offset, struct ui_file *stream, int recurse,
+                      struct ui_file *stream, int recurse,
                       struct value *original_value,
                       const struct value_print_options *options)
 {
   struct type *elttype = check_typedef (type->target_type ());
   struct value *deref_val = NULL;
   const bool value_is_synthetic
-    = original_value->bits_synthetic_pointer (TARGET_CHAR_BIT * embedded_offset,
-                                             TARGET_CHAR_BIT * type->length ());
+    = original_value->bits_synthetic_pointer (0, (TARGET_CHAR_BIT
+                                                 * type->length ()));
   const bool must_coerce_ref = ((options->addressprint && value_is_synthetic)
                                || options->deref_ref);
   const bool type_is_defined = elttype->code () != TYPE_CODE_UNDEF;
@@ -616,14 +614,9 @@ generic_val_print_ref (struct type *type,
     {
       deref_val = coerce_ref_if_computed (original_value);
 
-      if (deref_val != NULL)
-       {
-         /* More complicated computed references are not supported.  */
-         gdb_assert (embedded_offset == 0);
-       }
-      else
+      if (deref_val == nullptr)
        deref_val = value_at (type->target_type (),
-                             unpack_pointer (type, valaddr + embedded_offset));
+                             unpack_pointer (type, valaddr));
     }
   /* Else, original_value isn't a synthetic reference or we don't have to print
      the reference's contents.
@@ -643,7 +636,7 @@ generic_val_print_ref (struct type *type,
                                 ? get_value_addr_contents (deref_val)
                                 : valaddr);
 
-      print_ref_address (type, address, embedded_offset, stream);
+      print_ref_address (type, address, stream);
 
       if (options->deref_ref)
        gdb_puts (": ", stream);
@@ -747,20 +740,15 @@ generic_val_print_enum_1 (struct type *type, LONGEST val,
 /* generic_val_print helper for TYPE_CODE_ENUM.  */
 
 static void
-generic_val_print_enum (struct type *type,
-                       int embedded_offset, struct ui_file *stream,
+generic_val_print_enum (struct type *type, struct ui_file *stream,
                        struct value *original_value,
                        const struct value_print_options *options)
 {
-  LONGEST val;
-  struct gdbarch *gdbarch = type->arch ();
-  int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
-
   gdb_assert (!options->format);
 
   const gdb_byte *valaddr = original_value->contents_for_printing ().data ();
 
-  val = unpack_long (type, valaddr + embedded_offset * unit_size);
+  LONGEST val = unpack_long (type, valaddr);
 
   generic_val_print_enum_1 (type, val, stream);
 }
@@ -768,8 +756,7 @@ generic_val_print_enum (struct type *type,
 /* generic_val_print helper for TYPE_CODE_FUNC and TYPE_CODE_METHOD.  */
 
 static void
-generic_val_print_func (struct type *type,
-                       int embedded_offset, CORE_ADDR address,
+generic_val_print_func (struct type *type, CORE_ADDR address,
                        struct ui_file *stream,
                        struct value *original_value,
                        const struct value_print_options *options)
@@ -980,7 +967,7 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
 
     case TYPE_CODE_REF:
     case TYPE_CODE_RVALUE_REF:
-      generic_val_print_ref (type, 0, stream, recurse,
+      generic_val_print_ref (type, stream, recurse,
                             val, options);
       break;
 
@@ -988,14 +975,14 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
       if (options->format)
        value_print_scalar_formatted (val, options, 0, stream);
       else
-       generic_val_print_enum (type, 0, stream, val, options);
+       generic_val_print_enum (type, stream, val, options);
       break;
 
     case TYPE_CODE_FLAGS:
       if (options->format)
        value_print_scalar_formatted (val, options, 0, stream);
       else
-       val_print_type_code_flags (type, val, 0, stream);
+       val_print_type_code_flags (type, val, stream);
       break;
 
     case TYPE_CODE_FUNC:
@@ -1003,7 +990,7 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
       if (options->format)
        value_print_scalar_formatted (val, options, 0, stream);
       else
-       generic_val_print_func (type, 0, val->address (), stream,
+       generic_val_print_func (type, val->address (), stream,
                                val, options);
       break;
 
@@ -1257,10 +1244,9 @@ debug_val (struct value *val)
 
 static void
 val_print_type_code_flags (struct type *type, struct value *original_value,
-                          int embedded_offset, struct ui_file *stream)
+                          struct ui_file *stream)
 {
-  const gdb_byte *valaddr = (original_value->contents_for_printing ().data ()
-                            + embedded_offset);
+  const gdb_byte *valaddr = (original_value->contents_for_printing ().data ());
   ULONGEST val = unpack_long (type, valaddr);
   int field, nfields = type->num_fields ();
   struct gdbarch *gdbarch = type->arch ();
@@ -2626,7 +2612,7 @@ test_print_flags (gdbarch *arch)
   store_unsigned_integer (contents, 4, gdbarch_byte_order (arch), 0xaa);
 
   string_file out;
-  val_print_type_code_flags (flags_type, val, 0, &out);
+  val_print_type_code_flags (flags_type, val, &out);
   SELF_CHECK (out.string () == "[ A=2 B=1 C=5 ]");
 }