public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/7] Remove some more TYPE/FIELD macros
@ 2023-08-31 15:46 Simon Marchi
  2023-08-31 15:46 ` [PATCH 1/7] gdb: introduce field::is_artificial / field::set_is_artificial Simon Marchi
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Simon Marchi @ 2023-08-31 15:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Here's another round of gdbtypes.h macro removal, converting to methods.

Simon Marchi (7):
  gdb: introduce field::is_artificial / field::set_is_artificial
  gdb: remove FIELD_ARTIFICIAL
  gdb: remove TYPE_FIELD_ARTIFICIAL
  gdb: introduce field::bitsize / field::set_bitsize
  gdb: remove FIELD_BITSIZE
  gdb: remove TYPE_FIELD_BITSIZE
  gdb: remove TYPE_FIELD_PACKED

 gdb/ada-lang.c                    | 75 ++++++++++++++++---------------
 gdb/ada-typeprint.c               |  8 ++--
 gdb/ada-valprint.c                |  8 ++--
 gdb/amd64-tdep.c                  |  6 +--
 gdb/arm-tdep.c                    |  2 +-
 gdb/ax-gdb.c                      |  6 +--
 gdb/buildsym.c                    |  2 +-
 gdb/c-typeprint.c                 | 15 +++----
 gdb/c-varobj.c                    |  4 +-
 gdb/coffread.c                    |  6 +--
 gdb/compile/compile-c-types.c     |  2 +-
 gdb/compile/compile-cplus-types.c |  6 +--
 gdb/compile/compile-object-load.c |  2 +-
 gdb/cp-valprint.c                 | 16 +++----
 gdb/ctfread.c                     |  4 +-
 gdb/dwarf2/read.c                 | 36 +++++++--------
 gdb/eval.c                        |  2 +-
 gdb/f-lang.c                      |  2 +-
 gdb/gdb-gdb.py.in                 |  4 +-
 gdb/gdbtypes.c                    | 32 ++++++-------
 gdb/gdbtypes.h                    | 40 ++++++++++++-----
 gdb/guile/scm-type.c              |  2 +-
 gdb/i386-windows-tdep.c           |  2 +-
 gdb/m2-typeprint.c                |  5 +--
 gdb/mdebugread.c                  |  6 +--
 gdb/p-typeprint.c                 |  5 +--
 gdb/p-valprint.c                  |  4 +-
 gdb/python/py-type.c              |  4 +-
 gdb/rust-lang.c                   |  6 +--
 gdb/stabsread.c                   | 23 +++++-----
 gdb/target-descriptions.c         |  2 +-
 gdb/typeprint.c                   |  4 +-
 gdb/valops.c                      |  6 +--
 gdb/valprint.c                    |  4 +-
 gdb/value.c                       | 10 ++---
 35 files changed, 188 insertions(+), 173 deletions(-)


base-commit: 79771b88bf22d7b4499363ba8a2dbd6a534deb98
-- 
2.42.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/7] gdb: introduce field::is_artificial / field::set_is_artificial
  2023-08-31 15:46 [PATCH 0/7] Remove some more TYPE/FIELD macros Simon Marchi
@ 2023-08-31 15:46 ` Simon Marchi
  2023-08-31 15:46 ` [PATCH 2/7] gdb: remove FIELD_ARTIFICIAL Simon Marchi
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2023-08-31 15:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

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

Change-Id: If3a3825473d1d79bb586a8a074b87bba9b43fb1a
---
 gdb/buildsym.c    |  2 +-
 gdb/dwarf2/read.c | 14 +++++++-------
 gdb/gdb-gdb.py.in |  2 +-
 gdb/gdbtypes.c    |  4 ++--
 gdb/gdbtypes.h    | 14 ++++++++++++--
 gdb/mdebugread.c  |  2 +-
 gdb/stabsread.c   |  3 ++-
 7 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 3c1e9179411b..03d6e03b6304 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -277,7 +277,7 @@ buildsym_compunit::finish_block_internal
 		  if (sym->is_argument ())
 		    {
 		      ftype->field (iparams).set_type (sym->type ());
-		      TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
+		      ftype->field (iparams).set_is_artificial (false);
 		      iparams++;
 		    }
 		}
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 94d98feb56b6..63b099c111b5 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -6060,7 +6060,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 
       /* Put the discriminant at index 0.  */
       type->field (0).set_type (field_type);
-      TYPE_FIELD_ARTIFICIAL (type, 0) = 1;
+      type->field (0).set_is_artificial (true);
       type->field (0).set_name ("<<discriminant>>");
       type->field (0).set_loc_bitpos (bit_offset);
 
@@ -6158,7 +6158,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 
       /* Install the discriminant at index 0 in the union.  */
       type->field (0) = *disr_field;
-      TYPE_FIELD_ARTIFICIAL (type, 0) = 1;
+      type->field (0).set_is_artificial (true);
       type->field (0).set_name ("<<discriminant>>");
 
       /* We need a way to find the correct discriminant given a
@@ -11743,7 +11743,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
 	 pointer or virtual base class pointer) to private.  */
       if (dwarf2_attr (die, DW_AT_artificial, cu))
 	{
-	  FIELD_ARTIFICIAL (*fp) = 1;
+	  fp->set_is_artificial (true);
 	  new_field->accessibility = DW_ACCESS_private;
 	  fip->non_public_fields = true;
 	}
@@ -13588,10 +13588,10 @@ quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
 	  struct field &upper = range_fields[range_fields.size () - 1];
 
 	  lower.set_type (underlying);
-	  FIELD_ARTIFICIAL (lower) = 1;
+	  lower.set_is_artificial (true);
 
 	  upper.set_type (underlying);
-	  FIELD_ARTIFICIAL (upper) = 1;
+	  upper.set_is_artificial (true);
 
 	  if (!recognize_bound_expression (child_die, DW_AT_lower_bound,
 					   &bounds_offset, &lower, cu)
@@ -14713,9 +14713,9 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
 		 4.5 does not yet generate.  */
 	      attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
 	      if (attr != nullptr)
-		TYPE_FIELD_ARTIFICIAL (ftype, iparams) = attr->as_boolean ();
+		ftype->field (iparams).set_is_artificial (attr->as_boolean ());
 	      else
-		TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
+		ftype->field (iparams).set_is_artificial (false);
 	      arg_type = die_type (child_die, cu);
 
 	      /* RealView does not mark THIS as const, which the testsuite
diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
index 56d063cd506b..af4453f6eb22 100644
--- a/gdb/gdb-gdb.py.in
+++ b/gdb/gdb-gdb.py.in
@@ -172,7 +172,7 @@ class StructMainTypePrettyPrinter:
         """Return an image of the main_type field number FIELDNO."""
         f = self.val["flds_bnds"]["fields"][fieldno]
         label = "flds_bnds.fields[%d]:" % fieldno
-        if f["artificial"]:
+        if f["m_artificial"]:
             label += " (artificial)"
         fields = []
         fields.append("m_name = %s" % f["m_name"])
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 6abe5eaad0a1..ca168b31529f 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -5541,8 +5541,8 @@ copy_type_recursive (struct type *type, htab_t copied_types)
 
       for (i = 0; i < nfields; i++)
 	{
-	  TYPE_FIELD_ARTIFICIAL (new_type, i) = 
-	    TYPE_FIELD_ARTIFICIAL (type, i);
+	  new_type->field (i).set_is_artificial
+	    (TYPE_FIELD_ARTIFICIAL (type, i));
 	  TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
 	  if (type->field (i).type ())
 	    new_type->field (i).set_type
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 8f592dbe1c01..43263a90714d 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -564,6 +564,16 @@ struct field
     m_name = name;
   }
 
+  bool is_artificial () const
+  {
+    return m_artificial;
+  }
+
+  void set_is_artificial (bool is_artificial)
+  {
+    m_artificial = is_artificial;
+  }
+
   /* Return true if this field is static; false if not.  */
   bool is_static () const
   {
@@ -650,7 +660,7 @@ struct field
      to the user.  For TYPE_CODE_RANGE it is set if the specific
      bound is not defined.  */
 
-  unsigned int artificial : 1;
+  unsigned int m_artificial : 1;
 
   /* * Discriminant for union field_location.  */
 
@@ -1913,7 +1923,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_ARTIFICIAL(thisfld) ((thisfld).artificial)
+#define FIELD_ARTIFICIAL(thisfld) ((thisfld).is_artificial ())
 #define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
 
 #define TYPE_FIELD_ARTIFICIAL(thistype, n) FIELD_ARTIFICIAL((thistype)->field (n))
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index ad9967b75fad..109bd64e5183 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1206,7 +1206,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 		      if (sym->is_argument ())
 			{
 			  ftype->field (iparams).set_type (sym->type ());
-			  TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
+			  ftype->field (iparams).set_is_artificial (false);
 			  iparams++;
 			}
 		    }
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 1269fc02d724..4a4b39b41e09 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -1002,7 +1002,8 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
 	      if (ptype->code () == TYPE_CODE_VOID)
 		ptype = builtin_type (objfile)->builtin_int;
 	      ftype->field (nparams).set_type (ptype);
-	      TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
+	      ftype->field (nparams).set_is_artificial (false);
+	      nparams++;
 	    }
 	  ftype->set_num_fields (nparams);
 	  ftype->set_is_prototyped (true);
-- 
2.42.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/7] gdb: remove FIELD_ARTIFICIAL
  2023-08-31 15:46 [PATCH 0/7] Remove some more TYPE/FIELD macros Simon Marchi
  2023-08-31 15:46 ` [PATCH 1/7] gdb: introduce field::is_artificial / field::set_is_artificial Simon Marchi
@ 2023-08-31 15:46 ` Simon Marchi
  2023-08-31 15:46 ` [PATCH 3/7] gdb: remove TYPE_FIELD_ARTIFICIAL Simon Marchi
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2023-08-31 15:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace uses with field::is_artificial.

Change-Id: I599616fdd9f4b6d044de492e8151aa6130725cd1
---
 gdb/c-typeprint.c    | 2 +-
 gdb/gdbtypes.c       | 2 +-
 gdb/gdbtypes.h       | 3 +--
 gdb/guile/scm-type.c | 2 +-
 4 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 416f63bacf52..57b2c09be8bf 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -286,7 +286,7 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
 
       struct field arg = args[i];
       /* Skip any artificial arguments.  */
-      if (FIELD_ARTIFICIAL (arg))
+      if (arg.is_artificial ())
 	continue;
 
       if (printed_args > 0)
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index ca168b31529f..076a0817b265 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -4243,7 +4243,7 @@ check_types_equal (struct type *type1, struct type *type2,
 	  const struct field *field1 = &type1->field (i);
 	  const struct field *field2 = &type2->field (i);
 
-	  if (FIELD_ARTIFICIAL (*field1) != FIELD_ARTIFICIAL (*field2)
+	  if (field1->is_artificial () != field2->is_artificial ()
 	      || FIELD_BITSIZE (*field1) != FIELD_BITSIZE (*field2)
 	      || field1->loc_kind () != field2->loc_kind ())
 	    return false;
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 43263a90714d..9aa4a5c8a856 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1923,10 +1923,9 @@ 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_ARTIFICIAL(thisfld) ((thisfld).is_artificial ())
 #define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
 
-#define TYPE_FIELD_ARTIFICIAL(thistype, n) FIELD_ARTIFICIAL((thistype)->field (n))
+#define TYPE_FIELD_ARTIFICIAL(thistype, n) ((thistype)->field (n).is_artificial ())
 #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/guile/scm-type.c b/gdb/guile/scm-type.c
index 033b800d8b0a..3b0a27524182 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -1213,7 +1213,7 @@ gdbscm_field_artificial_p (SCM self)
     = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   struct field *field = tyscm_field_smob_to_field (f_smob);
 
-  return scm_from_bool (FIELD_ARTIFICIAL (*field));
+  return scm_from_bool (field->is_artificial ());
 }
 
 /* (field-baseclass? <gdb:field>) -> boolean
-- 
2.42.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/7] gdb: remove TYPE_FIELD_ARTIFICIAL
  2023-08-31 15:46 [PATCH 0/7] Remove some more TYPE/FIELD macros Simon Marchi
  2023-08-31 15:46 ` [PATCH 1/7] gdb: introduce field::is_artificial / field::set_is_artificial Simon Marchi
  2023-08-31 15:46 ` [PATCH 2/7] gdb: remove FIELD_ARTIFICIAL Simon Marchi
@ 2023-08-31 15:46 ` Simon Marchi
  2023-08-31 15:46 ` [PATCH 4/7] gdb: introduce field::bitsize / field::set_bitsize Simon Marchi
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2023-08-31 15:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with type::field + field::is_artificial.

Change-Id: Ie3bacae49d9bd02e83e504c1ce01470aba56a081
---
 gdb/c-typeprint.c                 | 4 ++--
 gdb/c-varobj.c                    | 4 ++--
 gdb/compile/compile-cplus-types.c | 4 ++--
 gdb/dwarf2/read.c                 | 8 ++++----
 gdb/f-lang.c                      | 2 +-
 gdb/gdbtypes.c                    | 2 +-
 gdb/gdbtypes.h                    | 1 -
 gdb/i386-windows-tdep.c           | 2 +-
 gdb/python/py-type.c              | 2 +-
 gdb/rust-lang.c                   | 6 +++---
 gdb/valops.c                      | 4 ++--
 11 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 57b2c09be8bf..a23ceb0ddc4a 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -535,7 +535,7 @@ c_type_print_args (struct type *type, struct ui_file *stream,
     {
       struct type *param_type;
 
-      if (TYPE_FIELD_ARTIFICIAL (type, i) && linkage_name)
+      if (type->field (i).is_artificial () && linkage_name)
 	continue;
 
       if (printed_any)
@@ -1102,7 +1102,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
 	     virtual table pointers are not specifically marked in
 	     the debug info, they should be artificial.  */
 	  if ((i == vptr_fieldno && type == basetype)
-	      || TYPE_FIELD_ARTIFICIAL (type, i))
+	      || type->field (i).is_artificial ())
 	    continue;
 
 	  if (need_access_label)
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index 87eca6b069ab..b00a2345e2c3 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -651,7 +651,7 @@ cplus_class_num_children (struct type *type, int children[3])
 	 table pointers are not specifically marked in the debug info,
 	 they should be artificial.  */
       if ((type == basetype && i == vptr_fieldno)
-	  || TYPE_FIELD_ARTIFICIAL (type, i))
+	  || type->field (i).is_artificial ())
 	continue;
 
       if (TYPE_FIELD_PROTECTED (type, i))
@@ -751,7 +751,7 @@ cplus_describe_child (const struct varobj *parent, int index,
 	  while (index >= 0)
 	    {
 	      if ((type == basetype && type_index == vptr_fieldno)
-		  || TYPE_FIELD_ARTIFICIAL (type, type_index))
+		  || type->field (type_index).is_artificial ())
 		; /* ignore vptr */
 	      else if (match_accessibility (type, type_index, acc))
 		    --index;
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index d8e305f237a4..cea04b74d10a 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -584,7 +584,7 @@ compile_cplus_convert_struct_or_union_members
       const char *field_name = type->field (i).name ();
 
       if (TYPE_FIELD_IGNORE (type, i)
-	  || TYPE_FIELD_ARTIFICIAL (type, i))
+	  || type->field (i).is_artificial ())
 	continue;
 
       /* GDB records unnamed/anonymous fields with empty string names.  */
@@ -982,7 +982,7 @@ compile_cplus_convert_func (compile_cplus_instance *instance,
   int artificials = 0;
   for (int i = 0; i < type->num_fields (); ++i)
     {
-      if (strip_artificial && TYPE_FIELD_ARTIFICIAL (type, i))
+      if (strip_artificial && type->field (i).is_artificial ())
 	{
 	  --array.n_elements;
 	  ++artificials;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 63b099c111b5..25e8034397a4 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7066,7 +7066,7 @@ dwarf2_compute_name (const char *name,
 		     artificial; there is no way to differentiate
 		     the two cases.  */
 		  if (type->num_fields () > 0
-		      && TYPE_FIELD_ARTIFICIAL (type, 0)
+		      && type->field (0).is_artificial ()
 		      && type->field (0).type ()->code () == TYPE_CODE_PTR
 		      && TYPE_CONST (type->field (0).type ()->target_type ()))
 		    buf.puts (" const");
@@ -12239,7 +12239,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
 	 parameter for non-static member functions (which is the this
 	 pointer) as artificial.  We obtain this information from
 	 read_subroutine_type via TYPE_FIELD_ARTIFICIAL.  */
-      if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
+      if (nparams == 0 || this_type->field (0).is_artificial () == 0)
 	fnp->voffset = VOFFSET_STATIC;
     }
   else
@@ -12328,7 +12328,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
 		 we cannot actually find a base class context for the
 		 vtable!  */
 	      if (this_type->num_fields () == 0
-		  || !TYPE_FIELD_ARTIFICIAL (this_type, 0))
+		  || !this_type->field (0).is_artificial ())
 		{
 		  complaint (_("cannot determine context for virtual member "
 			       "function \"%s\" (offset %s)"),
@@ -14723,7 +14723,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
 		 but not in the class specifications (GCC PR 43053).  */
 	      if (cu->lang () == language_cplus
 		  && !TYPE_CONST (arg_type)
-		  && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
+		  && ftype->field (iparams).is_artificial ())
 		{
 		  int is_this = 0;
 		  struct dwarf2_cu *arg_cu = cu;
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index bb177007303a..fc0614e57617 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1932,7 +1932,7 @@ fortran_prepare_argument (struct expression *exp,
 
   bool is_artificial = ((arg_num >= func_type->num_fields ())
 			? true
-			: TYPE_FIELD_ARTIFICIAL (func_type, arg_num));
+			: func_type->field (arg_num).is_artificial ());
 
   /* If this is an artificial argument, then either, this is an argument
      beyond the end of the known arguments, or possibly, there are no known
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 076a0817b265..0f0638e7bd77 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -5542,7 +5542,7 @@ copy_type_recursive (struct type *type, htab_t copied_types)
       for (i = 0; i < nfields; i++)
 	{
 	  new_type->field (i).set_is_artificial
-	    (TYPE_FIELD_ARTIFICIAL (type, i));
+	    (type->field (i).is_artificial ());
 	  TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
 	  if (type->field (i).type ())
 	    new_type->field (i).set_type
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 9aa4a5c8a856..be65669ac5f5 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1925,7 +1925,6 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
 
 #define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
 
-#define TYPE_FIELD_ARTIFICIAL(thistype, n) ((thistype)->field (n).is_artificial ())
 #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/i386-windows-tdep.c b/gdb/i386-windows-tdep.c
index 686004a5d320..a5fe5dc8a1c8 100644
--- a/gdb/i386-windows-tdep.c
+++ b/gdb/i386-windows-tdep.c
@@ -122,7 +122,7 @@ i386_windows_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
      artificial flag of the first parameter ('this' pointer).  */
   if (type->code () == TYPE_CODE_METHOD
       && type->num_fields () > 0
-      && TYPE_FIELD_ARTIFICIAL (type, 0)
+      && type->field (0).is_artificial ()
       && type->field (0).type ()->code () == TYPE_CODE_PTR)
     thiscall = 1;
 
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index b60875c792ed..9933bb378b57 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -197,7 +197,7 @@ convert_field (struct type *type, int field)
   if (PyObject_SetAttrString (result.get (), "name", arg.get ()) < 0)
     return NULL;
 
-  arg.reset (PyBool_FromLong (TYPE_FIELD_ARTIFICIAL (type, field)));
+  arg.reset (PyBool_FromLong (type->field (field).is_artificial ()));
   if (PyObject_SetAttrString (result.get (), "artificial", arg.get ()) < 0)
     return NULL;
 
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 27e8069f1481..0b4a7d47c957 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -93,7 +93,7 @@ rust_enum_variant (struct type *type)
 {
   /* The active variant is simply the first non-artificial field.  */
   for (int i = 0; i < type->num_fields (); ++i)
-    if (!TYPE_FIELD_ARTIFICIAL (type, i))
+    if (!type->field (i).is_artificial ())
       return i;
 
   /* Perhaps we could get here by trying to print an Ada variant
@@ -724,7 +724,7 @@ rust_print_struct_def (struct type *type, const char *varstring,
     {
       if (type->field (i).is_static ())
 	continue;
-      if (is_enum && TYPE_FIELD_ARTIFICIAL (type, i))
+      if (is_enum && type->field (i).is_artificial ())
 	continue;
       fields.push_back (i);
     }
@@ -741,7 +741,7 @@ rust_print_struct_def (struct type *type, const char *varstring,
       QUIT;
 
       gdb_assert (!type->field (i).is_static ());
-      gdb_assert (! (is_enum && TYPE_FIELD_ARTIFICIAL (type, i)));
+      gdb_assert (! (is_enum && type->field (i).is_artificial ()));
 
       if (flags->print_offsets)
 	podata->update (type, i, stream);
diff --git a/gdb/valops.c b/gdb/valops.c
index 6404091d451d..b007fe08d348 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3464,7 +3464,7 @@ compare_parameters (struct type *t1, struct type *t2, int skip_artificial)
 {
   int start = 0;
 
-  if (t1->num_fields () > 0 && TYPE_FIELD_ARTIFICIAL (t1, 0))
+  if (t1->num_fields () > 0 && t1->field (0).is_artificial ())
     ++start;
 
   /* If skipping artificial fields, find the first real field
@@ -3472,7 +3472,7 @@ compare_parameters (struct type *t1, struct type *t2, int skip_artificial)
   if (skip_artificial)
     {
       while (start < t1->num_fields ()
-	     && TYPE_FIELD_ARTIFICIAL (t1, start))
+	     && t1->field (start).is_artificial ())
 	++start;
     }
 
-- 
2.42.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/7] gdb: introduce field::bitsize / field::set_bitsize
  2023-08-31 15:46 [PATCH 0/7] Remove some more TYPE/FIELD macros Simon Marchi
                   ` (2 preceding siblings ...)
  2023-08-31 15:46 ` [PATCH 3/7] gdb: remove TYPE_FIELD_ARTIFICIAL Simon Marchi
@ 2023-08-31 15:46 ` Simon Marchi
  2023-08-31 15:46 ` [PATCH 5/7] gdb: remove FIELD_BITSIZE Simon Marchi
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2023-08-31 15:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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(-)

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
 	    {
-- 
2.42.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 5/7] gdb: remove FIELD_BITSIZE
  2023-08-31 15:46 [PATCH 0/7] Remove some more TYPE/FIELD macros Simon Marchi
                   ` (3 preceding siblings ...)
  2023-08-31 15:46 ` [PATCH 4/7] gdb: introduce field::bitsize / field::set_bitsize Simon Marchi
@ 2023-08-31 15:46 ` Simon Marchi
  2023-08-31 15:46 ` [PATCH 6/7] gdb: remove TYPE_FIELD_BITSIZE Simon Marchi
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2023-08-31 15:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with field::bitsize.

Change-Id: I400be235d6a1f446d0a4aafac01df5e850185d3a
---
 gdb/dwarf2/read.c | 2 +-
 gdb/gdbtypes.c    | 2 +-
 gdb/gdbtypes.h    | 6 ++----
 gdb/stabsread.c   | 8 ++++----
 4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 79005b6849ae..a538cb55b748 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -11722,7 +11722,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
 		}
 	      fp->set_loc_bitpos (fp->loc_bitpos ()
 				  + anonymous_size * bits_per_byte
-				  - bit_offset - FIELD_BITSIZE (*fp));
+				  - bit_offset - fp->bitsize ());
 	    }
 	}
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 43c09f825f8b..cd6b191ea628 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -4244,7 +4244,7 @@ check_types_equal (struct type *type1, struct type *type2,
 	  const struct field *field2 = &type2->field (i);
 
 	  if (field1->is_artificial () != field2->is_artificial ()
-	      || FIELD_BITSIZE (*field1) != FIELD_BITSIZE (*field2)
+	      || field1->bitsize () != field2->bitsize ()
 	      || field1->loc_kind () != field2->loc_kind ())
 	    return false;
 	  if (!compare_maybe_null_strings (field1->name (), field2->name ()))
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 00a792bc6580..6c522a935c5b 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1933,10 +1933,8 @@ 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 TYPE_FIELD_BITSIZE(thistype, n) FIELD_BITSIZE((thistype)->field (n))
-#define TYPE_FIELD_PACKED(thistype, n) (FIELD_BITSIZE((thistype)->field (n))!=0)
+#define TYPE_FIELD_BITSIZE(thistype, n) ((thistype)->field (n).bitsize ())
+#define TYPE_FIELD_PACKED(thistype, n) (((thistype)->field (n).bitsize ())!=0)
 
 #define TYPE_FIELD_PRIVATE_BITS(thistype) \
   TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index abc059b3ded7..cc7efda61bf7 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -2873,7 +2873,7 @@ read_one_struct_field (struct stab_field_info *fip, const char **pp,
   }
 
   if (fip->list->field.loc_bitpos () == 0
-      && FIELD_BITSIZE (fip->list->field) == 0)
+      && fip->list->field.bitsize () == 0)
     {
       /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
 	 it is a field which has been optimized out.  The correct stab for
@@ -2908,11 +2908,11 @@ read_one_struct_field (struct stab_field_info *fip, const char **pp,
 	{
 	  fip->list->field.set_bitsize (0);
 	}
-      if ((FIELD_BITSIZE (fip->list->field)
+      if ((fip->list->field.bitsize ()
 	   == TARGET_CHAR_BIT * field_type->length ()
 	   || (field_type->code () == TYPE_CODE_ENUM
-	       && FIELD_BITSIZE (fip->list->field)
-		  == gdbarch_int_bit (gdbarch))
+	       && (fip->list->field.bitsize ()
+		   == gdbarch_int_bit (gdbarch)))
 	  )
 	  &&
 	  fip->list->field.loc_bitpos () % 8 == 0)
-- 
2.42.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 6/7] gdb: remove TYPE_FIELD_BITSIZE
  2023-08-31 15:46 [PATCH 0/7] Remove some more TYPE/FIELD macros Simon Marchi
                   ` (4 preceding siblings ...)
  2023-08-31 15:46 ` [PATCH 5/7] gdb: remove FIELD_BITSIZE Simon Marchi
@ 2023-08-31 15:46 ` Simon Marchi
  2023-08-31 15:46 ` [PATCH 7/7] gdb: remove TYPE_FIELD_PACKED Simon Marchi
  2023-08-31 17:05 ` [PATCH 0/7] Remove some more TYPE/FIELD macros Tom Tromey
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2023-08-31 15:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with type::field + field::bitsize.

Change-Id: I2a24755a33683e4a2775a6d2a7b7a9ae7362e43a
---
 gdb/ada-lang.c                    | 52 +++++++++++++++----------------
 gdb/ada-typeprint.c               |  8 ++---
 gdb/ada-valprint.c                |  6 ++--
 gdb/amd64-tdep.c                  |  4 +--
 gdb/arm-tdep.c                    |  2 +-
 gdb/ax-gdb.c                      |  2 +-
 gdb/c-typeprint.c                 |  7 ++---
 gdb/compile/compile-c-types.c     |  2 +-
 gdb/compile/compile-cplus-types.c |  2 +-
 gdb/compile/compile-object-load.c |  2 +-
 gdb/cp-valprint.c                 |  2 +-
 gdb/eval.c                        |  2 +-
 gdb/gdbtypes.c                    | 16 +++++-----
 gdb/gdbtypes.h                    |  1 -
 gdb/m2-typeprint.c                |  3 +-
 gdb/p-typeprint.c                 |  3 +-
 gdb/p-valprint.c                  |  2 +-
 gdb/python/py-type.c              |  2 +-
 gdb/typeprint.c                   |  2 +-
 gdb/valprint.c                    |  4 +--
 gdb/value.c                       | 10 +++---
 21 files changed, 65 insertions(+), 69 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index f995ddc83ccd..77140333ea5a 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1881,8 +1881,8 @@ fat_pntr_bounds_bitsize (struct type *type)
 {
   type = desc_base_type (type);
 
-  if (TYPE_FIELD_BITSIZE (type, 1) > 0)
-    return TYPE_FIELD_BITSIZE (type, 1);
+  if (type->field (1).bitsize () > 0)
+    return type->field (1).bitsize ();
   else
     return 8 * ada_check_typedef (type->field (1).type ())->length ();
 }
@@ -1947,8 +1947,8 @@ fat_pntr_data_bitsize (struct type *type)
 {
   type = desc_base_type (type);
 
-  if (TYPE_FIELD_BITSIZE (type, 0) > 0)
-    return TYPE_FIELD_BITSIZE (type, 0);
+  if (type->field (0).bitsize () > 0)
+    return type->field (0).bitsize ();
   else
     return TARGET_CHAR_BIT * type->field (0).type ()->length ();
 }
@@ -1986,8 +1986,8 @@ desc_bound_bitsize (struct type *type, int i, int which)
 {
   type = desc_base_type (type);
 
-  if (TYPE_FIELD_BITSIZE (type, 2 * i + which - 2) > 0)
-    return TYPE_FIELD_BITSIZE (type, 2 * i + which - 2);
+  if (type->field (2 * i + which - 2).bitsize () > 0)
+    return type->field (2 * i + which - 2).bitsize ();
   else
     return 8 * type->field (2 * i + which - 2).type ()->length ();
 }
@@ -2151,7 +2151,7 @@ ada_type_of_array (struct value *arr, int bounds)
 	      if (lo < hi)
 		{
 		  int array_bitsize =
-			(hi - lo + 1) * TYPE_FIELD_BITSIZE (elt_type, 0);
+			(hi - lo + 1) * elt_type->field (0).bitsize ();
 
 		  elt_type->set_length ((array_bitsize + 7) / 8);
 		}
@@ -2269,7 +2269,7 @@ ada_is_unconstrained_packed_array_type (struct type *type)
       if (type->code () == TYPE_CODE_TYPEDEF)
 	type = ada_typedef_target_type (type);
       /* Now we can see if the array elements are packed.  */
-      return TYPE_FIELD_BITSIZE (type, 0) > 0;
+      return type->field (0).bitsize () > 0;
     }
 
   return 0;
@@ -2283,7 +2283,7 @@ ada_is_any_packed_array_type (struct type *type)
 {
   return (ada_is_constrained_packed_array_type (type)
 	  || (type->code () == TYPE_CODE_ARRAY
-	      && TYPE_FIELD_BITSIZE (type, 0) % 8 != 0));
+	      && type->field (0).bitsize () % 8 != 0));
 }
 
 /* Given that TYPE encodes a packed array type (constrained or unconstrained),
@@ -2317,7 +2317,7 @@ decode_packed_array_bitsize (struct type *type)
 	 fetches the array type.  */
       type = type->field (0).type ()->target_type ();
       /* Now we can see if the array elements are packed.  */
-      return TYPE_FIELD_BITSIZE (type, 0);
+      return type->field (0).bitsize ();
     }
 
   if (sscanf (tail + sizeof ("___XP") - 1, "%ld", &bits) != 1)
@@ -2458,7 +2458,7 @@ recursively_update_array_bitsize (struct type *type)
   if (elt_type->code () == TYPE_CODE_ARRAY)
     {
       LONGEST elt_len = recursively_update_array_bitsize (elt_type);
-      LONGEST elt_bitsize = elt_len * TYPE_FIELD_BITSIZE (elt_type, 0);
+      LONGEST elt_bitsize = elt_len * elt_type->field (0).bitsize ();
       type->field (0).set_bitsize (elt_bitsize);
 
       type->set_length (((our_len * elt_bitsize + HOST_CHAR_BIT - 1)
@@ -2556,7 +2556,7 @@ value_subscript_packed (struct value *arr, int arity, struct value **ind)
   for (i = 0; i < arity; i += 1)
     {
       if (elt_type->code () != TYPE_CODE_ARRAY
-	  || TYPE_FIELD_BITSIZE (elt_type, 0) == 0)
+	  || elt_type->field (0).bitsize () == 0)
 	error
 	  (_("attempt to do packed indexing of "
 	     "something other than a packed array"));
@@ -2576,7 +2576,7 @@ value_subscript_packed (struct value *arr, int arity, struct value **ind)
 	  if (idx < lowerbound || idx > upperbound)
 	    lim_warning (_("packed array index %ld out of bounds"),
 			 (long) idx);
-	  bits = TYPE_FIELD_BITSIZE (elt_type, 0);
+	  bits = elt_type->field (0).bitsize ();
 	  elt_total_bit_offset += (idx - lowerbound) * bits;
 	  elt_type = ada_check_typedef (elt_type->target_type ());
 	}
@@ -2992,7 +2992,7 @@ ada_value_subscript (struct value *arr, int arity, struct value **ind)
 
   elt_type = ada_check_typedef (elt->type ());
   if (elt_type->code () == TYPE_CODE_ARRAY
-      && TYPE_FIELD_BITSIZE (elt_type, 0) > 0)
+      && elt_type->field (0).bitsize () > 0)
     return value_subscript_packed (elt, arity, ind);
 
   for (k = 0; k < arity; k += 1)
@@ -3049,7 +3049,7 @@ ada_value_ptr_subscript (struct value *arr, int arity, struct value **ind)
     = check_typedef (array_ind->enclosing_type ());
 
   if (type->code () == TYPE_CODE_ARRAY
-      && TYPE_FIELD_BITSIZE (type, 0) > 0)
+      && type->field (0).bitsize () > 0)
     return value_subscript_packed (array_ind, arity, ind);
 
   for (k = 0; k < arity; k += 1)
@@ -3084,7 +3084,7 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
   struct type *slice_type = create_array_type_with_stride
 			      (alloc, type0->target_type (), index_type,
 			       type0->dyn_prop (DYN_PROP_BYTE_STRIDE),
-			       TYPE_FIELD_BITSIZE (type0, 0));
+			       type0->field (0).bitsize ());
   int base_low =  ada_discrete_type_low_bound (type0->index_type ());
   gdb::optional<LONGEST> base_low_pos, low_pos;
   CORE_ADDR base;
@@ -3099,7 +3099,7 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
       base_low_pos = base_low;
     }
 
-  ULONGEST stride = TYPE_FIELD_BITSIZE (slice_type, 0) / 8;
+  ULONGEST stride = slice_type->field (0).bitsize () / 8;
   if (stride == 0)
     stride = type0->target_type ()->length ();
 
@@ -3119,7 +3119,7 @@ ada_value_slice (struct value *array, int low, int high)
   struct type *slice_type = create_array_type_with_stride
 			      (alloc, type->target_type (), index_type,
 			       type->dyn_prop (DYN_PROP_BYTE_STRIDE),
-			       TYPE_FIELD_BITSIZE (type, 0));
+			       type->field (0).bitsize ());
   gdb::optional<LONGEST> low_pos, high_pos;
 
 
@@ -6886,10 +6886,10 @@ ada_value_primitive_field (struct value *arg1, int offset, int fieldno,
   /* Handle packed fields.  It might be that the field is not packed
      relative to its containing structure, but the structure itself is
      packed; in this case we must take the bit-field path.  */
-  if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0 || arg1->bitpos () != 0)
+  if (arg_type->field (fieldno).bitsize () != 0 || arg1->bitpos () != 0)
     {
       int bit_pos = arg_type->field (fieldno).loc_bitpos ();
-      int bit_size = TYPE_FIELD_BITSIZE (arg_type, fieldno);
+      int bit_size = arg_type->field (fieldno).bitsize ();
 
       return ada_value_primitive_packed_val (arg1,
 					     arg1->contents ().data (),
@@ -7018,7 +7018,7 @@ find_struct_field (const char *name, struct type *type, int offset,
 
       else if (name != NULL && field_name_match (t_field_name, name))
 	{
-	  int bit_size = TYPE_FIELD_BITSIZE (type, i);
+	  int bit_size = type->field (i).bitsize ();
 
 	  if (field_type_p != NULL)
 	    *field_type_p = type->field (i).type ();
@@ -7866,9 +7866,9 @@ ada_template_to_fixed_record_type_1 (struct type *type,
 	     would prevent us from printing this field appropriately.  */
 	  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)
+	  if (type->field (f).bitsize () > 0)
 	    {
-	      fld_bit_len = TYPE_FIELD_BITSIZE (type, f);
+	      fld_bit_len = type->field (f).bitsize ();
 	      rtype->field (f).set_bitsize (fld_bit_len);
 	    }
 	  else
@@ -8409,9 +8409,9 @@ to_fixed_array_type (struct type *type0, struct value *dval,
 	 bitsize of the array elements needs to be set again, and the array
 	 length needs to be recomputed based on that bitsize.  */
       int len = result->length () / result->target_type ()->length ();
-      int elt_bitsize = TYPE_FIELD_BITSIZE (type0, 0);
+      int elt_bitsize = type0->field (0).bitsize ();
 
-      result->field (0).set_bitsize (TYPE_FIELD_BITSIZE (type0, 0));
+      result->field (0).set_bitsize (elt_bitsize);
       result->set_length (len * elt_bitsize / HOST_CHAR_BIT);
       if (result->length () * HOST_CHAR_BIT < len * elt_bitsize)
 	result->set_length (result->length () + 1);
@@ -11111,7 +11111,7 @@ ada_funcall_operation::evaluate (struct type *expect_type,
       (desc_base_type (callee->type ())))
     callee = ada_coerce_to_simple_array (callee);
   else if (callee->type ()->code () == TYPE_CODE_ARRAY
-	   && TYPE_FIELD_BITSIZE (callee->type (), 0) != 0)
+	   && callee->type ()->field (0).bitsize () != 0)
     /* This is a packed array that has already been fixed, and
        therefore already coerced to a simple array.  Nothing further
        to do.  */
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index 3d7f61ff25a2..3b7faee8a613 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -383,8 +383,8 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
 		gdb_printf (stream, ", ");
 	      print_range (arr_type->index_type (), stream,
 			   0 /* bounds_preferred_p */);
-	      if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
-		bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
+	      if (arr_type->field (0).bitsize () > 0)
+		bitsize = arr_type->field (0).bitsize ();
 	      /* A multi-dimensional array is represented using a
 		 sequence of array types.  If one of these types has a
 		 name, then it is not another dimension of the outer
@@ -408,8 +408,8 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
 		gdb_printf (stream, ", ");
 	      print_range_type (range_desc_type->field (k).type (),
 				stream, 0 /* bounds_preferred_p */);
-	      if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
-		bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
+	      if (arr_type->field (0).bitsize () > 0)
+		bitsize = arr_type->field (0).bitsize ();
 	    }
 	}
     }
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index dacc72d9f1bf..9a1f3d6c9ffe 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -117,7 +117,7 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
   unsigned int things_printed = 0;
   unsigned len;
   struct type *elttype, *index_type;
-  unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
+  unsigned long bitsize = type->field (0).bitsize ();
   LONGEST low = 0;
 
   scoped_value_mark mark;
@@ -628,7 +628,7 @@ print_field_values (struct value *value, struct value *outer_value,
 	    {
 	      struct value *v;
 	      int bit_pos = type->field (i).loc_bitpos ();
-	      int bit_size = TYPE_FIELD_BITSIZE (type, i);
+	      int bit_size = type->field (i).bitsize ();
 	      struct value_print_options opts;
 
 	      v = ada_value_primitive_packed_val
@@ -883,7 +883,7 @@ ada_value_print_array (struct value *val, struct ui_file *stream, int recurse,
 
   if (val->entirely_optimized_out ())
     val_print_optimized_out (val, stream);
-  else if (TYPE_FIELD_BITSIZE (type, 0) > 0)
+  else if (type->field (0).bitsize () > 0)
     {
       const gdb_byte *valaddr = val->contents_for_printing ().data ();
       int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr;
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 2c4189203cb0..affb775fb7e2 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -558,7 +558,7 @@ amd64_has_unaligned_fields (struct type *type)
 	     empty structures), and bitfields (these are handled by
 	     the caller).  */
 	  if (type->field (i).is_static ()
-	      || (TYPE_FIELD_BITSIZE (type, i) == 0
+	      || (type->field (i).bitsize () == 0
 		  && subtype->length () == 0)
 	      || TYPE_FIELD_PACKED (type, i))
 	    continue;
@@ -594,7 +594,7 @@ amd64_classify_aggregate_field (struct type *type, int i,
 {
   struct type *subtype = check_typedef (type->field (i).type ());
   enum amd64_reg_class subclass[2];
-  int bitsize = TYPE_FIELD_BITSIZE (type, i);
+  int bitsize = type->field (i).bitsize ();
 
   if (bitsize == 0)
     bitsize = subtype->length () * 8;
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 6d4c9d04cbc9..fcdd304eef30 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -9109,7 +9109,7 @@ arm_return_in_memory (struct gdbarch *gdbarch, struct type *type)
 		  /* Bitfields are not addressable.  If the field bitsize is 
 		     zero, then the field is not packed.  Hence it cannot be
 		     a bitfield or any other packed type.  */
-		  if (TYPE_FIELD_BITSIZE (type, i) == 0)
+		  if (type->field (i).bitsize () == 0)
 		    {
 		      nRc = 1;
 		      break;
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 55450bd29797..068796aa9bcd 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -1323,7 +1323,7 @@ gen_primitive_field (struct agent_expr *ax, struct axs_value *value,
 		       + type->field (fieldno).loc_bitpos ()),
 		      (offset * TARGET_CHAR_BIT
 		       + type->field (fieldno).loc_bitpos ()
-		       + TYPE_FIELD_BITSIZE (type, fieldno)));
+		       + type->field (fieldno).bitsize ()));
   else
     {
       gen_offset (ax, offset
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index a23ceb0ddc4a..708250c4801d 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -1161,8 +1161,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
 		 unnamed fields.  This would lead to misleading
 		 results if the compiler does not put out fields
 		 for such things (I don't know what it does).  */
-	      gdb_printf (stream, " : %d",
-			  TYPE_FIELD_BITSIZE (type, i));
+	      gdb_printf (stream, " : %d", type->field (i).bitsize ());
 	    }
 	  gdb_printf (stream, ";\n");
 	}
@@ -1591,11 +1590,11 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 				language, &local_flags, podata);
 		gdb_printf (stream, " @%s",
 			    plongest (type->field (i).loc_bitpos ()));
-		if (TYPE_FIELD_BITSIZE (type, i) > 1)
+		if (type->field (i).bitsize () > 1)
 		  {
 		    gdb_printf (stream, "-%s",
 				plongest (type->field (i).loc_bitpos ()
-					  + TYPE_FIELD_BITSIZE (type, i)
+					  + type->field (i).bitsize ()
 					  - 1));
 		  }
 		gdb_printf (stream, ";\n");
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index 4853c3f78b12..274871655d05 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -106,7 +106,7 @@ convert_struct_or_union (compile_c_instance *context, struct type *type)
   for (i = 0; i < type->num_fields (); ++i)
     {
       gcc_type field_type;
-      unsigned long bitsize = TYPE_FIELD_BITSIZE (type, i);
+      unsigned long bitsize = type->field (i).bitsize ();
 
       field_type = context->convert_type (type->field (i).type ());
       if (bitsize == 0)
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index cea04b74d10a..ac27e83618b5 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -642,7 +642,7 @@ compile_cplus_convert_struct_or_union_members
 	}
       else
 	{
-	  unsigned long bitsize = TYPE_FIELD_BITSIZE (type, i);
+	  unsigned long bitsize = type->field (i).bitsize ();
 	  enum gcc_cp_symbol_kind field_flags = GCC_CP_SYMBOL_FIELD
 	    | get_field_access_flag (type, i);
 
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index 07cbbed4af91..013b6a9a4275 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -553,7 +553,7 @@ store_regs (struct type *regs_type, CORE_ADDR regs_base)
     {
       const char *reg_name = regs_type->field (fieldno).name ();
       ULONGEST reg_bitpos = regs_type->field (fieldno).loc_bitpos ();
-      ULONGEST reg_bitsize = TYPE_FIELD_BITSIZE (regs_type, fieldno);
+      ULONGEST reg_bitsize = regs_type->field (fieldno).bitsize ();
       ULONGEST reg_offset;
       struct type *reg_type
 	= check_typedef (regs_type->field (fieldno).type ());
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index fd0ba5a349e9..c73764eb5290 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -272,7 +272,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
 		}
 	      else if (val->bits_synthetic_pointer
 		       (type->field (i).loc_bitpos (),
-			TYPE_FIELD_BITSIZE (type, i)))
+			type->field (i).bitsize ()))
 		{
 		  fputs_styled (_("<synthetic pointer>"),
 				metadata_style.style (), stream);
diff --git a/gdb/eval.c b/gdb/eval.c
index 81b7aa0cb993..7f6da822b517 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2378,7 +2378,7 @@ array_operation::evaluate_struct_tuple (struct value *struct_val,
       if (val->type () != field_type)
 	val = value_cast (field_type, val);
 
-      bitsize = TYPE_FIELD_BITSIZE (struct_type, fieldno);
+      bitsize = struct_type->field (fieldno).bitsize ();
       bitpos = struct_type->field (fieldno).loc_bitpos ();
       addr = struct_val->contents_writeable ().data () + bitpos / 8;
       if (bitsize)
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index cd6b191ea628..59ddd75ab798 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1317,12 +1317,12 @@ update_static_array_size (struct type *type)
       if (element_type->code () == TYPE_CODE_ARRAY
 	  && (stride != 0 || element_type->is_multi_dimensional ())
 	  && element_type->length () != 0
-	  && TYPE_FIELD_BITSIZE (element_type, 0) != 0
+	  && element_type->field (0).bitsize () != 0
 	  && get_array_bounds (element_type, &low_bound, &high_bound)
 	  && high_bound >= low_bound)
 	type->field (0).set_bitsize
 	  ((high_bound - low_bound + 1)
-	   * TYPE_FIELD_BITSIZE (element_type, 0));
+	   * element_type->field (0).bitsize ());
 
       return true;
     }
@@ -2330,7 +2330,7 @@ resolve_dynamic_array_or_string_1 (struct type *type,
 	}
     }
   else
-    bit_stride = TYPE_FIELD_BITSIZE (type, 0);
+    bit_stride = type->field (0).bitsize ();
 
   type_allocator alloc (type, type_allocator::SMASH);
   return create_array_type_with_stride (alloc, elt_type, range_type, NULL,
@@ -2550,7 +2550,7 @@ compute_variant_fields_inner (struct type *type,
 			    + (type->field (idx).loc_bitpos ()
 			       / TARGET_CHAR_BIT));
 
-	  LONGEST bitsize = TYPE_FIELD_BITSIZE (type, idx);
+	  LONGEST bitsize = type->field (idx).bitsize ();
 	  LONGEST size = bitsize / 8;
 	  if (size == 0)
 	    size = type->field (idx).type ()->length ();
@@ -2704,8 +2704,8 @@ resolve_dynamic_struct (struct type *type,
 		  == FIELD_LOC_KIND_BITPOS);
 
       new_bit_length = resolved_type->field (i).loc_bitpos ();
-      if (TYPE_FIELD_BITSIZE (resolved_type, i) != 0)
-	new_bit_length += TYPE_FIELD_BITSIZE (resolved_type, i);
+      if (resolved_type->field (i).bitsize () != 0)
+	new_bit_length += resolved_type->field (i).bitsize ();
       else
 	{
 	  struct type *real_type
@@ -5349,7 +5349,7 @@ recursive_dump_type (struct type *type, int spaces)
       else
 	gdb_printf ("%*s[%d] bitpos %s bitsize %d type ", spaces + 2, "",
 		    idx, plongest (type->field (idx).loc_bitpos ()),
-		    TYPE_FIELD_BITSIZE (type, idx));
+		    type->field (idx).bitsize ());
       gdb_printf ("%s name '%s' (%s)\n",
 		  host_address_to_string (type->field (idx).type ()),
 		  type->field (idx).name () != NULL
@@ -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 ());
-	  new_type->field (i).set_bitsize (TYPE_FIELD_BITSIZE (type, i));
+	  new_type->field (i).set_bitsize (type->field (i).bitsize ());
 	  if (type->field (i).type ())
 	    new_type->field (i).set_type
 	      (copy_type_recursive (type->field (i).type (), copied_types));
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 6c522a935c5b..d2edca51caff 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1933,7 +1933,6 @@ 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 TYPE_FIELD_BITSIZE(thistype, n) ((thistype)->field (n).bitsize ())
 #define TYPE_FIELD_PACKED(thistype, n) (((thistype)->field (n).bitsize ())!=0)
 
 #define TYPE_FIELD_PRIVATE_BITS(thistype) \
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index 2eea410bcd3c..552c1219dbfc 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -577,8 +577,7 @@ m2_record_fields (struct type *type, struct ui_file *stream, int show,
 		 unnamed fields.  This would lead to misleading
 		 results if the compiler does not put out fields
 		 for such things (I don't know what it does).  */
-	      gdb_printf (stream, " : %d",
-			  TYPE_FIELD_BITSIZE (type, i));
+	      gdb_printf (stream, " : %d", type->field (i).bitsize ());
 	    }
 	  gdb_printf (stream, ";\n");
 	}
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index a3c2ef897d66..356a3a8d2355 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -529,8 +529,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
 		     unnamed fields.  This would lead to misleading
 		     results if the compiler does not put out fields
 		     for such things (I don't know what it does).  */
-		  gdb_printf (stream, " : %d",
-			      TYPE_FIELD_BITSIZE (type, i));
+		  gdb_printf (stream, " : %d", type->field (i).bitsize ());
 		}
 	      gdb_printf (stream, ";\n");
 	    }
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index 2136a192bbc2..b32c0f17c6b2 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -611,7 +611,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
 		}
 	      else if (val->bits_synthetic_pointer
 		       (type->field (i).loc_bitpos (),
-			TYPE_FIELD_BITSIZE (type, i)))
+			type->field (i).bitsize ()))
 		{
 		  fputs_styled (_("<synthetic pointer>"),
 				metadata_style.style (), stream);
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 9933bb378b57..0ea30d6c6b3f 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -208,7 +208,7 @@ convert_field (struct type *type, int field)
   if (PyObject_SetAttrString (result.get (), "is_base_class", arg.get ()) < 0)
     return NULL;
 
-  arg = gdb_py_object_from_longest (TYPE_FIELD_BITSIZE (type, field));
+  arg = gdb_py_object_from_longest (type->field (field).bitsize ());
   if (arg == NULL)
     return NULL;
   if (PyObject_SetAttrString (result.get (), "bitsize", arg.get ()) < 0)
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 01c11629a70b..4a282cbaaa29 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -153,7 +153,7 @@ print_offset_data::update (struct type *type, unsigned int field_idx,
       || offset_bitpos % TARGET_CHAR_BIT != 0)
     {
       /* We're dealing with a bitfield.  Print the bit offset.  */
-      fieldsize_bit = TYPE_FIELD_BITSIZE (type, field_idx);
+      fieldsize_bit = type->field (field_idx).bitsize ();
 
       unsigned real_bitpos = bitpos + offset_bitpos;
 
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 948966216808..b65dda15c04b 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1244,7 +1244,7 @@ val_print_type_code_flags (struct type *type, struct value *original_value,
 		 problematic place to notify the user of an internal error
 		 though.  Instead just fall through and print the field as an
 		 int.  */
-	      && TYPE_FIELD_BITSIZE (type, field) == 1)
+	      && type->field (field).bitsize () == 1)
 	    {
 	      if (val & ((ULONGEST)1 << type->field (field).loc_bitpos ()))
 		gdb_printf
@@ -1254,7 +1254,7 @@ val_print_type_code_flags (struct type *type, struct value *original_value,
 	    }
 	  else
 	    {
-	      unsigned field_len = TYPE_FIELD_BITSIZE (type, field);
+	      unsigned field_len = type->field (field).bitsize ();
 	      ULONGEST field_val = val >> type->field (field).loc_bitpos ();
 
 	      if (field_len < sizeof (ULONGEST) * TARGET_CHAR_BIT)
diff --git a/gdb/value.c b/gdb/value.c
index 4226e793ac95..1cc326256293 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2946,7 +2946,7 @@ value::primitive_field (LONGEST offset, int fieldno, struct type *arg_type)
      description correctly.  */
   check_typedef (type);
 
-  if (TYPE_FIELD_BITSIZE (arg_type, fieldno))
+  if (arg_type->field (fieldno).bitsize ())
     {
       /* Handle packed fields.
 
@@ -2961,7 +2961,7 @@ value::primitive_field (LONGEST offset, int fieldno, struct type *arg_type)
       LONGEST container_bitsize = type->length () * 8;
 
       v = value::allocate_lazy (type);
-      v->set_bitsize (TYPE_FIELD_BITSIZE (arg_type, fieldno));
+      v->set_bitsize (arg_type->field (fieldno).bitsize ());
       if ((bitpos % container_bitsize) + v->bitsize () <= container_bitsize
 	  && type->length () <= (int) sizeof (LONGEST))
 	v->set_bitpos (bitpos % container_bitsize);
@@ -3180,7 +3180,7 @@ unpack_value_field_as_long (struct type *type, const gdb_byte *valaddr,
 			    const struct value *val, LONGEST *result)
 {
   int bitpos = type->field (fieldno).loc_bitpos ();
-  int bitsize = TYPE_FIELD_BITSIZE (type, fieldno);
+  int bitsize = type->field (fieldno).bitsize ();
   struct type *field_type = type->field (fieldno).type ();
   int bit_offset;
 
@@ -3203,7 +3203,7 @@ LONGEST
 unpack_field_as_long (struct type *type, const gdb_byte *valaddr, int fieldno)
 {
   int bitpos = type->field (fieldno).loc_bitpos ();
-  int bitsize = TYPE_FIELD_BITSIZE (type, fieldno);
+  int bitsize = type->field (fieldno).bitsize ();
   struct type *field_type = type->field (fieldno).type ();
 
   return unpack_bits_as_long (field_type, valaddr, bitpos, bitsize);
@@ -3261,7 +3261,7 @@ value_field_bitfield (struct type *type, int fieldno,
 		      LONGEST embedded_offset, const struct value *val)
 {
   int bitpos = type->field (fieldno).loc_bitpos ();
-  int bitsize = TYPE_FIELD_BITSIZE (type, fieldno);
+  int bitsize = type->field (fieldno).bitsize ();
   struct value *res_val = value::allocate (type->field (fieldno).type ());
 
   val->unpack_bitfield (res_val, bitpos, bitsize, valaddr, embedded_offset);
-- 
2.42.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 7/7] gdb: remove TYPE_FIELD_PACKED
  2023-08-31 15:46 [PATCH 0/7] Remove some more TYPE/FIELD macros Simon Marchi
                   ` (5 preceding siblings ...)
  2023-08-31 15:46 ` [PATCH 6/7] gdb: remove TYPE_FIELD_BITSIZE Simon Marchi
@ 2023-08-31 15:46 ` Simon Marchi
  2023-08-31 17:05 ` [PATCH 0/7] Remove some more TYPE/FIELD macros Tom Tromey
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2023-08-31 15:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Replace with a new equivalent "is_packed" method on struct field.

Change-Id: I78647be3d408b40b63becb6b6f0fca211bede51c
---
 gdb/ada-valprint.c | 2 +-
 gdb/amd64-tdep.c   | 2 +-
 gdb/ax-gdb.c       | 4 ++--
 gdb/c-typeprint.c  | 2 +-
 gdb/cp-valprint.c  | 2 +-
 gdb/gdbtypes.h     | 7 +++++--
 gdb/m2-typeprint.c | 2 +-
 gdb/p-typeprint.c  | 2 +-
 gdb/p-valprint.c   | 2 +-
 gdb/typeprint.c    | 2 +-
 gdb/valops.c       | 2 +-
 11 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 9a1f3d6c9ffe..eaeca0f65161 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -615,7 +615,7 @@ print_field_values (struct value *value, struct value *outer_value,
       gdb_puts (" => ", stream);
       annotate_field_value ();
 
-      if (TYPE_FIELD_PACKED (type, i))
+      if (type->field (i).is_packed ())
 	{
 	  /* Bitfields require special handling, especially due to byte
 	     order problems.  */
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index affb775fb7e2..e6feee677b3d 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -560,7 +560,7 @@ amd64_has_unaligned_fields (struct type *type)
 	  if (type->field (i).is_static ()
 	      || (type->field (i).bitsize () == 0
 		  && subtype->length () == 0)
-	      || TYPE_FIELD_PACKED (type, i))
+	      || type->field (i).is_packed ())
 	    continue;
 
 	  int bitpos = type->field (i).loc_bitpos ();
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 068796aa9bcd..a679c8649150 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -1317,7 +1317,7 @@ gen_primitive_field (struct agent_expr *ax, struct axs_value *value,
 		     int offset, int fieldno, struct type *type)
 {
   /* Is this a bitfield?  */
-  if (TYPE_FIELD_PACKED (type, fieldno))
+  if (type->field (fieldno).is_packed ())
     gen_bitfield_ref (ax, value, type->field (fieldno).type (),
 		      (offset * TARGET_CHAR_BIT
 		       + type->field (fieldno).loc_bitpos ()),
@@ -1502,7 +1502,7 @@ gen_struct_elt_for_reference (struct agent_expr *ax, struct axs_value *value,
 		       fieldname);
 	      return 1;
 	    }
-	  if (TYPE_FIELD_PACKED (t, i))
+	  if (t->field (i).is_packed ())
 	    error (_("pointers to bitfield members not allowed"));
 
 	  /* FIXME we need a way to do "want_address" equivalent */	  
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 708250c4801d..e141a62311ca 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -1154,7 +1154,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
 			  stream, newshow, level + 4,
 			  language, &local_flags, &local_podata);
 
-	  if (!is_static && TYPE_FIELD_PACKED (type, i))
+	  if (!is_static && type->field (i).is_packed ())
 	    {
 	      /* It is a bitfield.  This code does not attempt
 		 to look at the bitpos and reconstruct filler,
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index c73764eb5290..820a761054a8 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -259,7 +259,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
 	  annotate_field_value ();
 
 	  if (!type->field (i).is_static ()
-	      && TYPE_FIELD_PACKED (type, i))
+	      && type->field (i).is_packed ())
 	    {
 	      struct value *v;
 
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index d2edca51caff..f45a957f3443 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -584,6 +584,11 @@ struct field
     m_bitsize = bitsize;
   }
 
+  bool is_packed () const
+  {
+    return m_bitsize != 0;
+  }
+
   /* Return true if this field is static; false if not.  */
   bool is_static () const
   {
@@ -1933,8 +1938,6 @@ 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 TYPE_FIELD_PACKED(thistype, n) (((thistype)->field (n).bitsize ())!=0)
-
 #define TYPE_FIELD_PRIVATE_BITS(thistype) \
   TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits
 #define TYPE_FIELD_PROTECTED_BITS(thistype) \
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index 552c1219dbfc..9a4cb8d6b558 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -570,7 +570,7 @@ m2_record_fields (struct type *type, struct ui_file *stream, int show,
 	  m2_print_type (type->field (i).type (),
 			 "",
 			 stream, 0, level + 4, flags);
-	  if (TYPE_FIELD_PACKED (type, i))
+	  if (type->field (i).is_packed ())
 	    {
 	      /* It is a bitfield.  This code does not attempt
 		 to look at the bitpos and reconstruct filler,
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index 356a3a8d2355..54ff96612202 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -522,7 +522,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
 				 type->field (i).name (),
 				 stream, show - 1, level + 4, flags);
 	      if (!type->field (i).is_static ()
-		  && TYPE_FIELD_PACKED (type, i))
+		  && type->field (i).is_packed ())
 		{
 		  /* It is a bitfield.  This code does not attempt
 		     to look at the bitpos and reconstruct filler,
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index b32c0f17c6b2..fb9386293a6f 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -598,7 +598,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
 	  annotate_field_value ();
 
 	  if (!type->field (i).is_static ()
-	      && TYPE_FIELD_PACKED (type, i))
+	      && type->field (i).is_packed ())
 	    {
 	      struct value *v;
 
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 4a282cbaaa29..259ff132142b 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -149,7 +149,7 @@ print_offset_data::update (struct type *type, unsigned int field_idx,
 
   maybe_print_hole (stream, bitpos, "hole");
 
-  if (TYPE_FIELD_PACKED (type, field_idx)
+  if (type->field (field_idx).is_packed ()
       || offset_bitpos % TARGET_CHAR_BIT != 0)
     {
       /* We're dealing with a bitfield.  Print the bit offset.  */
diff --git a/gdb/valops.c b/gdb/valops.c
index b007fe08d348..70851cd40b4f 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3581,7 +3581,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
 		v = value_addr (v);
 	      return v;
 	    }
-	  if (TYPE_FIELD_PACKED (t, i))
+	  if (t->field (i).is_packed ())
 	    error (_("pointers to bitfield members not allowed"));
 
 	  if (want_address)
-- 
2.42.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/7] Remove some more TYPE/FIELD macros
  2023-08-31 15:46 [PATCH 0/7] Remove some more TYPE/FIELD macros Simon Marchi
                   ` (6 preceding siblings ...)
  2023-08-31 15:46 ` [PATCH 7/7] gdb: remove TYPE_FIELD_PACKED Simon Marchi
@ 2023-08-31 17:05 ` Tom Tromey
  2023-08-31 17:16   ` Simon Marchi
  7 siblings, 1 reply; 10+ messages in thread
From: Tom Tromey @ 2023-08-31 17:05 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> Here's another round of gdbtypes.h macro removal, converting to methods.

Looks great.  Thank you.
Approved-By: Tom Tromey <tom@tromey.com>

Tom

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/7] Remove some more TYPE/FIELD macros
  2023-08-31 17:05 ` [PATCH 0/7] Remove some more TYPE/FIELD macros Tom Tromey
@ 2023-08-31 17:16   ` Simon Marchi
  0 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2023-08-31 17:16 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches

On 8/31/23 13:05, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> Here's another round of gdbtypes.h macro removal, converting to methods.
> 
> Looks great.  Thank you.
> Approved-By: Tom Tromey <tom@tromey.com>
> 
> Tom

Thanks, pushed.

Simon

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-08-31 17:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-31 15:46 [PATCH 0/7] Remove some more TYPE/FIELD macros Simon Marchi
2023-08-31 15:46 ` [PATCH 1/7] gdb: introduce field::is_artificial / field::set_is_artificial Simon Marchi
2023-08-31 15:46 ` [PATCH 2/7] gdb: remove FIELD_ARTIFICIAL Simon Marchi
2023-08-31 15:46 ` [PATCH 3/7] gdb: remove TYPE_FIELD_ARTIFICIAL Simon Marchi
2023-08-31 15:46 ` [PATCH 4/7] gdb: introduce field::bitsize / field::set_bitsize Simon Marchi
2023-08-31 15:46 ` [PATCH 5/7] gdb: remove FIELD_BITSIZE Simon Marchi
2023-08-31 15:46 ` [PATCH 6/7] gdb: remove TYPE_FIELD_BITSIZE Simon Marchi
2023-08-31 15:46 ` [PATCH 7/7] gdb: remove TYPE_FIELD_PACKED Simon Marchi
2023-08-31 17:05 ` [PATCH 0/7] Remove some more TYPE/FIELD macros Tom Tromey
2023-08-31 17:16   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).