]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: introduce field::bitsize / field::set_bitsize
authorSimon Marchi <simon.marchi@polymtl.ca>
Thu, 31 Aug 2023 15:46:25 +0000 (11:46 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 31 Aug 2023 17:16:13 +0000 (13:16 -0400)
Add these two methods, rename the field to m_bitsize to make it pseudo
private.

Change-Id: Ief95e5cf106e72f2c22ae47b033d0fa47202b413
Approved-By: Tom Tromey <tom@tromey.com>
gdb/ada-lang.c
gdb/coffread.c
gdb/cp-valprint.c
gdb/ctfread.c
gdb/dwarf2/read.c
gdb/gdb-gdb.py.in
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/mdebugread.c
gdb/stabsread.c
gdb/target-descriptions.c

index 5b856da31891c43be2cb7f25af080f2cf356e245..f995ddc83ccd97ca00b1e2abaf8ae3ed0bcdb206 100644 (file)
@@ -2102,9 +2102,9 @@ ada_type_of_array (struct value *arr, int bounds)
        ada_check_typedef (desc_data_target_type (arr->type ()));
 
       if (ada_is_unconstrained_packed_array_type (arr->type ()))
-       TYPE_FIELD_BITSIZE (array_type, 0) =
-         decode_packed_array_bitsize (arr->type ());
-      
+       array_type->field (0).set_bitsize
+         (decode_packed_array_bitsize (arr->type ()));
+
       return array_type;
     }
   else
@@ -2143,8 +2143,9 @@ ada_type_of_array (struct value *arr, int bounds)
              LONGEST lo = value_as_long (low);
              LONGEST hi = value_as_long (high);
 
-             TYPE_FIELD_BITSIZE (elt_type, 0) =
-               decode_packed_array_bitsize (arr->type ());
+             elt_type->field (0).set_bitsize
+               (decode_packed_array_bitsize (arr->type ()));
+
              /* If the array has no element, then the size is already
                 zero, and does not need to be recomputed.  */
              if (lo < hi)
@@ -2371,7 +2372,7 @@ constrained_packed_array_type (struct type *type, long *elt_bits)
     constrained_packed_array_type (ada_check_typedef (type->target_type ()),
                                   elt_bits);
   new_type = create_array_type (alloc, new_elt_type, index_type);
-  TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
+  new_type->field (0).set_bitsize (*elt_bits);
   new_type->set_name (ada_type_name (type));
 
   if ((check_typedef (index_type)->code () == TYPE_CODE_RANGE
@@ -2458,7 +2459,7 @@ recursively_update_array_bitsize (struct type *type)
     {
       LONGEST elt_len = recursively_update_array_bitsize (elt_type);
       LONGEST elt_bitsize = elt_len * TYPE_FIELD_BITSIZE (elt_type, 0);
-      TYPE_FIELD_BITSIZE (type, 0) = elt_bitsize;
+      type->field (0).set_bitsize (elt_bitsize);
 
       type->set_length (((our_len * elt_bitsize + HOST_CHAR_BIT - 1)
                         / HOST_CHAR_BIT));
@@ -7785,7 +7786,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
       off = align_up (off, field_alignment (type, f))
        + type->field (f).loc_bitpos ();
       rtype->field (f).set_loc_bitpos (off);
-      TYPE_FIELD_BITSIZE (rtype, f) = 0;
+      rtype->field (f).set_bitsize (0);
 
       if (ada_is_variant_part (type, f))
        {
@@ -7866,8 +7867,10 @@ ada_template_to_fixed_record_type_1 (struct type *type,
          rtype->field (f).set_type (type->field (f).type ());
          rtype->field (f).set_name (type->field (f).name ());
          if (TYPE_FIELD_BITSIZE (type, f) > 0)
-           fld_bit_len =
-             TYPE_FIELD_BITSIZE (rtype, f) = TYPE_FIELD_BITSIZE (type, f);
+           {
+             fld_bit_len = TYPE_FIELD_BITSIZE (type, f);
+             rtype->field (f).set_bitsize (fld_bit_len);
+           }
          else
            {
              struct type *field_type = type->field (f).type ();
@@ -8095,7 +8098,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
     {
       rtype->field (variant_field).set_type (branch_type);
       rtype->field (variant_field).set_name ("S");
-      TYPE_FIELD_BITSIZE (rtype, variant_field) = 0;
+      rtype->field (variant_field).set_bitsize (0);
       rtype->set_length (rtype->length () + branch_type->length ());
     }
 
@@ -8408,7 +8411,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
       int len = result->length () / result->target_type ()->length ();
       int elt_bitsize = TYPE_FIELD_BITSIZE (type0, 0);
 
-      TYPE_FIELD_BITSIZE (result, 0) = TYPE_FIELD_BITSIZE (type0, 0);
+      result->field (0).set_bitsize (TYPE_FIELD_BITSIZE (type0, 0));
       result->set_length (len * elt_bitsize / HOST_CHAR_BIT);
       if (result->length () * HOST_CHAR_BIT < len * elt_bitsize)
        result->set_length (result->length () + 1);
index e251f110ff844e191000c07931a9a8fe71da0101..e432693600e9b9fbdc55e6fe1c2c000d06146165 100644 (file)
@@ -2004,7 +2004,7 @@ coff_read_struct_type (int index, int length, int lastsym,
          list->field.set_type (decode_type (ms, ms->c_type, &sub_aux,
                                             objfile));
          list->field.set_loc_bitpos (8 * ms->c_value);
-         FIELD_BITSIZE (list->field) = 0;
+         list->field.set_bitsize (0);
          nfields++;
          break;
 
@@ -2021,7 +2021,7 @@ coff_read_struct_type (int index, int length, int lastsym,
          list->field.set_type (decode_type (ms, ms->c_type, &sub_aux,
                                             objfile));
          list->field.set_loc_bitpos (ms->c_value);
-         FIELD_BITSIZE (list->field) = sub_aux.x_sym.x_misc.x_lnsz.x_size;
+         list->field.set_bitsize (sub_aux.x_sym.x_misc.x_lnsz.x_size);
          nfields++;
          break;
 
@@ -2135,7 +2135,7 @@ coff_read_enum_type (int index, int length, int lastsym,
          type->field (n).set_loc_enumval (xsym->value_longest ());
          if (xsym->value_longest () < 0)
            unsigned_enum = 0;
-         TYPE_FIELD_BITSIZE (type, n) = 0;
+         type->field (n).set_bitsize (0);
        }
       if (syms == osyms)
        break;
index 0ad14b43527af4a78ea3962bff7cf82ce600e7ee..fd0ba5a349e96dbc364e47a26932ceded4bbbbc9 100644 (file)
@@ -752,13 +752,13 @@ test_print_fields (gdbarch *arch)
     {
       f = append_composite_type_field_raw (the_struct, "A", bool_type);
       f->set_loc_bitpos (1);
-      FIELD_BITSIZE (*f) = 1;
+      f->set_bitsize (1);
       f = append_composite_type_field_raw (the_struct, "B", uint8_type);
       f->set_loc_bitpos (3);
-      FIELD_BITSIZE (*f) = 3;
+      f->set_bitsize (3);
       f = append_composite_type_field_raw (the_struct, "C", bool_type);
       f->set_loc_bitpos (7);
-      FIELD_BITSIZE (*f) = 1;
+      f->set_bitsize (1);
     }
   /* According to the logic commented in "make_gdb_type_struct ()" of
    * target-descriptions.c, bit positions are numbered differently for
@@ -767,13 +767,13 @@ test_print_fields (gdbarch *arch)
     {
       f = append_composite_type_field_raw (the_struct, "A", bool_type);
       f->set_loc_bitpos (30);
-      FIELD_BITSIZE (*f) = 1;
+      f->set_bitsize (1);
       f = append_composite_type_field_raw (the_struct, "B", uint8_type);
       f->set_loc_bitpos (26);
-      FIELD_BITSIZE (*f) = 3;
+      f->set_bitsize (3);
       f = append_composite_type_field_raw (the_struct, "C", bool_type);
       f->set_loc_bitpos (24);
-      FIELD_BITSIZE (*f) = 1;
+      f->set_bitsize (1);
     }
 
   value *val = value::allocate (the_struct);
index 859908923a44344cd0c1cee84bfa968bea9d56fc..c04b043d6d3a1c5fd53443c1465e59be2ca55cc8 100644 (file)
@@ -418,7 +418,7 @@ ctf_add_member_cb (const char *name,
 
   fp->set_type (t);
   fp->set_loc_bitpos (offset / TARGET_CHAR_BIT);
-  FIELD_BITSIZE (*fp) = get_bitsize (ccp->fp, tid, kind);
+  fp->set_bitsize (get_bitsize (ccp->fp, tid, kind));
 
   fip->fields.emplace_back (new_field);
 
@@ -440,7 +440,7 @@ ctf_add_enum_member_cb (const char *name, int enum_value, void *arg)
   fp->set_name (name);
   fp->set_type (nullptr);
   fp->set_loc_enumval (enum_value);
-  FIELD_BITSIZE (*fp) = 0;
+  fp->set_bitsize (0);
 
   if (name != nullptr)
     {
index 25e8034397a4efc8b7ae9b9f2dcb8dd4cfd8c09b..79005b6849aedd72c9a893ff67a9d5e1f6d315bf 100644 (file)
@@ -11675,13 +11675,9 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       /* Get bit size of field (zero if none).  */
       attr = dwarf2_attr (die, DW_AT_bit_size, cu);
       if (attr != nullptr)
-       {
-         FIELD_BITSIZE (*fp) = attr->constant_value (0);
-       }
+       fp->set_bitsize (attr->constant_value (0));
       else
-       {
-         FIELD_BITSIZE (*fp) = 0;
-       }
+       fp->set_bitsize (0);
 
       /* Get bit offset of field.  */
       handle_member_location (die, cu, fp);
@@ -11790,7 +11786,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
     {
       /* C++ base class field.  */
       handle_member_location (die, cu, fp);
-      FIELD_BITSIZE (*fp) = 0;
+      fp->set_bitsize (0);
       fp->set_type (die_type (die, cu));
       fp->set_name (fp->type ()->name ());
     }
@@ -13516,7 +13512,7 @@ recognize_bound_expression (struct die_info *die, enum dwarf_attribute name,
 
   field->set_loc_bitpos (8 * offset);
   if (size != field->type ()->length ())
-    FIELD_BITSIZE (*field) = 8 * size;
+    field->set_bitsize (8 * size);
 
   return true;
 }
index af4453f6eb22d2354ddb691c7fd33a8189efb741..9d9d9e6e4610f4b7843d7ff1ca663a941ab5503d 100644 (file)
@@ -178,7 +178,7 @@ class StructMainTypePrettyPrinter:
         fields.append("m_name = %s" % f["m_name"])
         fields.append("m_type = %s" % f["m_type"])
         fields.append("m_loc_kind = %s" % f["m_loc_kind"])
-        fields.append("bitsize = %d" % f["bitsize"])
+        fields.append("bitsize = %d" % f["m_bitsize"])
         fields.append(self.struct_field_location_img(f))
         return label + "\n" + "  {" + ",\n   ".join(fields) + "}"
 
index 0f0638e7bd77cdaa2215c0104c57569ca33852d9..43c09f825f8b8aed5508dd5c0d710737c241e27e 100644 (file)
@@ -1320,9 +1320,9 @@ update_static_array_size (struct type *type)
          && TYPE_FIELD_BITSIZE (element_type, 0) != 0
          && get_array_bounds (element_type, &low_bound, &high_bound)
          && high_bound >= low_bound)
-       TYPE_FIELD_BITSIZE (type, 0)
-         ((high_bound - low_bound + 1)
-            * TYPE_FIELD_BITSIZE (element_type, 0));
+       type->field (0).set_bitsize
+         ((high_bound - low_bound + 1)
+          * TYPE_FIELD_BITSIZE (element_type, 0));
 
       return true;
     }
@@ -1359,7 +1359,7 @@ create_array_type_with_stride (type_allocator &alloc,
   if (byte_stride_prop != NULL)
     result_type->add_dyn_prop (DYN_PROP_BYTE_STRIDE, *byte_stride_prop);
   else if (bit_stride > 0)
-    TYPE_FIELD_BITSIZE (result_type, 0) = bit_stride;
+    result_type->field (0).set_bitsize (bit_stride);
 
   if (!update_static_array_size (result_type))
     {
@@ -5543,7 +5543,7 @@ copy_type_recursive (struct type *type, htab_t copied_types)
        {
          new_type->field (i).set_is_artificial
            (type->field (i).is_artificial ());
-         TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
+         new_type->field (i).set_bitsize (TYPE_FIELD_BITSIZE (type, i));
          if (type->field (i).type ())
            new_type->field (i).set_type
              (copy_type_recursive (type->field (i).type (), copied_types));
@@ -5710,7 +5710,7 @@ append_flags_type_field (struct type *type, int start_bitpos, int nr_bits,
   type->field (field_nr).set_name (xstrdup (name));
   type->field (field_nr).set_type (field_type);
   type->field (field_nr).set_loc_bitpos (start_bitpos);
-  TYPE_FIELD_BITSIZE (type, field_nr) = nr_bits;
+  type->field (field_nr).set_bitsize (nr_bits);
 }
 
 /* Special version of append_flags_type_field to add a flag field.
index be65669ac5f5b7b1dd44cebe387cee56fe172008..00a792bc65808d7f6a81fc7cc2023cbc842df3a2 100644 (file)
@@ -574,6 +574,16 @@ struct field
     m_artificial = is_artificial;
   }
 
+  unsigned int bitsize () const
+  {
+    return m_bitsize;
+  }
+
+  void set_bitsize (unsigned int bitsize)
+  {
+    m_bitsize = bitsize;
+  }
+
   /* Return true if this field is static; false if not.  */
   bool is_static () const
   {
@@ -672,7 +682,7 @@ struct field
      For an unpacked field, the field's type's length
      says how many bytes the field occupies.  */
 
-  unsigned int bitsize : 28;
+  unsigned int m_bitsize : 28;
 
   /* * In a struct or union type, type of this field.
      - In a function or member type, type of this argument.
@@ -1070,8 +1080,8 @@ struct type
 
   ULONGEST bit_stride () const
   {
-    if (this->code () == TYPE_CODE_ARRAY && this->field (0).bitsize != 0)
-      return this->field (0).bitsize;
+    if (this->code () == TYPE_CODE_ARRAY && this->field (0).bitsize () != 0)
+      return this->field (0).bitsize ();
     return this->bounds ()->bit_stride ();
   }
 
@@ -1923,7 +1933,7 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
   (TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits == NULL ? 0 \
     : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (index)))
 
-#define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
+#define FIELD_BITSIZE(thisfld) ((thisfld).bitsize ())
 
 #define TYPE_FIELD_BITSIZE(thistype, n) FIELD_BITSIZE((thistype)->field (n))
 #define TYPE_FIELD_PACKED(thistype, n) (FIELD_BITSIZE((thistype)->field (n))!=0)
index 109bd64e5183f6923399e4255a55da9b27d3a62e..ea3e15be53b286160a0da892e016b06bb3e2b251 100644 (file)
@@ -1068,7 +1068,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
                f->set_loc_enumval (tsym.value);
                f->set_type (t);
                f->set_name (debug_info->ss + cur_fdr->issBase + tsym.iss);
-               FIELD_BITSIZE (*f) = 0;
+               f->set_bitsize (0);
 
                enum_sym = new (&mdebugread_objfile->objfile_obstack) symbol;
                enum_sym->set_linkage_name
@@ -1247,7 +1247,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
        bitsize = 0;
        f->set_type (parse_type (cur_fd, ax, sh->index, &bitsize, bigend,
                                 name));
-       FIELD_BITSIZE (*f) = bitsize;
+       f->set_bitsize (bitsize);
       }
       break;
 
index 4a4b39b41e092bd2eba9c6ba9e679580629f9a9a..abc059b3ded7acf8e2f37e32e85417e8c39cdff9 100644 (file)
@@ -2786,7 +2786,7 @@ read_cpp_abbrev (struct stab_field_info *fip, const char **pp,
          return 0;
       }
       /* This field is unpacked.  */
-      FIELD_BITSIZE (fip->list->field) = 0;
+      fip->list->field.set_bitsize (0);
       fip->list->visibility = VISIBILITY_PRIVATE;
     }
   else
@@ -2864,7 +2864,7 @@ read_one_struct_field (struct stab_field_info *fip, const char **pp,
        stabs_general_complaint ("bad structure-type format");
        return;
       }
-    FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits, 0);
+    fip->list->field.set_bitsize (read_huge_number (pp, ';', &nbits, 0));
     if (nbits != 0)
       {
        stabs_general_complaint ("bad structure-type format");
@@ -2906,7 +2906,7 @@ read_one_struct_field (struct stab_field_info *fip, const char **pp,
          && field_type->code () != TYPE_CODE_BOOL
          && field_type->code () != TYPE_CODE_ENUM)
        {
-         FIELD_BITSIZE (fip->list->field) = 0;
+         fip->list->field.set_bitsize (0);
        }
       if ((FIELD_BITSIZE (fip->list->field)
           == TARGET_CHAR_BIT * field_type->length ()
@@ -2917,7 +2917,7 @@ read_one_struct_field (struct stab_field_info *fip, const char **pp,
          &&
          fip->list->field.loc_bitpos () % 8 == 0)
        {
-         FIELD_BITSIZE (fip->list->field) = 0;
+         fip->list->field.set_bitsize (0);
        }
     }
 }
@@ -3085,7 +3085,7 @@ read_baseclasses (struct stab_field_info *fip, const char **pp,
 
       newobj->next = fip->list;
       fip->list = newobj;
-      FIELD_BITSIZE (newobj->field) = 0;       /* This should be an unpacked
+      newobj->field.set_bitsize (0);   /* This should be an unpacked
                                           field!  */
 
       STABS_CONTINUE (pp, objfile);
@@ -3651,7 +3651,7 @@ read_enum_type (const char **pp, struct type *type,
          xsym->set_type (type);
          type->field (n).set_name (xsym->linkage_name ());
          type->field (n).set_loc_enumval (xsym->value_longest ());
-         TYPE_FIELD_BITSIZE (type, n) = 0;
+         type->field (n).set_bitsize (0);
        }
       if (syms == osyms)
        break;
index 7ae9058b2f29a04fffc04b620c87865f7084c69a..cdedf88c793c7077b5be6a8b15040296bfc88590 100644 (file)
@@ -232,7 +232,7 @@ make_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *ttype)
                fld->set_loc_bitpos (total_size - f.start - bitsize);
              else
                fld->set_loc_bitpos (f.start);
-             FIELD_BITSIZE (fld[0]) = bitsize;
+             fld->set_bitsize (bitsize);
            }
          else
            {