static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
-static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
+static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *,
+ bool * = nullptr);
static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
struct dwarf2_cu *);
return 0;
}
+/* Look for DW_AT_data_member_location and store the results in FIELD. */
+
+static void
+handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
+ struct field *field)
+{
+ struct attribute *attr;
+
+ attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
+ if (attr != NULL)
+ {
+ if (attr->form_is_constant ())
+ {
+ LONGEST offset = attr->constant_value (0);
+ SET_FIELD_BITPOS (*field, offset * bits_per_byte);
+ }
+ else if (attr->form_is_section_offset ())
+ dwarf2_complex_location_expr_complaint ();
+ else if (attr->form_is_block ())
+ {
+ bool handled;
+ CORE_ADDR offset = decode_locdesc (DW_BLOCK (attr), cu, &handled);
+ if (handled)
+ SET_FIELD_BITPOS (*field, offset * bits_per_byte);
+ else
+ {
+ struct objfile *objfile
+ = cu->per_cu->dwarf2_per_objfile->objfile;
+ struct dwarf2_locexpr_baton *dlbaton
+ = XOBNEW (&objfile->objfile_obstack,
+ struct dwarf2_locexpr_baton);
+ dlbaton->data = DW_BLOCK (attr)->data;
+ dlbaton->size = DW_BLOCK (attr)->size;
+ /* When using this baton, we want to compute the address
+ of the field, not the value. This is why
+ is_reference is set to false here. */
+ dlbaton->is_reference = false;
+ dlbaton->per_cu = cu->per_cu;
+
+ SET_FIELD_DWARF_BLOCK (*field, dlbaton);
+ }
+ }
+ else
+ dwarf2_complex_location_expr_complaint ();
+ }
+}
+
/* Add an aggregate field to the field list. */
static void
if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
{
- LONGEST offset;
-
/* Data member other than a C++ static data member. */
/* Get type of field. */
}
/* Get bit offset of field. */
- if (handle_data_member_location (die, cu, &offset))
- SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
+ handle_data_member_location (die, cu, fp);
attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
if (attr != nullptr)
{
}
else if (die->tag == DW_TAG_inheritance)
{
- LONGEST offset;
-
/* C++ base class field. */
- if (handle_data_member_location (die, cu, &offset))
- SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
+ handle_data_member_location (die, cu, fp);
FIELD_BITSIZE (*fp) = 0;
FIELD_TYPE (*fp) = die_type (die, cu);
FIELD_NAME (*fp) = TYPE_NAME (fp->type);
/* Decode simple location descriptions.
Given a pointer to a dwarf block that defines a location, compute
- the location and return the value.
-
- NOTE drow/2003-11-18: This function is called in two situations
- now: for the address of static or global variables (partial symbols
- only) and for offsets into structures which are expected to be
- (more or less) constant. The partial symbol case should go away,
- and only the constant case should remain. That will let this
- function complain more accurately. A few special modes are allowed
- without complaint for global variables (for instance, global
- register values and thread-local values).
-
- A location description containing no operations indicates that the
- object is optimized out. The return value is 0 for that case.
- FIXME drow/2003-11-16: No callers check for this case any more; soon all
- callers will only want a very basic result and this can become a
- complaint.
-
- Note that stack[0] is unused except as a default error return. */
+ the location and return the value. If COMPUTED is non-null, it is
+ set to true to indicate that decoding was successful, and false
+ otherwise. If COMPUTED is null, then this function may emit a
+ complaint. */
static CORE_ADDR
-decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
+decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu, bool *computed)
{
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
size_t i;
unsigned int bytes_read, unsnd;
gdb_byte op;
+ if (computed != nullptr)
+ *computed = false;
+
i = 0;
stacki = 0;
stack[stacki] = 0;
case DW_OP_reg31:
stack[++stacki] = op - DW_OP_reg0;
if (i < size)
- dwarf2_complex_location_expr_complaint ();
+ {
+ if (computed == nullptr)
+ dwarf2_complex_location_expr_complaint ();
+ else
+ return 0;
+ }
break;
case DW_OP_regx:
i += bytes_read;
stack[++stacki] = unsnd;
if (i < size)
- dwarf2_complex_location_expr_complaint ();
+ {
+ if (computed == nullptr)
+ dwarf2_complex_location_expr_complaint ();
+ else
+ return 0;
+ }
break;
case DW_OP_addr:
global symbols, although the variable's address will be bogus
in the psymtab. */
if (i < size)
- dwarf2_complex_location_expr_complaint ();
+ {
+ if (computed == nullptr)
+ dwarf2_complex_location_expr_complaint ();
+ else
+ return 0;
+ }
break;
case DW_OP_GNU_push_tls_address:
non-zero to not look as a variable garbage collected by linker
which have DW_OP_addr 0. */
if (i < size)
- dwarf2_complex_location_expr_complaint ();
+ {
+ if (computed == nullptr)
+ dwarf2_complex_location_expr_complaint ();
+ else
+ return 0;
+ }
stack[stacki]++;
break;
case DW_OP_GNU_uninit:
+ if (computed != nullptr)
+ return 0;
break;
case DW_OP_addrx:
break;
default:
- {
- const char *name = get_DW_OP_name (op);
+ if (computed == nullptr)
+ {
+ const char *name = get_DW_OP_name (op);
- if (name)
- complaint (_("unsupported stack op: '%s'"),
- name);
- else
- complaint (_("unsupported stack op: '%02x'"),
- op);
- }
+ if (name)
+ complaint (_("unsupported stack op: '%s'"),
+ name);
+ else
+ complaint (_("unsupported stack op: '%02x'"),
+ op);
+ }
return (stack[stacki]);
}
outside of the allocated space. Also enforce minimum>0. */
if (stacki >= ARRAY_SIZE (stack) - 1)
{
- complaint (_("location description stack overflow"));
+ if (computed == nullptr)
+ complaint (_("location description stack overflow"));
return 0;
}
if (stacki <= 0)
{
- complaint (_("location description stack underflow"));
+ if (computed == nullptr)
+ complaint (_("location description stack underflow"));
return 0;
}
}
+
+ if (computed != nullptr)
+ *computed = true;
return (stack[stacki]);
}
{
int i;
+ bool is_cplus = HAVE_CPLUS_STRUCT (type);
+
for (i = 0; i < TYPE_NFIELDS (type); ++i)
- if (!field_is_static (&TYPE_FIELD (type, i))
- && is_dynamic_type_internal (TYPE_FIELD_TYPE (type, i), 0))
+ {
+ /* Static fields can be ignored here. */
+ if (field_is_static (&TYPE_FIELD (type, i)))
+ continue;
+ /* If the field has dynamic type, then so does TYPE. */
+ if (is_dynamic_type_internal (TYPE_FIELD_TYPE (type, i), 0))
+ return 1;
+ /* If the field is at a fixed offset, then it is not
+ dynamic. */
+ if (TYPE_FIELD_LOC_KIND (type, i) != FIELD_LOC_KIND_DWARF_BLOCK)
+ continue;
+ /* Do not consider C++ virtual base types to be dynamic
+ due to the field's offset being dynamic; these are
+ handled via other means. */
+ if (is_cplus && BASETYPE_VIA_VIRTUAL (type, i))
+ continue;
return 1;
+ }
}
break;
}
if (field_is_static (&TYPE_FIELD (resolved_type, i)))
continue;
+ if (TYPE_FIELD_LOC_KIND (resolved_type, i) == FIELD_LOC_KIND_DWARF_BLOCK)
+ {
+ struct dwarf2_property_baton baton;
+ baton.property_type
+ = lookup_pointer_type (TYPE_FIELD_TYPE (resolved_type, i));
+ baton.locexpr = *TYPE_FIELD_DWARF_BLOCK (resolved_type, i);
+
+ struct dynamic_prop prop;
+ prop.kind = PROP_LOCEXPR;
+ prop.data.baton = &baton;
+
+ CORE_ADDR addr;
+ if (dwarf2_evaluate_property (&prop, nullptr, addr_stack, &addr,
+ true))
+ SET_FIELD_BITPOS (TYPE_FIELD (resolved_type, i),
+ TARGET_CHAR_BIT * (addr - addr_stack->addr));
+ }
+
/* As we know this field is not a static field, the field's
field_loc_kind should be FIELD_LOC_KIND_BITPOS. Verify
this is the case, but only trigger a simple error rather
#include "typeprint.h"
#include <algorithm>
#include "cli/cli-style.h"
+#include "dwarf2/loc.h"
static struct cp_abi_ops gnu_v3_abi_ops;
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