aboutsummaryrefslogtreecommitdiff
path: root/gdb/gnu-v3-abi.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2020-04-24 13:40:31 -0600
committerTom Tromey <tromey@adacore.com>2020-04-24 13:40:32 -0600
commit7d79de9a4be2d1abb0320c322967f1aad39b1f7d (patch)
treefa576d23c30849b3b5eeda590d1ce1b8094ac791 /gdb/gnu-v3-abi.c
parentf8e89861cfb6acbfa097814f5864afd5563a3011 (diff)
downloadgdb-7d79de9a4be2d1abb0320c322967f1aad39b1f7d.zip
gdb-7d79de9a4be2d1abb0320c322967f1aad39b1f7d.tar.gz
gdb-7d79de9a4be2d1abb0320c322967f1aad39b1f7d.tar.bz2
Add support for variable field offsets
In Ada, a field can have a variable offset. This patch adds support for this case to gdb, using the existing dynamic type resolution code. Doing just this, though, would break C++ virtual base handling. It turns out that virtual base handling only worked by the ugliest of hacks. In particular, the DWARF reader would call decode_locdesc for a virtual base location. Here's an example of such an expression from gdb's m-static test case: <241> DW_AT_data_member_location: 6 byte block: 12 6 48 1c 6 22 (DW_OP_dup; DW_OP_deref; DW_OP_lit24; DW_OP_minus; DW_OP_deref; DW_OP_plus) When examining this, decode_locdesc would treat DW_OP_deref as a no-op and compute some answer (here, -24). This would be stored as the offset. Later, in gnu-v3-abi.c, the real offset would be computed by digging around in the vtable. This patch cleans up this area. In particular, it now evaluates the location expression on demand. Note there is a new FIXME in gnu-v3-abi.c. I think some of the callers are incorrect here, and have only worked because this member is unused. I will file a bug for this. I didn't fix this problem in this series because I felt it was already too complex. gdb/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (handle_data_member_location): New overload. (dwarf2_add_field): Use it. (decode_locdesc): Add "computed" parameter. Update comment. * gdbtypes.c (is_dynamic_type_internal): Also look for FIELD_LOC_KIND_DWARF_BLOCK. (resolve_dynamic_struct): Handle FIELD_LOC_KIND_DWARF_BLOCK. * gdbtypes.c (is_dynamic_type_internal): Add special case for C++ virtual base classes. * gnu-v3-abi.c (gnuv3_baseclass_offset): Handle FIELD_LOC_KIND_DWARF_BLOCK. gdb/testsuite/ChangeLog 2020-04-24 Tom Tromey <tromey@adacore.com> * gdb.ada/variant.exp: Add dynamic field offset tests. * gdb.ada/variant/pck.ads (Nested_And_Variable): New type. * gdb.ada/variant/pkg.adb: Add new variables.
Diffstat (limited to 'gdb/gnu-v3-abi.c')
-rw-r--r--gdb/gnu-v3-abi.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 89574ec..7055843 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -30,6 +30,7 @@
#include "typeprint.h"
#include <algorithm>
#include "cli/cli-style.h"
+#include "dwarf2/loc.h"
static struct cp_abi_ops gnu_v3_abi_ops;
@@ -461,6 +462,31 @@ gnuv3_baseclass_offset (struct type *type, int index,
if (!BASETYPE_VIA_VIRTUAL (type, index))
return TYPE_BASECLASS_BITPOS (type, index) / 8;
+ /* If we have a DWARF expression for the offset, evaluate it. */
+ if (TYPE_FIELD_LOC_KIND (type, index) == FIELD_LOC_KIND_DWARF_BLOCK)
+ {
+ struct dwarf2_property_baton baton;
+ baton.property_type
+ = lookup_pointer_type (TYPE_FIELD_TYPE (type, index));
+ baton.locexpr = *TYPE_FIELD_DWARF_BLOCK (type, index);
+
+ struct dynamic_prop prop;
+ prop.kind = PROP_LOCEXPR;
+ prop.data.baton = &baton;
+
+ struct property_addr_info addr_stack;
+ addr_stack.type = type;
+ /* Note that we don't set "valaddr" here. Doing so causes
+ regressions. FIXME. */
+ addr_stack.addr = address + embedded_offset;
+ addr_stack.next = nullptr;
+
+ CORE_ADDR result;
+ if (dwarf2_evaluate_property (&prop, nullptr, &addr_stack, &result,
+ true))
+ return (int) (result - addr_stack.addr);
+ }
+
/* To access a virtual base, we need to use the vbase offset stored in
our vtable. Recent GCC versions provide this information. If it isn't
available, we could get what we needed from RTTI, or from drawing the