public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] gdb: add field::name / field::set_name
@ 2021-08-30 15:49 Simon Marchi
  2021-08-30 15:49 ` [PATCH 2/2] gdb: remove TYPE_FIELD_NAME and FIELD_NAME macros Simon Marchi
  2021-10-01  2:13 ` [PATCH 1/2] gdb: add field::name / field::set_name Simon Marchi
  0 siblings, 2 replies; 3+ messages in thread
From: Simon Marchi @ 2021-08-30 15:49 UTC (permalink / raw)
  To: gdb-patches

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

Add the `name` and `set_name` methods on `struct field`, in order to
remove `FIELD_NAME` and `TYPE_FIELD_NAME` macros.  In this patch, the
macros are changed to use `field::name`, so all the call sites that are
used to set the field's name are changed to use `field::set_name`.
The next patch will remove the macros completely.

Note that because of the name clash between the existing field named
`name` and the new method, I renamed the field `m_name`.  It is not
private per-se, because we can't make `struct field` a non-POD yet, but
it should be considered private anyway (not accessed outside `struct
field`).

Change-Id: If16ddbca4e0c39d0ff9da420bb5cdebe5b9b0896
---
 gdb/ada-lang.c     | 10 +++++-----
 gdb/coffread.c     |  8 +++++---
 gdb/ctfread.c      |  4 ++--
 gdb/dwarf2/read.c  | 30 +++++++++++++++---------------
 gdb/gdbtypes.c     | 12 ++++++------
 gdb/gdbtypes.h     | 16 +++++++++++++---
 gdb/gnu-v3-abi.c   | 12 ++++++------
 gdb/mdebugread.c   |  6 +++---
 gdb/rust-lang.c    |  4 ++--
 gdb/stabsread.c    | 26 +++++++++++++-------------
 gdb/windows-tdep.c |  2 +-
 11 files changed, 71 insertions(+), 59 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 6680a4fd657..ed7a0b80b8b 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -7590,7 +7590,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
 	  ada_ensure_varsize_limit (field_type);
 
 	  rtype->field (f).set_type (field_type);
-	  TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
+	  rtype->field (f).set_name (TYPE_FIELD_NAME (type, f));
 	  /* The multiplication can potentially overflow.  But because
 	     the field length has been size-checked just above, and
 	     assuming that the maximum size is a reasonable value,
@@ -7613,7 +7613,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
 	     to distinguish between the two options.  Stripping it
 	     would prevent us from printing this field appropriately.  */
 	  rtype->field (f).set_type (type->field (f).type ());
-	  TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
+	  rtype->field (f).set_name (TYPE_FIELD_NAME (type, f));
 	  if (TYPE_FIELD_BITSIZE (type, f) > 0)
 	    fld_bit_len =
 	      TYPE_FIELD_BITSIZE (rtype, f) = TYPE_FIELD_BITSIZE (type, f);
@@ -7675,7 +7675,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
       else
 	{
 	  rtype->field (variant_field).set_type (branch_type);
-	  TYPE_FIELD_NAME (rtype, variant_field) = "S";
+	  rtype->field (variant_field).set_name ("S");
 	  fld_bit_len =
 	    TYPE_LENGTH (rtype->field (variant_field).type ()) *
 	    TARGET_CHAR_BIT;
@@ -7791,7 +7791,7 @@ template_to_static_fixed_type (struct type *type0)
 	      TYPE_LENGTH (type) = 0;
 	    }
 	  type->field (f).set_type (new_type);
-	  TYPE_FIELD_NAME (type, f) = TYPE_FIELD_NAME (type0, f);
+	  type->field (f).set_name (TYPE_FIELD_NAME (type0, f));
 	}
     }
 
@@ -7860,7 +7860,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
   else
     {
       rtype->field (variant_field).set_type (branch_type);
-      TYPE_FIELD_NAME (rtype, variant_field) = "S";
+      rtype->field (variant_field).set_name ("S");
       TYPE_FIELD_BITSIZE (rtype, variant_field) = 0;
       TYPE_LENGTH (rtype) += TYPE_LENGTH (branch_type);
     }
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 0135363bc5a..30cf81988c5 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -2008,7 +2008,8 @@ coff_read_struct_type (int index, int length, int lastsym,
 	  list = newobj;
 
 	  /* Save the data.  */
-	  list->field.name = obstack_strdup (&objfile->objfile_obstack, name);
+	  list->field.set_name (obstack_strdup (&objfile->objfile_obstack,
+						name));
 	  list->field.set_type (decode_type (ms, ms->c_type, &sub_aux,
 					     objfile));
 	  SET_FIELD_BITPOS (list->field, 8 * ms->c_value);
@@ -2024,7 +2025,8 @@ coff_read_struct_type (int index, int length, int lastsym,
 	  list = newobj;
 
 	  /* Save the data.  */
-	  list->field.name = obstack_strdup (&objfile->objfile_obstack, name);
+	  list->field.set_name (obstack_strdup (&objfile->objfile_obstack,
+						name));
 	  list->field.set_type (decode_type (ms, ms->c_type, &sub_aux,
 					     objfile));
 	  SET_FIELD_BITPOS (list->field, ms->c_value);
@@ -2142,7 +2144,7 @@ coff_read_enum_type (int index, int length, int lastsym,
 	  struct symbol *xsym = syms->symbol[j];
 
 	  SYMBOL_TYPE (xsym) = type;
-	  TYPE_FIELD_NAME (type, n) = xsym->linkage_name ();
+	  type->field (n).set_name (xsym->linkage_name ());
 	  SET_FIELD_ENUMVAL (type->field (n), SYMBOL_VALUE (xsym));
 	  if (SYMBOL_VALUE (xsym) < 0)
 	    unsigned_enum = 0;
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index ef730df9f0b..4328203aba8 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -390,7 +390,7 @@ ctf_add_member_cb (const char *name,
   uint32_t kind;
 
   fp = &new_field.field;
-  FIELD_NAME (*fp) = name;
+  fp->set_name (name);
 
   kind = ctf_type_kind (ccp->fp, tid);
   t = fetch_tid_type (ccp, tid);
@@ -429,7 +429,7 @@ ctf_add_enum_member_cb (const char *name, int enum_value, void *arg)
   struct ctf_context *ccp = fip->cur_context;
 
   fp = &new_field.field;
-  FIELD_NAME (*fp) = name;
+  fp->set_name (name);
   fp->set_type (nullptr);
   SET_FIELD_ENUMVAL (*fp, enum_value);
   FIELD_BITSIZE (*fp) = 0;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 5385a3aff53..786017de914 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9061,14 +9061,14 @@ 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_NAME (type, 0) = "<<discriminant>>";
+      type->field (0).set_name ("<<discriminant>>");
       SET_FIELD_BITPOS (type->field (0), bit_offset);
 
       /* The order of fields doesn't really matter, so put the real
 	 field at index 1 and the data-less field at index 2.  */
       type->field (1) = saved_field;
-      TYPE_FIELD_NAME (type, 1)
-	= rust_last_path_segment (type->field (1).type ()->name ());
+      type->field (1).set_name
+	(rust_last_path_segment (type->field (1).type ()->name ()));
       type->field (1).type ()->set_name
 	(rust_fully_qualify (&objfile->objfile_obstack, type->name (),
 			     TYPE_FIELD_NAME (type, 1)));
@@ -9081,7 +9081,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       type->field (2).set_type (dataless_type);
       /* NAME points into the original discriminant name, which
 	 already has the correct lifetime.  */
-      TYPE_FIELD_NAME (type, 2) = name;
+      type->field (2).set_name (name);
       SET_FIELD_BITPOS (type->field (2), 0);
 
       /* Indicate that this is a variant type.  */
@@ -9099,7 +9099,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       struct type *field_type = type->field (0).type ();
       const char *variant_name
 	= rust_last_path_segment (field_type->name ());
-      TYPE_FIELD_NAME (type, 0) = variant_name;
+      type->field (0).set_name (variant_name);
       field_type->set_name
 	(rust_fully_qualify (&objfile->objfile_obstack,
 			     type->name (), variant_name));
@@ -9158,7 +9158,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_NAME (type, 0) = "<<discriminant>>";
+      type->field (0).set_name ("<<discriminant>>");
 
       /* We need a way to find the correct discriminant given a
 	 variant name.  For convenience we build a map here.  */
@@ -9208,7 +9208,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 	      sub_type->set_num_fields (sub_type->num_fields () - 1);
 	      sub_type->set_fields (sub_type->fields () + 1);
 	    }
-	  TYPE_FIELD_NAME (type, i) = variant_name;
+	  type->field (i).set_name (variant_name);
 	  sub_type->set_name
 	    (rust_fully_qualify (&objfile->objfile_obstack,
 				 type->name (), variant_name));
@@ -14594,7 +14594,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
 
       /* The name is already allocated along with this objfile, so we don't
 	 need to duplicate it for the type.  */
-      fp->name = fieldname;
+      fp->set_name (fieldname);
 
       /* Change accessibility for artificial fields (e.g. virtual table
 	 pointer or virtual base class pointer) to private.  */
@@ -14641,7 +14641,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
 	 need to duplicate it for the type.  */
       SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
       fp->set_type (die_type (die, cu));
-      FIELD_NAME (*fp) = fieldname;
+      fp->set_name (fieldname);
     }
   else if (die->tag == DW_TAG_inheritance)
     {
@@ -14649,7 +14649,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       handle_data_member_location (die, cu, fp);
       FIELD_BITSIZE (*fp) = 0;
       fp->set_type (die_type (die, cu));
-      FIELD_NAME (*fp) = fp->type ()->name ();
+      fp->set_name (fp->type ()->name ());
     }
   else
     gdb_assert_not_reached ("missing case in dwarf2_add_field");
@@ -16098,7 +16098,7 @@ update_enumeration_type_from_children (struct die_info *die,
 
       fields.emplace_back ();
       struct field &field = fields.back ();
-      FIELD_NAME (field) = dwarf2_physname (name, child_die, cu);
+      field.set_name (dwarf2_physname (name, child_die, cu));
       SET_FIELD_ENUMVAL (field, value);
     }
 
@@ -16472,9 +16472,9 @@ quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
 
       /* Set the name of each field in the bounds.  */
       xsnprintf (name, sizeof (name), "LB%d", i / 2);
-      FIELD_NAME (range_fields[i]) = objfile->intern (name);
+      range_fields[i].set_name (objfile->intern (name));
       xsnprintf (name, sizeof (name), "UB%d", i / 2);
-      FIELD_NAME (range_fields[i + 1]) = objfile->intern (name);
+      range_fields[i + 1].set_name (objfile->intern (name));
     }
 
   struct type *bounds = alloc_type (objfile);
@@ -16516,10 +16516,10 @@ quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
   /* The names are chosen to coincide with what the compiler does with
      -fgnat-encodings=all, which the Ada code in gdb already
      understands.  */
-  TYPE_FIELD_NAME (result, 0) = "P_ARRAY";
+  result->field (0).set_name ("P_ARRAY");
   result->field (0).set_type (lookup_pointer_type (type));
 
-  TYPE_FIELD_NAME (result, 1) = "P_BOUNDS";
+  result->field (1).set_name ("P_BOUNDS");
   result->field (1).set_type (lookup_pointer_type (bounds));
   SET_FIELD_BITPOS (result->field (1), 8 * bounds_offset);
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 74ad5d6f7fe..a64ed12c1bb 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -4876,8 +4876,9 @@ print_args (struct field *args, int nargs, int spaces)
 
       for (i = 0; i < nargs; i++)
 	{
-	  printf_filtered ("%*s[%d] name '%s'\n", spaces, "", i,
-			   args[i].name != NULL ? args[i].name : "<NULL>");
+	  printf_filtered
+	    ("%*s[%d] name '%s'\n", spaces, "", i,
+	     args[i].name () != NULL ? args[i].name () : "<NULL>");
 	  recursive_dump_type (args[i].type (), spaces + 2);
 	}
     }
@@ -5558,8 +5559,7 @@ copy_type_recursive (struct objfile *objfile,
 	      (copy_type_recursive (objfile, type->field (i).type (),
 				    copied_types));
 	  if (TYPE_FIELD_NAME (type, i))
-	    TYPE_FIELD_NAME (new_type, i) = 
-	      xstrdup (TYPE_FIELD_NAME (type, i));
+	    new_type->field (i).set_name (xstrdup (TYPE_FIELD_NAME (type, i)));
 	  switch (TYPE_FIELD_LOC_KIND (type, i))
 	    {
 	    case FIELD_LOC_KIND_BITPOS:
@@ -5842,7 +5842,7 @@ append_flags_type_field (struct type *type, int start_bitpos, int nr_bits,
   gdb_assert (nr_bits >= 1 && (start_bitpos + nr_bits) <= type_bitsize);
   gdb_assert (name != NULL);
 
-  TYPE_FIELD_NAME (type, field_nr) = xstrdup (name);
+  type->field (field_nr).set_name (xstrdup (name));
   type->field (field_nr).set_type (field_type);
   SET_FIELD_BITPOS (type->field (field_nr), start_bitpos);
   TYPE_FIELD_BITSIZE (type, field_nr) = nr_bits;
@@ -5893,7 +5893,7 @@ append_composite_type_field_raw (struct type *t, const char *name,
   f = &t->field (t->num_fields () - 1);
   memset (f, 0, sizeof f[0]);
   f[0].set_type (field);
-  FIELD_NAME (f[0]) = name;
+  f[0].set_name (name);
   return f;
 }
 
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index bfb7f2965a6..949a932935b 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -654,6 +654,16 @@ struct field
     this->m_type = type;
   }
 
+  const char *name () const
+  {
+    return m_name;
+  }
+
+  void set_name (const char *name)
+  {
+    m_name = name;
+  }
+
   union field_location loc;
 
   /* * For a function or member type, this is 1 if the argument is
@@ -685,7 +695,7 @@ struct field
      NULL for range bounds, array domains, and member function
      arguments.  */
 
-  const char *name;
+  const char *m_name;
 };
 
 struct range_bounds
@@ -1968,7 +1978,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_NAME(thisfld) ((thisfld).name)
+#define FIELD_NAME(thisfld) ((thisfld).name ())
 #define FIELD_LOC_KIND(thisfld) ((thisfld).loc_kind)
 #define FIELD_BITPOS_LVAL(thisfld) ((thisfld).loc.bitpos)
 #define FIELD_BITPOS(thisfld) (FIELD_BITPOS_LVAL (thisfld) + 0)
@@ -1995,7 +2005,7 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
 #define FIELD_ARTIFICIAL(thisfld) ((thisfld).artificial)
 #define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
 
-#define TYPE_FIELD_NAME(thistype, n) FIELD_NAME((thistype)->field (n))
+#define TYPE_FIELD_NAME(thistype, n) ((thistype)->field (n).name ())
 #define TYPE_FIELD_LOC_KIND(thistype, n) FIELD_LOC_KIND ((thistype)->field (n))
 #define TYPE_FIELD_BITPOS(thistype, n) FIELD_BITPOS ((thistype)->field (n))
 #define TYPE_FIELD_ENUMVAL(thistype, n) FIELD_ENUMVAL ((thistype)->field (n))
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 45e57c210cb..c928afe6c34 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -135,28 +135,28 @@ build_gdb_vtable_type (struct gdbarch *arch)
   offset = 0;
 
   /* ptrdiff_t vcall_and_vbase_offsets[0]; */
-  FIELD_NAME (*field) = "vcall_and_vbase_offsets";
+  field->set_name ("vcall_and_vbase_offsets");
   field->set_type (lookup_array_range_type (ptrdiff_type, 0, -1));
   SET_FIELD_BITPOS (*field, offset * TARGET_CHAR_BIT);
   offset += TYPE_LENGTH (field->type ());
   field++;
 
   /* ptrdiff_t offset_to_top; */
-  FIELD_NAME (*field) = "offset_to_top";
+  field->set_name ("offset_to_top");
   field->set_type (ptrdiff_type);
   SET_FIELD_BITPOS (*field, offset * TARGET_CHAR_BIT);
   offset += TYPE_LENGTH (field->type ());
   field++;
 
   /* void *type_info; */
-  FIELD_NAME (*field) = "type_info";
+  field->set_name ("type_info");
   field->set_type (void_ptr_type);
   SET_FIELD_BITPOS (*field, offset * TARGET_CHAR_BIT);
   offset += TYPE_LENGTH (field->type ());
   field++;
 
   /* void (*virtual_functions[0]) (); */
-  FIELD_NAME (*field) = "virtual_functions";
+  field->set_name ("virtual_functions");
   field->set_type (lookup_array_range_type (ptr_to_void_fn_type, 0, -1));
   SET_FIELD_BITPOS (*field, offset * TARGET_CHAR_BIT);
   offset += TYPE_LENGTH (field->type ());
@@ -1036,14 +1036,14 @@ build_std_type_info_type (struct gdbarch *arch)
   offset = 0;
 
   /* The vtable.  */
-  FIELD_NAME (*field) = "_vptr.type_info";
+  field->set_name ("_vptr.type_info");
   field->set_type (void_ptr_type);
   SET_FIELD_BITPOS (*field, offset * TARGET_CHAR_BIT);
   offset += TYPE_LENGTH (field->type ());
   field++;
 
   /* The name.  */
-  FIELD_NAME (*field) = "__name";
+  field->set_name ("__name");
   field->set_type (char_ptr_type);
   SET_FIELD_BITPOS (*field, offset * TARGET_CHAR_BIT);
   offset += TYPE_LENGTH (field->type ());
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 026f2ff20da..3e560ae53e2 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1058,13 +1058,13 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 
 		SET_FIELD_ENUMVAL (*f, tsym.value);
 		f->set_type (t);
-		FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss;
+		f->set_name (debug_info->ss + cur_fdr->issBase + tsym.iss);
 		FIELD_BITSIZE (*f) = 0;
 
 		enum_sym = new (&mdebugread_objfile->objfile_obstack) symbol;
 		enum_sym->set_linkage_name
 		  (obstack_strdup (&mdebugread_objfile->objfile_obstack,
-				   f->name));
+				   f->name ()));
 		SYMBOL_ACLASS_INDEX (enum_sym) = LOC_CONST;
 		SYMBOL_TYPE (enum_sym) = t;
 		SYMBOL_DOMAIN (enum_sym) = VAR_DOMAIN;
@@ -1241,7 +1241,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
       {
 	struct field *f = &top_stack->cur_type->field (top_stack->cur_field);
 	top_stack->cur_field++;
-	FIELD_NAME (*f) = name;
+	f->set_name (name);
 	SET_FIELD_BITPOS (*f, sh->value);
 	bitsize = 0;
 	f->set_type (parse_type (cur_fd, ax, sh->index, &bitsize, bigend,
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 60ea89b1394..f3e346e4db5 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -915,7 +915,7 @@ rust_composite_type (struct type *original,
       SET_FIELD_BITPOS (*field, bitpos);
       bitpos += TYPE_LENGTH (type1) * TARGET_CHAR_BIT;
 
-      FIELD_NAME (*field) = field1;
+      field->set_name (field1);
       field->set_type (type1);
       ++i;
     }
@@ -935,7 +935,7 @@ rust_composite_type (struct type *original,
 	}
       SET_FIELD_BITPOS (*field, bitpos);
 
-      FIELD_NAME (*field) = field2;
+      field->set_name (field2);
       field->set_type (type2);
       ++i;
     }
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 72cb351d2f8..765fec4b23a 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -1225,8 +1225,8 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
 
 	    for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
 	      if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
-		TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
-		  TYPE_BASECLASS (SYMBOL_TYPE (sym), j)->name ();
+		SYMBOL_TYPE (sym)->field (j).set_name
+		  (TYPE_BASECLASS (SYMBOL_TYPE (sym), j)->name ());
 	  }
 
       if (SYMBOL_TYPE (sym)->name () == NULL)
@@ -2712,8 +2712,8 @@ read_cpp_abbrev (struct stab_field_info *fip, const char **pp,
 	    {
 	      name = "";
 	    }
-	  fip->list->field.name = obconcat (&objfile->objfile_obstack,
-					    vptr_name, name, (char *) NULL);
+	  fip->list->field.set_name (obconcat (&objfile->objfile_obstack,
+					       vptr_name, name, (char *) NULL));
 	  break;
 
 	case 'b':		/* $vb -- a virtual bsomethingorother */
@@ -2725,15 +2725,15 @@ read_cpp_abbrev (struct stab_field_info *fip, const char **pp,
 			 symnum);
 	      name = "FOO";
 	    }
-	  fip->list->field.name = obconcat (&objfile->objfile_obstack, vb_name,
-					    name, (char *) NULL);
+	  fip->list->field.set_name (obconcat (&objfile->objfile_obstack,
+					       vb_name, name, (char *) NULL));
 	  break;
 
 	default:
 	  invalid_cpp_abbrev_complaint (*pp);
-	  fip->list->field.name = obconcat (&objfile->objfile_obstack,
-					    "INVALID_CPLUSPLUS_ABBREV",
-					    (char *) NULL);
+	  fip->list->field.set_name (obconcat (&objfile->objfile_obstack,
+					       "INVALID_CPLUSPLUS_ABBREV",
+					       (char *) NULL));
 	  break;
 	}
 
@@ -2782,8 +2782,8 @@ read_one_struct_field (struct stab_field_info *fip, const char **pp,
 {
   struct gdbarch *gdbarch = objfile->arch ();
 
-  fip->list->field.name
-    = obstack_strndup (&objfile->objfile_obstack, *pp, p - *pp);
+  fip->list->field.set_name
+    (obstack_strndup (&objfile->objfile_obstack, *pp, p - *pp));
   *pp = p + 1;
 
   /* This means we have a visibility for a field coming.  */
@@ -3120,7 +3120,7 @@ read_baseclasses (struct stab_field_info *fip, const char **pp,
 	 field's name.  */
 
       newobj->field.set_type (read_type (pp, objfile));
-      newobj->field.name = newobj->field.type ()->name ();
+      newobj->field.set_name (newobj->field.type ()->name ());
 
       /* Skip trailing ';' and bump count of number of fields seen.  */
       if (**pp == ';')
@@ -3638,7 +3638,7 @@ read_enum_type (const char **pp, struct type *type,
 	  struct symbol *xsym = syms->symbol[j];
 
 	  SYMBOL_TYPE (xsym) = type;
-	  TYPE_FIELD_NAME (type, n) = xsym->linkage_name ();
+	  type->field (n).set_name (xsym->linkage_name ());
 	  SET_FIELD_ENUMVAL (type->field (n), SYMBOL_VALUE (xsym));
 	  TYPE_FIELD_BITSIZE (type, n) = 0;
 	}
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index ca854390b7e..a1296bea951 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -762,7 +762,7 @@ create_enum (struct gdbarch *gdbarch, int bit, const char *name,
 
   for (i = 0; i < count; i++)
     {
-      TYPE_FIELD_NAME (type, i) = values[i].name;
+      type->field (i).set_name (values[i].name);
       SET_FIELD_ENUMVAL (type->field (i), values[i].value);
     }
 
-- 
2.33.0


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

* [PATCH 2/2] gdb: remove TYPE_FIELD_NAME and FIELD_NAME macros
  2021-08-30 15:49 [PATCH 1/2] gdb: add field::name / field::set_name Simon Marchi
@ 2021-08-30 15:49 ` Simon Marchi
  2021-10-01  2:13 ` [PATCH 1/2] gdb: add field::name / field::set_name Simon Marchi
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2021-08-30 15:49 UTC (permalink / raw)
  To: gdb-patches

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

Remove the `TYPE_FIELD_NAME` and `FIELD_NAME` macros, changing all the
call sites to use field::name directly.

Change-Id: I6900ae4e1ffab1396e24fb3298e94bf123826ca6
---
 gdb/ada-lang.c                    | 54 +++++++++++++++----------------
 gdb/ada-typeprint.c               | 10 +++---
 gdb/ada-valprint.c                |  8 ++---
 gdb/ada-varobj.c                  |  4 +--
 gdb/ax-gdb.c                      |  4 +--
 gdb/c-typeprint.c                 |  6 ++--
 gdb/c-varobj.c                    | 12 +++----
 gdb/compile/compile-c-types.c     |  4 +--
 gdb/compile/compile-cplus-types.c |  4 +--
 gdb/compile/compile-object-load.c |  2 +-
 gdb/completer.c                   |  8 ++---
 gdb/cp-valprint.c                 |  8 ++---
 gdb/d-valprint.c                  |  4 +--
 gdb/dwarf2/read.c                 | 34 +++++++++----------
 gdb/eval.c                        |  2 +-
 gdb/f-typeprint.c                 |  2 +-
 gdb/f-valprint.c                  |  2 +-
 gdb/gdbtypes.c                    | 15 ++++-----
 gdb/gdbtypes.h                    |  4 +--
 gdb/gnu-v2-abi.c                  |  2 +-
 gdb/go-lang.c                     |  4 +--
 gdb/guile/scm-type.c              |  8 ++---
 gdb/m2-typeprint.c                | 12 +++----
 gdb/p-lang.c                      | 20 ++++++------
 gdb/p-typeprint.c                 |  8 ++---
 gdb/p-valprint.c                  |  4 +--
 gdb/python/py-type.c              | 14 ++++----
 gdb/rust-lang.c                   | 26 +++++++--------
 gdb/stabsread.c                   |  2 +-
 gdb/symtab.c                      |  6 ++--
 gdb/typeprint.c                   |  2 +-
 gdb/valops.c                      |  6 ++--
 gdb/valprint.c                    | 10 +++---
 gdb/value.c                       |  2 +-
 34 files changed, 155 insertions(+), 158 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index ed7a0b80b8b..49284444576 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -468,7 +468,7 @@ ada_get_field_index (const struct type *type, const char *field_name,
   struct type *struct_type = check_typedef ((struct type *) type);
 
   for (fieldno = 0; fieldno < struct_type->num_fields (); fieldno++)
-    if (field_name_match (TYPE_FIELD_NAME (struct_type, fieldno), field_name))
+    if (field_name_match (struct_type->field (fieldno).name (), field_name))
       return fieldno;
 
   if (!maybe_missing)
@@ -1375,13 +1375,13 @@ ada_fixup_array_indexes_type (struct type *index_desc_type)
      is not equal to the field name.  */
   if (index_desc_type->field (0).type ()->name () != NULL
       && strcmp (index_desc_type->field (0).type ()->name (),
-		 TYPE_FIELD_NAME (index_desc_type, 0)) == 0)
+		 index_desc_type->field (0).name ()) == 0)
     return;
 
   /* Fixup each field of INDEX_DESC_TYPE.  */
   for (i = 0; i < index_desc_type->num_fields (); i++)
    {
-     const char *name = TYPE_FIELD_NAME (index_desc_type, i);
+     const char *name = index_desc_type->field (i).name ();
      struct type *raw_type = ada_check_typedef (ada_find_any_type (name));
 
      if (raw_type)
@@ -4633,16 +4633,16 @@ ada_identical_enum_types_p (struct type *type1, struct type *type2)
      suffix).  */
   for (i = 0; i < type1->num_fields (); i++)
     {
-      const char *name_1 = TYPE_FIELD_NAME (type1, i);
-      const char *name_2 = TYPE_FIELD_NAME (type2, i);
+      const char *name_1 = type1->field (i).name ();
+      const char *name_2 = type2->field (i).name ();
       int len_1 = strlen (name_1);
       int len_2 = strlen (name_2);
 
-      ada_remove_trailing_digits (TYPE_FIELD_NAME (type1, i), &len_1);
-      ada_remove_trailing_digits (TYPE_FIELD_NAME (type2, i), &len_2);
+      ada_remove_trailing_digits (type1->field (i).name (), &len_1);
+      ada_remove_trailing_digits (type2->field (i).name (), &len_2);
       if (len_1 != len_2
-	  || strncmp (TYPE_FIELD_NAME (type1, i),
-		      TYPE_FIELD_NAME (type2, i),
+	  || strncmp (type1->field (i).name (),
+		      type2->field (i).name (),
 		      len_1) != 0)
 	return 0;
     }
@@ -5961,7 +5961,7 @@ ada_is_ignored_field (struct type *type, int field_num)
 
   /* Check the name of that field.  */
   {
-    const char *name = TYPE_FIELD_NAME (type, field_num);
+    const char *name = type->field (field_num).name ();
 
     /* Anonymous field names should not be printed.
        brobecker/2007-02-20: I don't think this can actually happen
@@ -6320,7 +6320,7 @@ ada_parent_type (struct type *type)
 int
 ada_is_parent_field (struct type *type, int field_num)
 {
-  const char *name = TYPE_FIELD_NAME (ada_check_typedef (type), field_num);
+  const char *name = ada_check_typedef (type)->field (field_num).name ();
 
   return (name != NULL
 	  && (startswith (name, "PARENT")
@@ -6336,7 +6336,7 @@ ada_is_parent_field (struct type *type, int field_num)
 int
 ada_is_wrapper_field (struct type *type, int field_num)
 {
-  const char *name = TYPE_FIELD_NAME (type, field_num);
+  const char *name = type->field (field_num).name ();
 
   if (name != NULL && strcmp (name, "RETVAL") == 0)
     {
@@ -6395,7 +6395,7 @@ ada_variant_discrim_type (struct type *var_type, struct type *outer_type)
 static int
 ada_is_others_clause (struct type *type, int field_num)
 {
-  const char *name = TYPE_FIELD_NAME (type, field_num);
+  const char *name = type->field (field_num).name ();
 
   return (name != NULL && name[0] == 'O');
 }
@@ -6500,7 +6500,7 @@ ada_scan_number (const char str[], int k, LONGEST * R, int *new_k)
 static int
 ada_in_variant (LONGEST val, struct type *type, int field_num)
 {
-  const char *name = TYPE_FIELD_NAME (type, field_num);
+  const char *name = type->field (field_num).name ();
   int p;
 
   p = 0;
@@ -6660,7 +6660,7 @@ find_struct_field (const char *name, struct type *type, int offset,
     {
       int bit_pos = TYPE_FIELD_BITPOS (type, i);
       int fld_offset = offset + bit_pos / 8;
-      const char *t_field_name = TYPE_FIELD_NAME (type, i);
+      const char *t_field_name = type->field (i).name ();
 
       if (t_field_name == NULL)
 	continue;
@@ -6770,7 +6770,7 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
   type = ada_check_typedef (type);
   for (i = 0; i < type->num_fields (); i += 1)
     {
-      const char *t_field_name = TYPE_FIELD_NAME (type, i);
+      const char *t_field_name = type->field (i).name ();
 
       if (t_field_name == NULL)
 	continue;
@@ -6870,7 +6870,7 @@ ada_index_struct_field_1 (int *index_p, struct value *arg, int offset,
 
   for (i = 0; i < type->num_fields (); i += 1)
     {
-      if (TYPE_FIELD_NAME (type, i) == NULL)
+      if (type->field (i).name () == NULL)
 	continue;
       else if (ada_is_wrapper_field (type, i))
 	{
@@ -6963,7 +6963,7 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
 
   for (i = 0; i < type->num_fields (); i += 1)
     {
-      const char *t_field_name = TYPE_FIELD_NAME (type, i);
+      const char *t_field_name = type->field (i).name ();
       struct type *t;
 
       if (t_field_name == NULL)
@@ -7005,7 +7005,7 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
 		 NOT wrapped in a struct, since the compiler sometimes
 		 generates these for unchecked variant types.  Revisit
 		 if the compiler changes this practice.  */
-	      const char *v_field_name = TYPE_FIELD_NAME (field_type, j);
+	      const char *v_field_name = field_type->field (j).name ();
 
 	      if (v_field_name != NULL 
 		  && field_name_match (v_field_name, name))
@@ -7171,7 +7171,7 @@ ada_coerce_ref (struct value *val0)
 static unsigned int
 field_alignment (struct type *type, int f)
 {
-  const char *name = TYPE_FIELD_NAME (type, f);
+  const char *name = type->field (f).name ();
   int len;
   int align_offset;
 
@@ -7414,7 +7414,7 @@ dynamic_template_type (struct type *type)
 static int
 is_dynamic_field (struct type *templ_type, int field_num)
 {
-  const char *name = TYPE_FIELD_NAME (templ_type, field_num);
+  const char *name = templ_type->field (field_num).name ();
 
   return name != NULL
     && templ_type->field (field_num).type ()->code () == TYPE_CODE_PTR
@@ -7590,7 +7590,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
 	  ada_ensure_varsize_limit (field_type);
 
 	  rtype->field (f).set_type (field_type);
-	  rtype->field (f).set_name (TYPE_FIELD_NAME (type, f));
+	  rtype->field (f).set_name (type->field (f).name ());
 	  /* The multiplication can potentially overflow.  But because
 	     the field length has been size-checked just above, and
 	     assuming that the maximum size is a reasonable value,
@@ -7613,7 +7613,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
 	     to distinguish between the two options.  Stripping it
 	     would prevent us from printing this field appropriately.  */
 	  rtype->field (f).set_type (type->field (f).type ());
-	  rtype->field (f).set_name (TYPE_FIELD_NAME (type, f));
+	  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);
@@ -7791,7 +7791,7 @@ template_to_static_fixed_type (struct type *type0)
 	      TYPE_LENGTH (type) = 0;
 	    }
 	  type->field (f).set_type (new_type);
-	  type->field (f).set_name (TYPE_FIELD_NAME (type0, f));
+	  type->field (f).set_name (type0->field (f).name ());
 	}
     }
 
@@ -8680,7 +8680,7 @@ ada_is_aligner_type (struct type *type)
 
   return (type->code () == TYPE_CODE_STRUCT
 	  && type->num_fields () == 1
-	  && strcmp (TYPE_FIELD_NAME (type, 0), "F") == 0);
+	  && strcmp (type->field (0).name (), "F") == 0);
 }
 
 /* If there is an ___XVS-convention type parallel to SUBTYPE, return
@@ -8721,7 +8721,7 @@ ada_get_base_type (struct type *raw_type)
       /* This is an older encoding form where the base type needs to be
 	 looked up by name.  We prefer the newer encoding because it is
 	 more efficient.  */
-      raw_real_type = ada_find_any_type (TYPE_FIELD_NAME (real_type_namer, 0));
+      raw_real_type = ada_find_any_type (real_type_namer->field (0).name ());
       if (raw_real_type == NULL)
 	return raw_type;
       else
@@ -10218,7 +10218,7 @@ convert_char_literal (struct type *type, LONGEST val)
 	 have a name like "pkg__QUxx".  This is safe enough because we
 	 already have the correct type, and because mangling means
 	 there can't be clashes.  */
-      const char *ename = TYPE_FIELD_NAME (type, f);
+      const char *ename = type->field (f).name ();
       size_t elen = strlen (ename);
 
       if (elen >= len && strcmp (name, ename + elen - len) == 0)
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index 54bbe0f1a01..6bc8912422b 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -326,7 +326,7 @@ print_enum_type (struct type *type, struct ui_file *stream)
       if (i)
 	fprintf_filtered (stream, ", ");
       wrap_here ("    ");
-      fputs_styled (ada_enum_name (TYPE_FIELD_NAME (type, i)),
+      fputs_styled (ada_enum_name (type->field (i).name ()),
 		    variable_name_style.style (), stream);
       if (lastval != TYPE_FIELD_ENUMVAL (type, i))
 	{
@@ -439,7 +439,7 @@ print_choices (struct type *type, int field_num, struct ui_file *stream,
 {
   int have_output;
   int p;
-  const char *name = TYPE_FIELD_NAME (type, field_num);
+  const char *name = type->field (field_num).name ();
 
   have_output = 0;
 
@@ -620,7 +620,7 @@ print_selected_record_field_types (struct type *type, struct type *outer_type,
 	  flds += 1;
 	  fprintf_filtered (stream, "\n%*s", level + 4, "");
 	  ada_print_type (type->field (i).type (),
-			  TYPE_FIELD_NAME (type, i),
+			  type->field (i).name (),
 			  stream, show - 1, level + 4, flags);
 	  fprintf_filtered (stream, ";");
 	}
@@ -682,7 +682,7 @@ print_variant_part (const variant_part &part,
     name = "?";
   else
     {
-      name = TYPE_FIELD_NAME (type, part.discriminant_index);
+      name = type->field (part.discriminant_index).name ();;
       discr_type = type->field (part.discriminant_index).type ();
     }
 
@@ -851,7 +851,7 @@ print_unchecked_union_type (struct type *type, struct ui_file *stream,
 	  fprintf_filtered (stream, "\n%*swhen ? =>\n%*s", level + 8, "",
 			    level + 12, "");
 	  ada_print_type (type->field (i).type (),
-			  TYPE_FIELD_NAME (type, i),
+			  type->field (i).name (),
 			  stream, show - 1, level + 12, flags);
 	  fprintf_filtered (stream, ";");
 	}
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index d516a4d134e..979487f515e 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -388,7 +388,7 @@ ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
 	}
       if (i < len)
 	{
-	  fputs_styled (ada_enum_name (TYPE_FIELD_NAME (type, i)),
+	  fputs_styled (ada_enum_name (type->field (i).name ()),
 			variable_name_style.style (), stream);
 	}
       else
@@ -619,8 +619,8 @@ print_field_values (struct value *value, struct value *outer_value,
 
       annotate_field_begin (type->field (i).type ());
       fprintf_filtered (stream, "%.*s",
-			ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
-			TYPE_FIELD_NAME (type, i));
+			ada_name_prefix_len (type->field (i).name ()),
+			type->field (i).name ());
       annotate_field_name_end ();
       fputs_filtered (" => ", stream);
       annotate_field_value ();
@@ -841,7 +841,7 @@ ada_val_print_enum (struct value *value, struct ui_file *stream, int recurse,
 
   if (i < len)
     {
-      const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
+      const char *name = ada_enum_name (type->field (i).name ());
 
       if (name[0] == '\'')
 	fprintf_filtered (stream, "%ld %ps", (long) val,
diff --git a/gdb/ada-varobj.c b/gdb/ada-varobj.c
index 65bfec2def8..a4c29c5c5dd 100644
--- a/gdb/ada-varobj.c
+++ b/gdb/ada-varobj.c
@@ -502,7 +502,7 @@ ada_varobj_describe_struct_child (struct value *parent_value,
 		 name, except that we need to strip suffixes from it.
 		 For instance, fields with alignment constraints will
 		 have an __XVA suffix added to them.  */
-	      const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno);
+	      const char *field_name = parent_type->field (fieldno).name ();
 	      int child_name_len = ada_name_prefix_len (field_name);
 
 	      *child_name = string_printf ("%.*s", child_name_len, field_name);
@@ -522,7 +522,7 @@ ada_varobj_describe_struct_child (struct value *parent_value,
 		 name, except that we need to strip suffixes from it.
 		 For instance, fields with alignment constraints will
 		 have an __XVA suffix added to them.  */
-	      const char *field_name = TYPE_FIELD_NAME (parent_type, fieldno);
+	      const char *field_name = parent_type->field (fieldno).name ();
 	      int child_name_len = ada_name_prefix_len (field_name);
 
 	      *child_path_expr =
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 009c128c83c..07a69a3c46e 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -1337,7 +1337,7 @@ gen_struct_ref_recursive (struct agent_expr *ax, struct axs_value *value,
 
   for (i = type->num_fields () - 1; i >= nbases; i--)
     {
-      const char *this_name = TYPE_FIELD_NAME (type, i);
+      const char *this_name = type->field (i).name ();
 
       if (this_name)
 	{
@@ -1481,7 +1481,7 @@ gen_struct_elt_for_reference (struct agent_expr *ax, struct axs_value *value,
 
   for (i = t->num_fields () - 1; i >= TYPE_N_BASECLASSES (t); i--)
     {
-      const char *t_field_name = TYPE_FIELD_NAME (t, i);
+      const char *t_field_name = t->field (i).name ();
 
       if (t_field_name && strcmp (t_field_name, fieldname) == 0)
 	{
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 741541749b3..107d200bd55 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -1206,7 +1206,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
 	    }
 
 	  c_print_type_1 (type->field (i).type (),
-			  TYPE_FIELD_NAME (type, i),
+			  type->field (i).name (),
 			  stream, newshow, level + 4,
 			  language, &local_flags, &local_podata);
 
@@ -1602,7 +1602,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 	      if (i)
 		fprintf_filtered (stream, ", ");
 	      wrap_here ("    ");
-	      fputs_styled (TYPE_FIELD_NAME (type, i),
+	      fputs_styled (type->field (i).name (),
 			    variable_name_style.style (), stream);
 	      if (lastval != TYPE_FIELD_ENUMVAL (type, i))
 		{
@@ -1650,7 +1650,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 		/* We pass "show" here and not "show - 1" to get enum types
 		   printed.  There's no other way to see them.  */
 		c_print_type_1 (type->field (i).type (),
-				TYPE_FIELD_NAME (type, i),
+				type->field (i).name (),
 				stream, show, level + 4,
 				language, &local_flags, podata);
 		fprintf_filtered (stream, " @%s",
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index f6db3a5d1ba..a2901d1a861 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -165,7 +165,7 @@ c_is_path_expr_parent (const struct varobj *var)
 	      const char *field_name;
 
 	      gdb_assert (var->index < parent_type->num_fields ());
-	      field_name = TYPE_FIELD_NAME (parent_type, var->index);
+	      field_name = parent_type->field (var->index).name ();
 	      return !(field_name == NULL || *field_name == '\0');
 	    }
 	}
@@ -341,7 +341,7 @@ c_describe_child (const struct varobj *parent, int index,
 
 	/* If the type is anonymous and the field has no name,
 	   set an appropriate name.  */
-	field_name = TYPE_FIELD_NAME (type, index);
+	field_name = type->field (index).name ();
 	if (field_name == NULL || *field_name == '\0')
 	  {
 	    if (cname)
@@ -764,7 +764,7 @@ cplus_describe_child (const struct varobj *parent, int index,
 
 	  /* If the type is anonymous and the field has no name,
 	     set an appropriate name.  */
-	  field_name = TYPE_FIELD_NAME (type, type_index);
+	  field_name = type->field (type_index).name ();
 	  if (field_name == NULL || *field_name == '\0')
 	    {
 	      if (cname)
@@ -783,7 +783,7 @@ cplus_describe_child (const struct varobj *parent, int index,
 	  else
 	    {
 	      if (cname)
-		*cname = TYPE_FIELD_NAME (type, type_index);
+		*cname = type->field (type_index).name ();
 
 	      if (cfull_expression)
 		*cfull_expression
@@ -801,7 +801,7 @@ cplus_describe_child (const struct varobj *parent, int index,
 	{
 	  /* This is a baseclass.  */
 	  if (cname)
-	    *cname = TYPE_FIELD_NAME (type, index);
+	    *cname = type->field (index).name ();
 
 	  if (cvalue && value)
 	    *cvalue = value_cast (type->field (index).type (), value);
@@ -830,7 +830,7 @@ cplus_describe_child (const struct varobj *parent, int index,
 		 'class' keyword.  See PR mi/11912  */
 	      *cfull_expression = string_printf ("(%s(class %s%s) %s)",
 						 ptr,
-						 TYPE_FIELD_NAME (type, index),
+						 type->field (index).name (),
 						 ptr,
 						 parent_expression);
 	    }
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index eaeb83284d4..e9e5398b83a 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -112,7 +112,7 @@ convert_struct_or_union (compile_c_instance *context, struct type *type)
       if (bitsize == 0)
 	bitsize = 8 * TYPE_LENGTH (type->field (i).type ());
       context->plugin ().build_add_field (result,
-					  TYPE_FIELD_NAME (type, i),
+					  type->field (i).name (),
 					  field_type,
 					  bitsize,
 					  TYPE_FIELD_BITPOS (type, i));
@@ -137,7 +137,7 @@ convert_enum (compile_c_instance *context, struct type *type)
   for (i = 0; i < type->num_fields (); ++i)
     {
       context->plugin ().build_add_enum_constant
-	(result, TYPE_FIELD_NAME (type, i), TYPE_FIELD_ENUMVAL (type, i));
+	(result, type->field (i).name (), TYPE_FIELD_ENUMVAL (type, i));
     }
 
   context->plugin ().finish_enum_type (result);
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index 71ad6791e1d..8871de17f78 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -582,7 +582,7 @@ compile_cplus_convert_struct_or_union_members
 {
   for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); ++i)
     {
-      const char *field_name = TYPE_FIELD_NAME (type, i);
+      const char *field_name = type->field (i).name ();
 
       if (TYPE_FIELD_IGNORE (type, i)
 	  || TYPE_FIELD_ARTIFICIAL (type, i))
@@ -937,7 +937,7 @@ compile_cplus_convert_enum (compile_cplus_instance *instance, struct type *type,
   for (int i = 0; i < type->num_fields (); ++i)
     {
       gdb::unique_xmalloc_ptr<char> fname
-	= compile_cplus_instance::decl_name (TYPE_FIELD_NAME (type, i));
+	= compile_cplus_instance::decl_name (type->field (i).name ());
 
       if (TYPE_FIELD_LOC_KIND (type, i) != FIELD_LOC_KIND_ENUMVAL
 	  || fname == nullptr)
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index a25eb6142c7..f28bf26a240 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -552,7 +552,7 @@ store_regs (struct type *regs_type, CORE_ADDR regs_base)
 
   for (fieldno = 0; fieldno < regs_type->num_fields (); fieldno++)
     {
-      const char *reg_name = TYPE_FIELD_NAME (regs_type, fieldno);
+      const char *reg_name = regs_type->field (fieldno).name ();
       ULONGEST reg_bitpos = TYPE_FIELD_BITPOS (regs_type, fieldno);
       ULONGEST reg_bitsize = TYPE_FIELD_BITSIZE (regs_type, fieldno);
       ULONGEST reg_offset;
diff --git a/gdb/completer.c b/gdb/completer.c
index 40b976c8001..fb9e952ddc6 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1073,13 +1073,13 @@ add_struct_fields (struct type *type, completion_list &output,
       if (i < TYPE_N_BASECLASSES (type))
 	add_struct_fields (TYPE_BASECLASS (type, i),
 			   output, fieldname, namelen);
-      else if (TYPE_FIELD_NAME (type, i))
+      else if (type->field (i).name ())
 	{
-	  if (TYPE_FIELD_NAME (type, i)[0] != '\0')
+	  if (type->field (i).name ()[0] != '\0')
 	    {
-	      if (! strncmp (TYPE_FIELD_NAME (type, i), 
+	      if (! strncmp (type->field (i).name (), 
 			     fieldname, namelen))
-		output.emplace_back (xstrdup (TYPE_FIELD_NAME (type, i)));
+		output.emplace_back (xstrdup (type->field (i).name ()));
 	    }
 	  else if (type->field (i).type ()->code () == TYPE_CODE_UNION)
 	    {
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 7442ec0743e..f6969a5ab9d 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -231,12 +231,12 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
 	    {
 	      fputs_filtered ("static ", stream);
 	      fprintf_symbol_filtered (stream,
-				       TYPE_FIELD_NAME (type, i),
+				       type->field (i).name (),
 				       current_language->la_language,
 				       DMGL_PARAMS | DMGL_ANSI);
 	    }
 	  else
-	    fputs_styled (TYPE_FIELD_NAME (type, i),
+	    fputs_styled (type->field (i).name (),
 			  variable_name_style.style (), stream);
 	  annotate_field_name_end ();
 
@@ -246,7 +246,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
 
 	  /* Do not print leading '=' in case of anonymous
 	     unions.  */
-	  if (strcmp (TYPE_FIELD_NAME (type, i), ""))
+	  if (strcmp (type->field (i).name (), ""))
 	    fputs_filtered (" = ", stream);
 	  else
 	    {
@@ -710,7 +710,7 @@ cp_print_class_member (const gdb_byte *valaddr, struct type *type,
       else
 	c_type_print_base (self_type, stream, 0, 0, &type_print_raw_options);
       fprintf_filtered (stream, "::");
-      fputs_styled (TYPE_FIELD_NAME (self_type, fieldno),
+      fputs_styled (self_type->field (fieldno).name (),
 		    variable_name_style.style (), stream);
     }
   else
diff --git a/gdb/d-valprint.c b/gdb/d-valprint.c
index 9bd976c9998..d46d51b4cd6 100644
--- a/gdb/d-valprint.c
+++ b/gdb/d-valprint.c
@@ -36,8 +36,8 @@ dynamic_array_type (struct type *type,
 {
   if (type->num_fields () == 2
       && type->field (0).type ()->code () == TYPE_CODE_INT
-      && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
-      && strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0
+      && strcmp (type->field (0).name (), "length") == 0
+      && strcmp (type->field (1).name (), "ptr") == 0
       && !value_bits_any_optimized_out (val,
 					TARGET_CHAR_BIT * embedded_offset,
 					TARGET_CHAR_BIT * TYPE_LENGTH (type)))
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 786017de914..c7a856f9457 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9019,9 +9019,9 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 
 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
   if (type->num_fields () == 1
-      && startswith (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX))
+      && startswith (type->field (0).name (), RUST_ENUM_PREFIX))
     {
-      const char *name = TYPE_FIELD_NAME (type, 0) + strlen (RUST_ENUM_PREFIX);
+      const char *name = type->field (0).name () + strlen (RUST_ENUM_PREFIX);
 
       /* Decode the field name to find the offset of the
 	 discriminant.  */
@@ -9039,7 +9039,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 	    {
 	      complaint (_("Could not parse Rust enum encoding string \"%s\""
 			   "[in module %s]"),
-			 TYPE_FIELD_NAME (type, 0),
+			 type->field (0).name (),
 			 objfile_name (objfile));
 	      return;
 	    }
@@ -9071,7 +9071,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 	(rust_last_path_segment (type->field (1).type ()->name ()));
       type->field (1).type ()->set_name
 	(rust_fully_qualify (&objfile->objfile_obstack, type->name (),
-			     TYPE_FIELD_NAME (type, 1)));
+			     type->field (1).name ()));
 
       const char *dataless_name
 	= rust_fully_qualify (&objfile->objfile_obstack, type->name (),
@@ -9090,7 +9090,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
     }
   /* A union with a single anonymous field is probably an old-style
      univariant enum.  */
-  else if (type->num_fields () == 1 && streq (TYPE_FIELD_NAME (type, 0), ""))
+  else if (type->num_fields () == 1 && streq (type->field (0).name (), ""))
     {
       /* Smash this type to be a structure type.  We have to do this
 	 because the type has already been recorded.  */
@@ -9123,7 +9123,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 	      /* Could be data-less variant, so keep going.  */
 	      disr_type = nullptr;
 	    }
-	  else if (strcmp (TYPE_FIELD_NAME (disr_type, 0),
+	  else if (strcmp (disr_type->field (0).name (),
 			   "RUST$ENUM$DISR") != 0)
 	    {
 	      /* Not a Rust enum.  */
@@ -9169,7 +9169,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 	  if (TYPE_FIELD_LOC_KIND (enum_type, i) == FIELD_LOC_KIND_ENUMVAL)
 	    {
 	      const char *name
-		= rust_last_path_segment (TYPE_FIELD_NAME (enum_type, i));
+		= rust_last_path_segment (enum_type->field (i).name ());
 	      discriminant_map[name] = TYPE_FIELD_ENUMVAL (enum_type, i);
 	    }
 	}
@@ -15284,10 +15284,10 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
     return;
 
   /* Check for __pfn and __delta members.  */
-  if (TYPE_FIELD_NAME (type, 0) == NULL
-      || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
-      || TYPE_FIELD_NAME (type, 1) == NULL
-      || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
+  if (type->field (0).name () == NULL
+      || strcmp (type->field (0).name (), "__pfn") != 0
+      || type->field (1).name () == NULL
+      || strcmp (type->field (1).name (), "__delta") != 0)
     return;
 
   /* Find the type of the method.  */
@@ -15378,10 +15378,10 @@ quirk_ada_thick_pointer_struct (struct die_info *die, struct dwarf2_cu *cu,
     return;
 
   /* Check for P_ARRAY and P_BOUNDS members.  */
-  if (TYPE_FIELD_NAME (type, 0) == NULL
-      || strcmp (TYPE_FIELD_NAME (type, 0), "P_ARRAY") != 0
-      || TYPE_FIELD_NAME (type, 1) == NULL
-      || strcmp (TYPE_FIELD_NAME (type, 1), "P_BOUNDS") != 0)
+  if (type->field (0).name () == NULL
+      || strcmp (type->field (0).name (), "P_ARRAY") != 0
+      || type->field (1).name () == NULL
+      || strcmp (type->field (1).name (), "P_BOUNDS") != 0)
     return;
 
   /* Make sure we're looking at a pointer to an array.  */
@@ -15894,7 +15894,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
 		       i >= TYPE_N_BASECLASSES (t);
 		       --i)
 		    {
-		      const char *fieldname = TYPE_FIELD_NAME (t, i);
+		      const char *fieldname = t->field (i).name ();
 
 		      if (is_vtable_name (fieldname, cu))
 			{
@@ -15927,7 +15927,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
 		   i >= TYPE_N_BASECLASSES (type);
 		   --i)
 		{
-		  if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
+		  if (strcmp (type->field (i).name (), "__vfp") == 0)
 		    {
 		      set_type_vptr_fieldno (type, i);
 		      set_type_vptr_basetype (type, type);
diff --git a/gdb/eval.c b/gdb/eval.c
index 5c348c34e66..0dfaa2393a7 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2300,7 +2300,7 @@ array_operation::evaluate_struct_tuple (struct value *struct_val,
 	error (_("too many initializers"));
       field_type = struct_type->field (fieldno).type ();
       if (field_type->code () == TYPE_CODE_UNION
-	  && TYPE_FIELD_NAME (struct_type, fieldno)[0] == '0')
+	  && struct_type->field (fieldno).name ()[0] == '0')
 	error (_("don't know which variant you want to set"));
 
       /* Here, struct_type is the type of the inner struct,
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index 976fc387b5f..1791cb29451 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -406,7 +406,7 @@ f_language::f_type_print_base (struct type *type, struct ui_file *stream,
 	      f_type_print_base (type->field (index).type (), stream,
 				 show - 1, level + 4);
 	      fputs_filtered (" :: ", stream);
-	      fputs_styled (TYPE_FIELD_NAME (type, index),
+	      fputs_styled (type->field (index).name (),
 			    variable_name_style.style (), stream);
 	      f_type_print_varspec_suffix (type->field (index).type (),
 					   stream, show - 1, 0, 0, 0, false);
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 240daaf34f9..27d9a730978 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -312,7 +312,7 @@ f_language::value_print_inner (struct value *val, struct ui_file *stream,
 	      if (printed_field > 0)
 		fputs_filtered (", ", stream);
 
-	      field_name = TYPE_FIELD_NAME (type, index);
+	      field_name = type->field (index).name ();
 	      if (field_name != NULL)
 		{
 		  fputs_styled (field_name, variable_name_style.style (),
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index a64ed12c1bb..a38c3b5d0cf 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1846,7 +1846,7 @@ lookup_struct_elt (struct type *type, const char *name, int noerr)
 
   for (i = type->num_fields () - 1; i >= TYPE_N_BASECLASSES (type); i--)
     {
-      const char *t_field_name = TYPE_FIELD_NAME (type, i);
+      const char *t_field_name = type->field (i).name ();
 
       if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
 	{
@@ -4206,8 +4206,7 @@ check_types_equal (struct type *type1, struct type *type2,
 	      || FIELD_BITSIZE (*field1) != FIELD_BITSIZE (*field2)
 	      || FIELD_LOC_KIND (*field1) != FIELD_LOC_KIND (*field2))
 	    return false;
-	  if (!compare_maybe_null_strings (FIELD_NAME (*field1),
-					   FIELD_NAME (*field2)))
+	  if (!compare_maybe_null_strings (field1->name (), field2->name ()))
 	    return false;
 	  switch (FIELD_LOC_KIND (*field1))
 	    {
@@ -5346,10 +5345,10 @@ recursive_dump_type (struct type *type, int spaces)
 			 TYPE_FIELD_BITSIZE (type, idx));
       gdb_print_host_address (type->field (idx).type (), gdb_stdout);
       printf_filtered (" name '%s' (",
-		       TYPE_FIELD_NAME (type, idx) != NULL
-		       ? TYPE_FIELD_NAME (type, idx)
+		       type->field (idx).name () != NULL
+		       ? type->field (idx).name ()
 		       : "<NULL>");
-      gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
+      gdb_print_host_address (type->field (idx).name (), gdb_stdout);
       printf_filtered (")\n");
       if (type->field (idx).type () != NULL)
 	{
@@ -5558,8 +5557,8 @@ copy_type_recursive (struct objfile *objfile,
 	    new_type->field (i).set_type
 	      (copy_type_recursive (objfile, type->field (i).type (),
 				    copied_types));
-	  if (TYPE_FIELD_NAME (type, i))
-	    new_type->field (i).set_name (xstrdup (TYPE_FIELD_NAME (type, i)));
+	  if (type->field (i).name ())
+	    new_type->field (i).set_name (xstrdup (type->field (i).name ()));
 	  switch (TYPE_FIELD_LOC_KIND (type, i))
 	    {
 	    case FIELD_LOC_KIND_BITPOS:
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 949a932935b..eb3b7c67d4a 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1968,7 +1968,7 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
 #define TYPE_TAIL_CALL_LIST(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->tail_call_list
 #define TYPE_BASECLASS(thistype,index) ((thistype)->field (index).type ())
 #define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
-#define TYPE_BASECLASS_NAME(thistype,index) TYPE_FIELD_NAME(thistype, index)
+#define TYPE_BASECLASS_NAME(thistype,index) (thistype->field (index).name ())
 #define TYPE_BASECLASS_BITPOS(thistype,index) TYPE_FIELD_BITPOS(thistype,index)
 #define BASETYPE_VIA_PUBLIC(thistype, index) \
   ((!TYPE_FIELD_PRIVATE(thistype, index)) && (!TYPE_FIELD_PROTECTED(thistype, index)))
@@ -1978,7 +1978,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 FIELD_NAME(thisfld) ((thisfld).name ())
 #define FIELD_LOC_KIND(thisfld) ((thisfld).loc_kind)
 #define FIELD_BITPOS_LVAL(thisfld) ((thisfld).loc.bitpos)
 #define FIELD_BITPOS(thisfld) (FIELD_BITPOS_LVAL (thisfld) + 0)
@@ -2005,7 +2004,6 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
 #define FIELD_ARTIFICIAL(thisfld) ((thisfld).artificial)
 #define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
 
-#define TYPE_FIELD_NAME(thistype, n) ((thistype)->field (n).name ())
 #define TYPE_FIELD_LOC_KIND(thistype, n) FIELD_LOC_KIND ((thistype)->field (n))
 #define TYPE_FIELD_BITPOS(thistype, n) FIELD_BITPOS ((thistype)->field (n))
 #define TYPE_FIELD_ENUMVAL(thistype, n) FIELD_ENUMVAL ((thistype)->field (n))
diff --git a/gdb/gnu-v2-abi.c b/gdb/gnu-v2-abi.c
index 466ae6c0802..c0200b273cd 100644
--- a/gdb/gnu-v2-abi.c
+++ b/gdb/gnu-v2-abi.c
@@ -294,7 +294,7 @@ static int
 vb_match (struct type *type, int index, struct type *basetype)
 {
   struct type *fieldtype;
-  const char *name = TYPE_FIELD_NAME (type, index);
+  const char *name = type->field (index).name ();
   const char *field_class_name = NULL;
 
   if (*name != '_')
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 2a4fb1a35b0..72c5d8884d9 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -82,9 +82,9 @@ gccgo_string_p (struct type *type)
       type1 = check_typedef (type1);
 
       if (type0->code () == TYPE_CODE_PTR
-	  && strcmp (TYPE_FIELD_NAME (type, 0), "__data") == 0
+	  && strcmp (type->field (0).name (), "__data") == 0
 	  && type1->code () == TYPE_CODE_INT
-	  && strcmp (TYPE_FIELD_NAME (type, 1), "__length") == 0)
+	  && strcmp (type->field (1).name (), "__length") == 0)
 	{
 	  struct type *target_type = TYPE_TARGET_TYPE (type0);
 
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index d65102b01c7..04d3d754900 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -999,7 +999,7 @@ gdbscm_type_field (SCM self, SCM field_scm)
 
     for (int i = 0; i < type->num_fields (); i++)
       {
-	const char *t_field_name = TYPE_FIELD_NAME (type, i);
+	const char *t_field_name = type->field (i).name ();
 
 	if (t_field_name && (strcmp_iw (t_field_name, field.get ()) == 0))
 	  {
@@ -1041,7 +1041,7 @@ gdbscm_type_has_field_p (SCM self, SCM field_scm)
 
     for (int i = 0; i < type->num_fields (); i++)
       {
-	const char *t_field_name = TYPE_FIELD_NAME (type, i);
+	const char *t_field_name = type->field (i).name ();
 
 	if (t_field_name && (strcmp_iw (t_field_name, field.get ()) == 0))
 	  return SCM_BOOL_T;
@@ -1131,8 +1131,8 @@ gdbscm_field_name (SCM self)
     = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   struct field *field = tyscm_field_smob_to_field (f_smob);
 
-  if (FIELD_NAME (*field))
-    return gdbscm_scm_from_c_string (FIELD_NAME (*field));
+  if (field->name () != nullptr)
+    return gdbscm_scm_from_c_string (field->name ());
   return SCM_BOOL_F;
 }
 
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index e2ffc7187b8..8209686980f 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -353,8 +353,8 @@ m2_is_long_set (struct type *type)
 	    return 0;
 	  if (type->field (i).type ()->code () != TYPE_CODE_SET)
 	    return 0;
-	  if (TYPE_FIELD_NAME (type, i) != NULL
-	      && (strcmp (TYPE_FIELD_NAME (type, i), "") != 0))
+	  if (type->field (i).name () != NULL
+	      && (strcmp (type->field (i).name (), "") != 0))
 	    return 0;
 	  range = type->field (i).type ()->index_type ();
 	  if ((i > TYPE_N_BASECLASSES (type))
@@ -492,9 +492,9 @@ m2_is_unbounded_array (struct type *type)
        */
       if (type->num_fields () != 2)
 	return 0;
-      if (strcmp (TYPE_FIELD_NAME (type, 0), "_m2_contents") != 0)
+      if (strcmp (type->field (0).name (), "_m2_contents") != 0)
 	return 0;
-      if (strcmp (TYPE_FIELD_NAME (type, 1), "_m2_high") != 0)
+      if (strcmp (type->field (1).name (), "_m2_high") != 0)
 	return 0;
       if (type->field (0).type ()->code () != TYPE_CODE_PTR)
 	return 0;
@@ -563,7 +563,7 @@ m2_record_fields (struct type *type, struct ui_file *stream, int show,
 	  QUIT;
 
 	  print_spaces_filtered (level + 4, stream);
-	  fputs_styled (TYPE_FIELD_NAME (type, i),
+	  fputs_styled (type->field (i).name (),
 			variable_name_style.style (), stream);
 	  fputs_filtered (" : ", stream);
 	  m2_print_type (type->field (i).type (),
@@ -609,7 +609,7 @@ m2_enum (struct type *type, struct ui_file *stream, int show, int level)
 	  if (i > 0)
 	    fprintf_filtered (stream, ", ");
 	  wrap_here ("    ");
-	  fputs_styled (TYPE_FIELD_NAME (type, i),
+	  fputs_styled (type->field (i).name (),
 			variable_name_style.style (), stream);
 	  if (lastval != TYPE_FIELD_ENUMVAL (type, i))
 	    {
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 3dcc75a4c83..cac8fbeaeb0 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -96,10 +96,10 @@ pascal_is_string_type (struct type *type,int *length_pos, int *length_size,
       /* Old Borland type pascal strings from Free Pascal Compiler.  */
       /* Two fields: length and st.  */
       if (type->num_fields () == 2
-	  && TYPE_FIELD_NAME (type, 0)
-	  && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
-	  && TYPE_FIELD_NAME (type, 1)
-	  && strcmp (TYPE_FIELD_NAME (type, 1), "st") == 0)
+	  && type->field (0).name ()
+	  && strcmp (type->field (0).name (), "length") == 0
+	  && type->field (1).name ()
+	  && strcmp (type->field (1).name (), "st") == 0)
 	{
 	  if (length_pos)
 	    *length_pos = TYPE_FIELD_BITPOS (type, 0) / TARGET_CHAR_BIT;
@@ -110,16 +110,16 @@ pascal_is_string_type (struct type *type,int *length_pos, int *length_size,
 	  if (char_type)
 	    *char_type = TYPE_TARGET_TYPE (type->field (1).type ());
 	  if (arrayname)
-	    *arrayname = TYPE_FIELD_NAME (type, 1);
+	    *arrayname = type->field (1).name ();
 	 return 2;
 	};
       /* GNU pascal strings.  */
       /* Three fields: Capacity, length and schema$ or _p_schema.  */
       if (type->num_fields () == 3
-	  && TYPE_FIELD_NAME (type, 0)
-	  && strcmp (TYPE_FIELD_NAME (type, 0), "Capacity") == 0
-	  && TYPE_FIELD_NAME (type, 1)
-	  && strcmp (TYPE_FIELD_NAME (type, 1), "length") == 0)
+	  && type->field (0).name ()
+	  && strcmp (type->field (0).name (), "Capacity") == 0
+	  && type->field (1).name ()
+	  && strcmp (type->field (1).name (), "length") == 0)
 	{
 	  if (length_pos)
 	    *length_pos = TYPE_FIELD_BITPOS (type, 1) / TARGET_CHAR_BIT;
@@ -136,7 +136,7 @@ pascal_is_string_type (struct type *type,int *length_pos, int *length_size,
 		*char_type = TYPE_TARGET_TYPE (*char_type);
 	    }
 	  if (arrayname)
-	    *arrayname = TYPE_FIELD_NAME (type, 2);
+	    *arrayname = type->field (2).name ();
 	 return 3;
 	};
     }
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index 21306ada148..48bfba8b0d0 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -523,8 +523,8 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
 	    {
 	      QUIT;
 	      /* Don't print out virtual function table.  */
-	      if ((startswith (TYPE_FIELD_NAME (type, i), "_vptr"))
-		  && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
+	      if ((startswith (type->field (i).name (), "_vptr"))
+		  && is_cplus_marker ((type->field (i).name ())[5]))
 		continue;
 
 	      /* If this is a pascal object or class we can print the
@@ -565,7 +565,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
 	      if (field_is_static (&type->field (i)))
 		fprintf_filtered (stream, "static ");
 	      print_type (type->field (i).type (),
-				 TYPE_FIELD_NAME (type, i),
+				 type->field (i).name (),
 				 stream, show - 1, level + 4, flags);
 	      if (!field_is_static (&type->field (i))
 		  && TYPE_FIELD_PACKED (type, i))
@@ -710,7 +710,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
 	      if (i)
 		fprintf_filtered (stream, ", ");
 	      wrap_here ("    ");
-	      fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
+	      fputs_filtered (type->field (i).name (), stream);
 	      if (lastval != TYPE_FIELD_ENUMVAL (type, i))
 		{
 		  fprintf_filtered (stream,
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index 9a52fe14ba8..44be49848b2 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -583,12 +583,12 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
 	    {
 	      fputs_filtered ("static ", stream);
 	      fprintf_symbol_filtered (stream,
-				       TYPE_FIELD_NAME (type, i),
+				       type->field (i).name (),
 				       current_language->la_language,
 				       DMGL_PARAMS | DMGL_ANSI);
 	    }
 	  else
-	    fputs_styled (TYPE_FIELD_NAME (type, i),
+	    fputs_styled (type->field (i).name (),
 			  variable_name_style.style (), stream);
 	  annotate_field_name_end ();
 	  fputs_filtered (" = ", stream);
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 04d1c7a0ee7..7c46309b0a1 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -204,13 +204,13 @@ convert_field (struct type *type, int field)
     }
 
   arg.reset (NULL);
-  if (TYPE_FIELD_NAME (type, field))
+  if (type->field (field).name ())
     {
-      const char *field_name = TYPE_FIELD_NAME (type, field);
+      const char *field_name = type->field (field).name ();
 
       if (field_name[0] != '\0')
 	{
-	  arg.reset (PyString_FromString (TYPE_FIELD_NAME (type, field)));
+	  arg.reset (PyString_FromString (type->field (field).name ()));
 	  if (arg == NULL)
 	    return NULL;
 	}
@@ -261,8 +261,8 @@ field_name (struct type *type, int field)
 {
   gdbpy_ref<> result;
 
-  if (TYPE_FIELD_NAME (type, field))
-    result.reset (PyString_FromString (TYPE_FIELD_NAME (type, field)));
+  if (type->field (field).name ())
+    result.reset (PyString_FromString (type->field (field).name ()));
   else
     result = gdbpy_ref<>::new_reference (Py_None);
 
@@ -1205,7 +1205,7 @@ typy_getitem (PyObject *self, PyObject *key)
 
   for (i = 0; i < type->num_fields (); i++)
     {
-      const char *t_field_name = TYPE_FIELD_NAME (type, i);
+      const char *t_field_name = type->field (i).name ();
 
       if (t_field_name && (strcmp_iw (t_field_name, field.get ()) == 0))
 	return convert_field (type, i).release ();
@@ -1263,7 +1263,7 @@ typy_has_key (PyObject *self, PyObject *args)
 
   for (i = 0; i < type->num_fields (); i++)
     {
-      const char *t_field_name = TYPE_FIELD_NAME (type, i);
+      const char *t_field_name = type->field (i).name ();
 
       if (t_field_name && (strcmp_iw (t_field_name, field) == 0))
 	Py_RETURN_TRUE;
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f3e346e4db5..79284bedb2b 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -135,7 +135,7 @@ rust_underscore_fields (struct type *type)
 	  char buf[20];
 
 	  xsnprintf (buf, sizeof (buf), "__%d", field_number);
-	  if (strcmp (buf, TYPE_FIELD_NAME (type, i)) != 0)
+	  if (strcmp (buf, type->field (i).name ()) != 0)
 	    return false;
 	  field_number++;
 	}
@@ -182,7 +182,7 @@ rust_range_type_p (struct type *type)
     return true;
 
   i = 0;
-  if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
+  if (strcmp (type->field (0).name (), "start") == 0)
     {
       if (type->num_fields () == 1)
 	return true;
@@ -194,7 +194,7 @@ rust_range_type_p (struct type *type)
       return false;
     }
 
-  return strcmp (TYPE_FIELD_NAME (type, i), "end") == 0;
+  return strcmp (type->field (i).name (), "end") == 0;
 }
 
 /* Return true if TYPE is an inclusive range type, otherwise false.
@@ -244,9 +244,9 @@ rust_get_trait_object_pointer (struct value *value)
   int vtable_field = 0;
   for (int i = 0; i < 2; ++i)
     {
-      if (strcmp (TYPE_FIELD_NAME (type, i), "vtable") == 0)
+      if (strcmp (type->field (i).name (), "vtable") == 0)
 	vtable_field = i;
-      else if (strcmp (TYPE_FIELD_NAME (type, i), "pointer") != 0)
+      else if (strcmp (type->field (i).name (), "pointer") != 0)
 	return NULL;
     }
 
@@ -381,7 +381,7 @@ rust_language::val_print_struct
 
       if (!is_tuple && !is_tuple_struct)
 	{
-	  fputs_styled (TYPE_FIELD_NAME (type, i),
+	  fputs_styled (type->field (i).name (),
 			variable_name_style.style (), stream);
 	  fputs_filtered (": ", stream);
 	}
@@ -463,7 +463,7 @@ rust_language::print_enum (struct value *val, struct ui_file *stream,
       if (!is_tuple)
 	fprintf_filtered (stream, "%ps: ",
 			  styled_string (variable_name_style.style (),
-					 TYPE_FIELD_NAME (variant_type, j)));
+					 variant_type->field (j).name ()));
 
       common_val_print (value_field (val, j), stream, recurse + 1, &opts,
 			this);
@@ -708,12 +708,12 @@ rust_print_struct_def (struct type *type, const char *varstring,
       if (!for_rust_enum || flags->print_offsets)
 	print_spaces_filtered (level + 2, stream);
       if (is_enum)
-	fputs_styled (TYPE_FIELD_NAME (type, i), variable_name_style.style (),
+	fputs_styled (type->field (i).name (), variable_name_style.style (),
 		      stream);
       else if (!is_tuple_struct)
 	fprintf_filtered (stream, "%ps: ",
 			  styled_string (variable_name_style.style (),
-					 TYPE_FIELD_NAME (type, i)));
+					 type->field (i).name ()));
 
       rust_internal_print_type (type->field (i).type (), NULL,
 				stream, (is_enum ? show : show - 1),
@@ -840,7 +840,7 @@ rust_internal_print_type (struct type *type, const char *varstring,
 
 	for (int i = 0; i < type->num_fields (); ++i)
 	  {
-	    const char *name = TYPE_FIELD_NAME (type, i);
+	    const char *name = type->field (i).name ();
 
 	    QUIT;
 
@@ -1071,14 +1071,14 @@ rust_compute_range (struct type *type, struct value *range,
     return;
 
   i = 0;
-  if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
+  if (strcmp (type->field (0).name (), "start") == 0)
     {
       *kind = RANGE_HIGH_BOUND_DEFAULT;
       *low = value_as_long (value_field (range, 0));
       ++i;
     }
   if (type->num_fields () > i
-      && strcmp (TYPE_FIELD_NAME (type, i), "end") == 0)
+      && strcmp (type->field (i).name (), "end") == 0)
     {
       *kind = (*kind == (RANGE_LOW_BOUND_DEFAULT | RANGE_HIGH_BOUND_DEFAULT)
 	       ? RANGE_LOW_BOUND_DEFAULT : RANGE_STANDARD);
@@ -1125,7 +1125,7 @@ rust_subscript (struct type *expect_type, struct expression *exp,
 	{
 	  for (int i = 0; i < type->num_fields (); ++i)
 	    {
-	      if (strcmp (TYPE_FIELD_NAME (type, i), "data_ptr") == 0)
+	      if (strcmp (type->field (i).name (), "data_ptr") == 0)
 		{
 		  base_type = TYPE_TARGET_TYPE (type->field (i).type ());
 		  break;
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 765fec4b23a..f63b3720c75 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -3195,7 +3195,7 @@ read_tilde_fields (struct stab_field_info *fip, const char **pp,
 		   i >= TYPE_N_BASECLASSES (t);
 		   --i)
 		{
-		  const char *name = TYPE_FIELD_NAME (t, i);
+		  const char *name = t->field (i).name ();
 
 		  if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
 		      && is_cplus_marker (name[sizeof (vptr_name) - 2]))
diff --git a/gdb/symtab.c b/gdb/symtab.c
index fa3f42207ec..e41655ecdfc 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1973,7 +1973,7 @@ check_field (struct type *type, const char *name,
 
   for (i = type->num_fields () - 1; i >= TYPE_N_BASECLASSES (type); i--)
     {
-      const char *t_field_name = TYPE_FIELD_NAME (type, i);
+      const char *t_field_name = type->field (i).name ();
 
       if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
 	{
@@ -5609,9 +5609,9 @@ completion_list_add_fields (completion_tracker &tracker,
 
       if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
 	for (j = TYPE_N_BASECLASSES (t); j < t->num_fields (); j++)
-	  if (TYPE_FIELD_NAME (t, j))
+	  if (t->field (j).name ())
 	    completion_list_add_name (tracker, sym->language (),
-				      TYPE_FIELD_NAME (t, j),
+				      t->field (j).name (),
 				      lookup_name, text, word);
     }
 }
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 0776f634215..6cc12359917 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -627,7 +627,7 @@ print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
 	}
       if (i < len)
 	{
-	  fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
+	  fputs_filtered (type->field (i).name (), stream);
 	}
       else
 	{
diff --git a/gdb/valops.c b/gdb/valops.c
index 50874a5f55d..9be38710819 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1993,7 +1993,7 @@ struct_field_searcher::search (struct value *arg1, LONGEST offset,
   if (!m_looking_for_baseclass)
     for (i = type->num_fields () - 1; i >= nbases; i--)
       {
-	const char *t_field_name = TYPE_FIELD_NAME (type, i);
+	const char *t_field_name = type->field (i).name ();
 
 	if (t_field_name && (strcmp_iw (t_field_name, m_name) == 0))
 	  {
@@ -3338,7 +3338,7 @@ enum_constant_from_type (struct type *type, const char *name)
 
   for (i = TYPE_N_BASECLASSES (type); i < type->num_fields (); ++i)
     {
-      const char *fname = TYPE_FIELD_NAME (type, i);
+      const char *fname = type->field (i).name ();
       int len;
 
       if (TYPE_FIELD_LOC_KIND (type, i) != FIELD_LOC_KIND_ENUMVAL
@@ -3510,7 +3510,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
 
   for (i = t->num_fields () - 1; i >= TYPE_N_BASECLASSES (t); i--)
     {
-      const char *t_field_name = TYPE_FIELD_NAME (t, i);
+      const char *t_field_name = t->field (i).name ();
 
       if (t_field_name && strcmp (t_field_name, name) == 0)
 	{
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 324055da93f..c6ea0d82e40 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -615,7 +615,7 @@ generic_val_print_enum_1 (struct type *type, LONGEST val,
     }
   if (i < len)
     {
-      fputs_styled (TYPE_FIELD_NAME (type, i), variable_name_style.style (),
+      fputs_styled (type->field (i).name (), variable_name_style.style (),
 		    stream);
     }
   else if (type->is_flag_enum ())
@@ -646,7 +646,7 @@ generic_val_print_enum_1 (struct type *type, LONGEST val,
 		fputs_filtered (" | ", stream);
 
 	      val &= ~TYPE_FIELD_ENUMVAL (type, i);
-	      fputs_styled (TYPE_FIELD_NAME (type, i),
+	      fputs_styled (type->field (i).name (),
 			    variable_name_style.style (), stream);
 	    }
 	}
@@ -1203,7 +1203,7 @@ val_print_type_code_flags (struct type *type, struct value *original_value,
   fputs_filtered ("[", stream);
   for (field = 0; field < nfields; field++)
     {
-      if (TYPE_FIELD_NAME (type, field)[0] != '\0')
+      if (type->field (field).name ()[0] != '\0')
 	{
 	  struct type *field_type = type->field (field).type ();
 
@@ -1218,7 +1218,7 @@ val_print_type_code_flags (struct type *type, struct value *original_value,
 		fprintf_filtered
 		  (stream, " %ps",
 		   styled_string (variable_name_style.style (),
-				  TYPE_FIELD_NAME (type, field)));
+				  type->field (field).name ()));
 	    }
 	  else
 	    {
@@ -1229,7 +1229,7 @@ val_print_type_code_flags (struct type *type, struct value *original_value,
 		field_val &= ((ULONGEST) 1 << field_len) - 1;
 	      fprintf_filtered (stream, " %ps=",
 				styled_string (variable_name_style.style (),
-					       TYPE_FIELD_NAME (type, field)));
+					       type->field (field).name ()));
 	      if (field_type->code () == TYPE_CODE_ENUM)
 		generic_val_print_enum_1 (field_type, field_val, stream);
 	      else
diff --git a/gdb/value.c b/gdb/value.c
index 2cbaadc3641..14cf1d0a9f5 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2934,7 +2934,7 @@ value_static_field (struct type *type, int fieldno)
     case FIELD_LOC_KIND_PHYSNAME:
     {
       const char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, fieldno);
-      /* TYPE_FIELD_NAME (type, fieldno); */
+      /* type->field (fieldno).name (); */
       struct block_symbol sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0);
 
       if (sym.symbol == NULL)
-- 
2.33.0


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

* Re: [PATCH 1/2] gdb: add field::name / field::set_name
  2021-08-30 15:49 [PATCH 1/2] gdb: add field::name / field::set_name Simon Marchi
  2021-08-30 15:49 ` [PATCH 2/2] gdb: remove TYPE_FIELD_NAME and FIELD_NAME macros Simon Marchi
@ 2021-10-01  2:13 ` Simon Marchi
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2021-10-01  2:13 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches



On 2021-08-30 11:49, Simon Marchi wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
> 
> Add the `name` and `set_name` methods on `struct field`, in order to
> remove `FIELD_NAME` and `TYPE_FIELD_NAME` macros.  In this patch, the
> macros are changed to use `field::name`, so all the call sites that are
> used to set the field's name are changed to use `field::set_name`.
> The next patch will remove the macros completely.
> 
> Note that because of the name clash between the existing field named
> `name` and the new method, I renamed the field `m_name`.  It is not
> private per-se, because we can't make `struct field` a non-POD yet, but
> it should be considered private anyway (not accessed outside `struct
> field`).
> 
> Change-Id: If16ddbca4e0c39d0ff9da420bb5cdebe5b9b0896

I pushed these two patches.

Simon

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

end of thread, other threads:[~2021-10-01  2:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-30 15:49 [PATCH 1/2] gdb: add field::name / field::set_name Simon Marchi
2021-08-30 15:49 ` [PATCH 2/2] gdb: remove TYPE_FIELD_NAME and FIELD_NAME macros Simon Marchi
2021-10-01  2:13 ` [PATCH 1/2] gdb: add field::name / field::set_name 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).