aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2/read.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-09-30 22:38:29 -0400
committerSimon Marchi <simon.marchi@efficios.com>2021-10-07 11:03:54 -0400
commitcd3f655cc7a55437a05aa8e7b1fcc9051b5fe404 (patch)
tree6ac5ac49884488ff6e8856d8d1ae7964a47866fe /gdb/dwarf2/read.c
parent8baf3d07567f886be683aa26e3fc92346b604a93 (diff)
downloadgdb-cd3f655cc7a55437a05aa8e7b1fcc9051b5fe404.zip
gdb-cd3f655cc7a55437a05aa8e7b1fcc9051b5fe404.tar.gz
gdb-cd3f655cc7a55437a05aa8e7b1fcc9051b5fe404.tar.bz2
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
Diffstat (limited to 'gdb/dwarf2/read.c')
-rw-r--r--gdb/dwarf2/read.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 5d48e4c..cbd9a30 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9093,7 +9093,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
type->field (0).set_type (field_type);
TYPE_FIELD_ARTIFICIAL (type, 0) = 1;
type->field (0).set_name ("<<discriminant>>");
- SET_FIELD_BITPOS (type->field (0), bit_offset);
+ type->field (0).set_loc_bitpos (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. */
@@ -9113,7 +9113,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
/* NAME points into the original discriminant name, which
already has the correct lifetime. */
type->field (2).set_name (name);
- SET_FIELD_BITPOS (type->field (2), 0);
+ type->field (2).set_loc_bitpos (0);
/* Indicate that this is a variant type. */
static discriminant_range ranges[1] = { { 0, 0 } };
@@ -13469,7 +13469,8 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
/* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
}
- SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
+
+ call_site->target.set_loc_dwarf_block (nullptr);
if (!attr || (attr->form_is_block () && attr->as_block ()->size == 0))
/* Keep NULL DWARF_BLOCK. */;
else if (attr->form_is_block ())
@@ -13483,7 +13484,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
dlbaton->per_objfile = per_objfile;
dlbaton->per_cu = cu->per_cu;
- SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
+ call_site->target.set_loc_dwarf_block (dlbaton);
}
else if (attr->form_is_ref ())
{
@@ -13505,7 +13506,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
"physname, for referencing DIE %s [in module %s]"),
sect_offset_str (die->sect_off), objfile_name (objfile));
else
- SET_FIELD_PHYSNAME (call_site->target, target_physname);
+ call_site->target.set_loc_physname (target_physname);
}
else
{
@@ -13521,7 +13522,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
{
lowpc = (gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr)
- baseaddr);
- SET_FIELD_PHYSADDR (call_site->target, lowpc);
+ call_site->target.set_loc_physaddr (lowpc);
}
}
}
@@ -14483,7 +14484,7 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu,
if (attr->form_is_constant ())
{
LONGEST offset = attr->constant_value (0);
- SET_FIELD_BITPOS (*field, offset * bits_per_byte);
+ field->set_loc_bitpos (offset * bits_per_byte);
}
else if (attr->form_is_section_offset ())
dwarf2_complex_location_expr_complaint ();
@@ -14492,7 +14493,7 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu,
bool handled;
CORE_ADDR offset = decode_locdesc (attr->as_block (), cu, &handled);
if (handled)
- SET_FIELD_BITPOS (*field, offset * bits_per_byte);
+ field->set_loc_bitpos (offset * bits_per_byte);
else
{
dwarf2_per_objfile *per_objfile = cu->per_objfile;
@@ -14509,7 +14510,7 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu,
dlbaton->per_objfile = per_objfile;
dlbaton->per_cu = cu->per_cu;
- SET_FIELD_DWARF_BLOCK (*field, dlbaton);
+ field->set_loc_dwarf_block (dlbaton);
}
}
else
@@ -14519,7 +14520,7 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu,
{
attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
if (attr != nullptr)
- SET_FIELD_BITPOS (*field, attr->constant_value (0));
+ field->set_loc_bitpos (attr->constant_value (0));
}
}
@@ -14568,7 +14569,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
/* Get type of field. */
fp->set_type (die_type (die, cu));
- SET_FIELD_BITPOS (*fp, 0);
+ fp->set_loc_bitpos (0);
/* Get bit size of field (zero if none). */
attr = dwarf2_attr (die, DW_AT_bit_size, cu);
@@ -14593,8 +14594,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
anonymous object to the MSB of the field. We don't
have to do anything special since we don't need to
know the size of the anonymous object. */
- SET_FIELD_BITPOS (*fp, (FIELD_BITPOS (*fp)
- + attr->constant_value (0)));
+ fp->set_loc_bitpos ((FIELD_BITPOS (*fp) + attr->constant_value (0)));
}
else
{
@@ -14623,10 +14623,9 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
bit field. */
anonymous_size = TYPE_LENGTH (fp->type ());
}
- SET_FIELD_BITPOS (*fp,
- (FIELD_BITPOS (*fp)
- + anonymous_size * bits_per_byte
- - bit_offset - FIELD_BITSIZE (*fp)));
+ fp->set_loc_bitpos (FIELD_BITPOS (*fp)
+ + anonymous_size * bits_per_byte
+ - bit_offset - FIELD_BITSIZE (*fp));
}
}
@@ -14682,7 +14681,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. */
- SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
+ fp->set_loc_physname (physname ? physname : "");
fp->set_type (die_type (die, cu));
fp->set_name (fieldname);
}
@@ -16142,7 +16141,7 @@ update_enumeration_type_from_children (struct die_info *die,
fields.emplace_back ();
struct field &field = fields.back ();
field.set_name (dwarf2_physname (name, child_die, cu));
- SET_FIELD_ENUMVAL (field, value);
+ field.set_loc_enumval (value);
}
if (!fields.empty ())
@@ -16416,7 +16415,7 @@ recognize_bound_expression (struct die_info *die, enum dwarf_attribute name,
else
return false;
- SET_FIELD_BITPOS (*field, 8 * offset);
+ field->set_loc_bitpos (8 * offset);
if (size != TYPE_LENGTH (field->type ()))
FIELD_BITSIZE (*field) = 8 * size;
@@ -16564,7 +16563,7 @@ quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
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);
+ result->field (1).set_loc_bitpos (8 * bounds_offset);
result->set_name (type->name ());
TYPE_LENGTH (result) = (TYPE_LENGTH (result->field (0).type ())