gdb: add field::name / field::set_name

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
This commit is contained in:
Simon Marchi 2021-08-30 11:49:48 -04:00
parent cdfbeec413
commit d3fd12dfc5
11 changed files with 71 additions and 59 deletions

View File

@ -7601,7 +7601,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,
@ -7624,7 +7624,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);
@ -7686,7 +7686,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;
@ -7802,7 +7802,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));
}
}
@ -7871,7 +7871,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);
}

View File

@ -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;

View File

@ -399,7 +399,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);
@ -438,7 +438,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;

View File

@ -9092,14 +9092,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)));
@ -9112,7 +9112,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. */
@ -9130,7 +9130,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));
@ -9189,7 +9189,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. */
@ -9239,7 +9239,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));
@ -14637,7 +14637,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. */
@ -14684,7 +14684,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)
{
@ -14692,7 +14692,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
handle_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");
@ -16141,7 +16141,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);
}
@ -16515,9 +16515,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);
@ -16559,10 +16559,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);

View File

@ -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:
@ -5846,7 +5846,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;
@ -5897,7 +5897,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;
}

View File

@ -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
@ -1974,7 +1984,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)
@ -2001,7 +2011,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))

View File

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

View File

@ -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,

View File

@ -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;
}

View File

@ -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;
}

View File

@ -761,7 +761,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);
}