Make tdesc_arch_data::arch_regs an std::vector

Make tdesc_arch_data::arch_regs be an std::vector of tdesc_arch_reg
objects.

On particularity is that the tdesc_arch_data linked to a gdbarch is
allocated on the gdbarch's obstack.  To be safe, I did not change it and
called placement-new on the area returned by OBSTACK_ZALLOC.

gdb/ChangeLog:

	* target-descriptions.c (tdesc_arch_reg): Remove typedef.
	(struct tdesc_arch_reg): Add constructor.
	(DEF_VEC_O (tdesc_arch_reg)): Remove.
	(struct tdesc_arch_data): Initialize fields.
	<arch_regs>: Change type to std::vector.
	(target_find_description): Adjust.
	(tdesc_find_type): Adjust.
	(tdesc_data_init): Call tdesc_arch_data constructor.
	(tdesc_data_alloc): Allocate tdesc_arch_data with new.
	(tdesc_data_cleanup): Free data with delete.
	(tdesc_numbered_register): Adjust.
	(tdesc_find_arch_register): Adjust.
	(tdesc_use_registers): Adjust.
This commit is contained in:
Simon Marchi
2017-12-05 16:30:27 -05:00
committed by Simon Marchi
parent d05200d155
commit f0cddbef41
2 changed files with 54 additions and 42 deletions

View File

@ -1,3 +1,19 @@
2017-12-05 Simon Marchi <simon.marchi@polymtl.ca>
* target-descriptions.c (tdesc_arch_reg): Remove typedef.
(struct tdesc_arch_reg): Add constructor.
(DEF_VEC_O (tdesc_arch_reg)): Remove.
(struct tdesc_arch_data): Initialize fields.
<arch_regs>: Change type to std::vector.
(target_find_description): Adjust.
(tdesc_find_type): Adjust.
(tdesc_data_init): Call tdesc_arch_data constructor.
(tdesc_data_alloc): Allocate tdesc_arch_data with new.
(tdesc_data_cleanup): Free data with delete.
(tdesc_numbered_register): Adjust.
(tdesc_find_arch_register): Adjust.
(tdesc_use_registers): Adjust.
2017-12-05 Simon Marchi <simon.marchi@polymtl.ca> 2017-12-05 Simon Marchi <simon.marchi@polymtl.ca>
* target-descriptions.c (tdesc_type_field): Remove typedef. * target-descriptions.c (tdesc_type_field): Remove typedef.

View File

@ -424,12 +424,15 @@ struct target_desc : tdesc_element
target description may be shared by multiple architectures, but target description may be shared by multiple architectures, but
this data is private to one gdbarch. */ this data is private to one gdbarch. */
typedef struct tdesc_arch_reg struct tdesc_arch_reg
{ {
tdesc_arch_reg (tdesc_reg *reg_, struct type *type_)
: reg (reg_), type (type_)
{}
struct tdesc_reg *reg; struct tdesc_reg *reg;
struct type *type; struct type *type;
} tdesc_arch_reg; };
DEF_VEC_O(tdesc_arch_reg);
struct tdesc_arch_data struct tdesc_arch_data
{ {
@ -439,13 +442,13 @@ struct tdesc_arch_data
Registers which are NULL in this array, or off the end, are Registers which are NULL in this array, or off the end, are
treated as zero-sized and nameless (i.e. placeholders in the treated as zero-sized and nameless (i.e. placeholders in the
numbering). */ numbering). */
VEC(tdesc_arch_reg) *arch_regs; std::vector<tdesc_arch_reg> arch_regs;
/* Functions which report the register name, type, and reggroups for /* Functions which report the register name, type, and reggroups for
pseudo-registers. */ pseudo-registers. */
gdbarch_register_name_ftype *pseudo_register_name; gdbarch_register_name_ftype *pseudo_register_name = NULL;
gdbarch_register_type_ftype *pseudo_register_type; gdbarch_register_type_ftype *pseudo_register_type = NULL;
gdbarch_register_reggroup_p_ftype *pseudo_register_reggroup_p; gdbarch_register_reggroup_p_ftype *pseudo_register_reggroup_p = NULL;
}; };
/* Info about an inferior's target description. There's one of these /* Info about an inferior's target description. There's one of these
@ -586,7 +589,7 @@ target_find_description (void)
data = ((struct tdesc_arch_data *) data = ((struct tdesc_arch_data *)
gdbarch_data (target_gdbarch (), tdesc_data)); gdbarch_data (target_gdbarch (), tdesc_data));
if (tdesc_has_registers (current_target_desc) if (tdesc_has_registers (current_target_desc)
&& data->arch_regs == NULL) && data->arch_regs.empty ())
warning (_("Target-supplied registers are not supported " warning (_("Target-supplied registers are not supported "
"by the current architecture")); "by the current architecture"));
} }
@ -778,20 +781,16 @@ tdesc_named_type (const struct tdesc_feature *feature, const char *id)
struct type * struct type *
tdesc_find_type (struct gdbarch *gdbarch, const char *id) tdesc_find_type (struct gdbarch *gdbarch, const char *id)
{ {
struct tdesc_arch_reg *reg; tdesc_arch_data *data
struct tdesc_arch_data *data; = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
int i, num_regs;
data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data); for (const tdesc_arch_reg &reg : data->arch_regs)
num_regs = VEC_length (tdesc_arch_reg, data->arch_regs);
for (i = 0; i < num_regs; i++)
{ {
reg = VEC_index (tdesc_arch_reg, data->arch_regs, i); if (reg.reg
if (reg->reg && reg.reg->tdesc_type
&& reg->reg->tdesc_type && reg.type
&& reg->type && reg.reg->tdesc_type->name == id)
&& reg->reg->tdesc_type->name == id) return reg.type;
return reg->type;
} }
return NULL; return NULL;
@ -1019,6 +1018,8 @@ tdesc_data_init (struct obstack *obstack)
struct tdesc_arch_data *data; struct tdesc_arch_data *data;
data = OBSTACK_ZALLOC (obstack, struct tdesc_arch_data); data = OBSTACK_ZALLOC (obstack, struct tdesc_arch_data);
new (data) tdesc_arch_data ();
return data; return data;
} }
@ -1028,7 +1029,7 @@ tdesc_data_init (struct obstack *obstack)
struct tdesc_arch_data * struct tdesc_arch_data *
tdesc_data_alloc (void) tdesc_data_alloc (void)
{ {
return XCNEW (struct tdesc_arch_data); return new tdesc_arch_data ();
} }
/* Free something allocated by tdesc_data_alloc, if it is not going /* Free something allocated by tdesc_data_alloc, if it is not going
@ -1040,8 +1041,7 @@ tdesc_data_cleanup (void *data_untyped)
{ {
struct tdesc_arch_data *data = (struct tdesc_arch_data *) data_untyped; struct tdesc_arch_data *data = (struct tdesc_arch_data *) data_untyped;
VEC_free (tdesc_arch_reg, data->arch_regs); delete data;
xfree (data);
} }
/* Search FEATURE for a register named NAME. */ /* Search FEATURE for a register named NAME. */
@ -1064,18 +1064,17 @@ tdesc_numbered_register (const struct tdesc_feature *feature,
struct tdesc_arch_data *data, struct tdesc_arch_data *data,
int regno, const char *name) int regno, const char *name)
{ {
struct tdesc_arch_reg arch_reg = { 0 };
struct tdesc_reg *reg = tdesc_find_register_early (feature, name); struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
if (reg == NULL) if (reg == NULL)
return 0; return 0;
/* Make sure the vector includes a REGNO'th element. */ /* Make sure the vector includes a REGNO'th element. */
while (regno >= VEC_length (tdesc_arch_reg, data->arch_regs)) while (regno >= data->arch_regs.size ())
VEC_safe_push (tdesc_arch_reg, data->arch_regs, &arch_reg); data->arch_regs.emplace_back (nullptr, nullptr);
data->arch_regs[regno] = tdesc_arch_reg (reg, NULL);
arch_reg.reg = reg;
VEC_replace (tdesc_arch_reg, data->arch_regs, regno, &arch_reg);
return 1; return 1;
} }
@ -1132,8 +1131,8 @@ tdesc_find_arch_register (struct gdbarch *gdbarch, int regno)
struct tdesc_arch_data *data; struct tdesc_arch_data *data;
data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data); data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
if (regno < VEC_length (tdesc_arch_reg, data->arch_regs)) if (regno < data->arch_regs.size ())
return VEC_index (tdesc_arch_reg, data->arch_regs, regno); return &data->arch_regs[regno];
else else
return NULL; return NULL;
} }
@ -1378,7 +1377,6 @@ tdesc_use_registers (struct gdbarch *gdbarch,
{ {
int num_regs = gdbarch_num_regs (gdbarch); int num_regs = gdbarch_num_regs (gdbarch);
struct tdesc_arch_data *data; struct tdesc_arch_data *data;
struct tdesc_arch_reg *arch_reg, new_arch_reg = { 0 };
htab_t reg_hash; htab_t reg_hash;
/* We can't use the description for registers if it doesn't describe /* We can't use the description for registers if it doesn't describe
@ -1389,7 +1387,7 @@ tdesc_use_registers (struct gdbarch *gdbarch,
data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data); data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
data->arch_regs = early_data->arch_regs; data->arch_regs = early_data->arch_regs;
xfree (early_data); delete early_data;
/* Build up a set of all registers, so that we can assign register /* Build up a set of all registers, so that we can assign register
numbers where needed. The hash table expands as necessary, so numbers where needed. The hash table expands as necessary, so
@ -1405,26 +1403,24 @@ tdesc_use_registers (struct gdbarch *gdbarch,
/* Remove any registers which were assigned numbers by the /* Remove any registers which were assigned numbers by the
architecture. */ architecture. */
for (int ixr = 0; for (const tdesc_arch_reg &arch_reg : data->arch_regs)
VEC_iterate (tdesc_arch_reg, data->arch_regs, ixr, arch_reg); if (arch_reg.reg != NULL)
ixr++) htab_remove_elt (reg_hash, arch_reg.reg);
if (arch_reg->reg)
htab_remove_elt (reg_hash, arch_reg->reg);
/* Assign numbers to the remaining registers and add them to the /* Assign numbers to the remaining registers and add them to the
list of registers. The new numbers are always above gdbarch_num_regs. list of registers. The new numbers are always above gdbarch_num_regs.
Iterate over the features, not the hash table, so that the order Iterate over the features, not the hash table, so that the order
matches that in the target description. */ matches that in the target description. */
gdb_assert (VEC_length (tdesc_arch_reg, data->arch_regs) <= num_regs); gdb_assert (data->arch_regs.size () <= num_regs);
while (VEC_length (tdesc_arch_reg, data->arch_regs) < num_regs) while (data->arch_regs.size () < num_regs)
VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg); data->arch_regs.emplace_back (nullptr, nullptr);
for (const tdesc_feature_up &feature : target_desc->features) for (const tdesc_feature_up &feature : target_desc->features)
for (const tdesc_reg_up &reg : feature->registers) for (const tdesc_reg_up &reg : feature->registers)
if (htab_find (reg_hash, reg.get ()) != NULL) if (htab_find (reg_hash, reg.get ()) != NULL)
{ {
new_arch_reg.reg = reg.get (); data->arch_regs.emplace_back (reg.get (), nullptr);
VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
num_regs++; num_regs++;
} }