aboutsummaryrefslogtreecommitdiff
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/amd64-tdep.c
parentRISC-V: Support aliases for Zbs instructions (diff)
downloadbinutils-gdb-cd3f655cc7a55437a05aa8e7b1fcc9051b5fe404.tar.gz
binutils-gdb-cd3f655cc7a55437a05aa8e7b1fcc9051b5fe404.tar.bz2
binutils-gdb-cd3f655cc7a55437a05aa8e7b1fcc9051b5fe404.zip
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/amd64-tdep.c')
-rw-r--r--gdb/amd64-tdep.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 129f07e598d..47761208088 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -553,7 +553,6 @@ amd64_has_unaligned_fields (struct type *type)
for (int i = 0; i < type->num_fields (); i++)
{
struct type *subtype = check_typedef (type->field (i).type ());
- int bitpos = TYPE_FIELD_BITPOS (type, i);
/* Ignore static fields, empty fields (for example nested
empty structures), and bitfields (these are handled by
@@ -564,6 +563,8 @@ amd64_has_unaligned_fields (struct type *type)
|| TYPE_FIELD_PACKED (type, i))
continue;
+ int bitpos = TYPE_FIELD_BITPOS (type, i);
+
if (bitpos % 8 != 0)
return true;
@@ -592,21 +593,21 @@ amd64_classify_aggregate_field (struct type *type, int i,
unsigned int bitoffset)
{
struct type *subtype = check_typedef (type->field (i).type ());
- int bitpos = bitoffset + TYPE_FIELD_BITPOS (type, i);
- int pos = bitpos / 64;
enum amd64_reg_class subclass[2];
int bitsize = TYPE_FIELD_BITSIZE (type, i);
- int endpos;
if (bitsize == 0)
bitsize = TYPE_LENGTH (subtype) * 8;
- endpos = (bitpos + bitsize - 1) / 64;
/* Ignore static fields, or empty fields, for example nested
empty structures.*/
if (field_is_static (&type->field (i)) || bitsize == 0)
return;
+ int bitpos = bitoffset + TYPE_FIELD_BITPOS (type, i);
+ int pos = bitpos / 64;
+ int endpos = (bitpos + bitsize - 1) / 64;
+
if (subtype->code () == TYPE_CODE_STRUCT
|| subtype->code () == TYPE_CODE_UNION)
{