gdb: add accessors for field (and call site) location

Add accessors for the various location values in struct field.  This
lets us assert that when we get a location value of a certain kind (say,
bitpos), the field's location indeed contains a value of that kind.

Remove the SET_FIELD_* macros, instead use the new setters directly.
Update the FIELD_* macros used to access field locations to go through
the getters.  They will be removed in a subsequent patch.

There are places where the FIELD_* macros are used on call_site_target
structures, because it contains members of the same name (loc_kind and
loc).  For now, I have replicated the getters/setters in
call_site_target.  But we could perhaps eventually factor them in a
"location" structure that can be used at both places.

Note that the field structure, being zero-initialized, defaults to a
bitpos location with value 0.  While writing this patch, I tried to make
it default to an "unset" location, to catch places where we would miss
setting a field's location.  However, I found that some places relied on
the default being "bitpos 0", so I left it as-is.  This change could
always be done as follow-up work, making these places explicitly set the
"bitpos 0" location.

I found two issues to fix:

 - I got some failures in the gdb.base/infcall-nested-structs-c++.exp
   test.  They were caused by two functions in amd64-tdep.c using
   TYPE_FIELD_BITPOS before checking if the location is of the bitpos
   kind, which they do indirectly through `field_is_static`.  Simply
   move getting the bitpos below the field_is_static call.

 - I got a failure in gdb.xml/tdesc-regs.exp.  It turns out that in
   make_gdb_type_enum, we set enum field values using SET_FIELD_BITPOS,
   and later access them through FIELD_ENUMVAL.  Fix that by using
   set_loc_enumval to set the value.

Change-Id: I53d3734916c46457576ba11dd77df4049d2fc1e8
This commit is contained in:
Simon Marchi 2021-09-30 22:38:29 -04:00 committed by Simon Marchi
parent 8baf3d0756
commit cd3f655cc7
14 changed files with 189 additions and 105 deletions

View file

@ -2599,8 +2599,8 @@ resolve_dynamic_struct (struct type *type,
CORE_ADDR addr;
if (dwarf2_evaluate_property (&prop, nullptr, addr_stack, &addr,
true))
SET_FIELD_BITPOS (resolved_type->field (i),
TARGET_CHAR_BIT * (addr - addr_stack->addr));
resolved_type->field (i).set_loc_bitpos
(TARGET_CHAR_BIT * (addr - addr_stack->addr));
}
/* As we know this field is not a static field, the field's
@ -5561,25 +5561,22 @@ copy_type_recursive (struct objfile *objfile,
switch (TYPE_FIELD_LOC_KIND (type, i))
{
case FIELD_LOC_KIND_BITPOS:
SET_FIELD_BITPOS (new_type->field (i),
TYPE_FIELD_BITPOS (type, i));
new_type->field (i).set_loc_bitpos (TYPE_FIELD_BITPOS (type, i));
break;
case FIELD_LOC_KIND_ENUMVAL:
SET_FIELD_ENUMVAL (new_type->field (i),
TYPE_FIELD_ENUMVAL (type, i));
new_type->field (i).set_loc_enumval (TYPE_FIELD_ENUMVAL (type, i));
break;
case FIELD_LOC_KIND_PHYSADDR:
SET_FIELD_PHYSADDR (new_type->field (i),
TYPE_FIELD_STATIC_PHYSADDR (type, i));
new_type->field (i).set_loc_physaddr
(TYPE_FIELD_STATIC_PHYSADDR (type, i));
break;
case FIELD_LOC_KIND_PHYSNAME:
SET_FIELD_PHYSNAME (new_type->field (i),
xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
i)));
new_type->field (i).set_loc_physname
(xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type, i)));
break;
case FIELD_LOC_KIND_DWARF_BLOCK:
SET_FIELD_DWARF_BLOCK (new_type->field (i),
TYPE_FIELD_DWARF_BLOCK (type, i));
new_type->field (i).set_loc_dwarf_block
(TYPE_FIELD_DWARF_BLOCK (type, i));
break;
default:
internal_error (__FILE__, __LINE__,
@ -5846,7 +5843,7 @@ append_flags_type_field (struct type *type, int start_bitpos, int nr_bits,
type->field (field_nr).set_name (xstrdup (name));
type->field (field_nr).set_type (field_type);
SET_FIELD_BITPOS (type->field (field_nr), start_bitpos);
type->field (field_nr).set_loc_bitpos (start_bitpos);
TYPE_FIELD_BITSIZE (type, field_nr) = nr_bits;
type->set_num_fields (type->num_fields () + 1);
}
@ -5918,10 +5915,8 @@ append_composite_type_field_aligned (struct type *t, const char *name,
TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
if (t->num_fields () > 1)
{
SET_FIELD_BITPOS (f[0],
(FIELD_BITPOS (f[-1])
+ (TYPE_LENGTH (f[-1].type ())
* TARGET_CHAR_BIT)));
f->set_loc_bitpos
((FIELD_BITPOS (f[-1]) + (TYPE_LENGTH (f[-1].type ()) * TARGET_CHAR_BIT)));
if (alignment)
{
@ -5932,7 +5927,7 @@ append_composite_type_field_aligned (struct type *t, const char *name,
if (left)
{
SET_FIELD_BITPOS (f[0], FIELD_BITPOS (f[0]) + (alignment - left));
f->set_loc_bitpos (FIELD_BITPOS (f[0]) + (alignment - left));
TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT;
}
}