[4/7] gdb: introduce field::bitsize / field::set_bitsize

Message ID 20230831154727.1240363-5-simon.marchi@efficios.com
State New
Headers
Series Remove some more TYPE/FIELD macros |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Patch failed to apply

Commit Message

Simon Marchi Aug. 31, 2023, 3:46 p.m. UTC
  From: Simon Marchi <simon.marchi@polymtl.ca>

Add these two methods, rename the field to m_bitsize to make it pseudo
private.

Change-Id: Ief95e5cf106e72f2c22ae47b033d0fa47202b413
---
 gdb/ada-lang.c            | 27 +++++++++++++++------------
 gdb/coffread.c            |  6 +++---
 gdb/cp-valprint.c         | 12 ++++++------
 gdb/ctfread.c             |  4 ++--
 gdb/dwarf2/read.c         | 12 ++++--------
 gdb/gdb-gdb.py.in         |  2 +-
 gdb/gdbtypes.c            | 12 ++++++------
 gdb/gdbtypes.h            | 18 ++++++++++++++----
 gdb/mdebugread.c          |  4 ++--
 gdb/stabsread.c           | 12 ++++++------
 gdb/target-descriptions.c |  2 +-
 11 files changed, 60 insertions(+), 51 deletions(-)
  

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 5b856da31891..f995ddc83ccd 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -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);
diff --git a/gdb/coffread.c b/gdb/coffread.c
index e251f110ff84..e432693600e9 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -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;
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 0ad14b43527a..fd0ba5a349e9 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -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);
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 859908923a44..c04b043d6d3a 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -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)
     {
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 25e8034397a4..79005b6849ae 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -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;
 }
diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
index af4453f6eb22..9d9d9e6e4610 100644
--- a/gdb/gdb-gdb.py.in
+++ b/gdb/gdb-gdb.py.in
@@ -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) + "}"
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 0f0638e7bd77..43c09f825f8b 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -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.
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index be65669ac5f5..00a792bc6580 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -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)
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 109bd64e5183..ea3e15be53b2 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -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;
 
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 4a4b39b41e09..abc059b3ded7 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -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;
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 7ae9058b2f29..cdedf88c793c 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -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
 	    {