]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add new unpack_field_as_long overload
authorTom Tromey <tromey@adacore.com>
Thu, 17 Apr 2025 14:46:47 +0000 (08:46 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 6 May 2025 15:01:54 +0000 (09:01 -0600)
This introduces a new unpack_field_as_long that takes the field object
directly, rather than a type and an index.  This will be used in the
next patch.

gdb/value.c
gdb/value.h

index 0f1be2e5d122ca09e5e29708e2689ed89ebbc717..d8d57faaba16f652321367789aa31cb84d17d105 100644 (file)
@@ -3296,21 +3296,28 @@ unpack_value_field_as_long (struct type *type, const gdb_byte *valaddr,
   return 1;
 }
 
-/* Unpack a field FIELDNO of the specified TYPE, from the anonymous
-   object at VALADDR.  See unpack_bits_as_long for more details.  */
+/* See value.h.  */
 
 LONGEST
-unpack_field_as_long (struct type *type, const gdb_byte *valaddr, int fieldno)
+unpack_field_as_long (const gdb_byte *valaddr, struct field *field)
 {
-  int bitpos = type->field (fieldno).loc_bitpos ();
-  int bitsize = type->field (fieldno).bitsize ();
-  struct type *field_type = type->field (fieldno).type ();
+  int bitpos = field->loc_bitpos ();
+  int bitsize = field->bitsize ();
+  struct type *field_type = field->type ();
 
   return unpack_bits_as_long (field_type, valaddr, bitpos, bitsize);
 }
 
 /* See value.h.  */
 
+LONGEST
+unpack_field_as_long (struct type *type, const gdb_byte *valaddr, int fieldno)
+{
+  return unpack_field_as_long (valaddr, &type->field (fieldno));
+}
+
+/* See value.h.  */
+
 void
 value::unpack_bitfield (struct value *dest_val,
                        LONGEST bitpos, LONGEST bitsize,
index 71d0ba17f437e8e571ee2cd171cffde19e06aab0..0c7c785bee5a26a7a9157fe84234947edbb5c755 100644 (file)
@@ -1058,10 +1058,19 @@ extern gdb_mpz value_as_mpz (struct value *val);
 extern LONGEST unpack_long (struct type *type, const gdb_byte *valaddr);
 extern CORE_ADDR unpack_pointer (struct type *type, const gdb_byte *valaddr);
 
+/* Unpack a field FIELDNO of the specified TYPE, from the anonymous
+   object at VALADDR.  See unpack_bits_as_long for more details.  */
+
 extern LONGEST unpack_field_as_long (struct type *type,
                                     const gdb_byte *valaddr,
                                     int fieldno);
 
+/* Unpack a field, FIELD, from the anonymous object at VALADDR.  See
+   unpack_bits_as_long for more details.  */
+
+extern LONGEST unpack_field_as_long (const gdb_byte *valaddr,
+                                    struct field *field);
+
 /* Unpack a bitfield of the specified FIELD_TYPE, from the object at
    VALADDR, and store the result in *RESULT.
    The bitfield starts at BITPOS bits and contains BITSIZE bits; if