_("%s evaluation requires a frame."), op_name);
}
+/* Ensure that a PER_CU is defined and throw an exception otherwise. */
+
+static void
+ensure_have_per_cu (dwarf2_per_cu_data *per_cu, const char* op_name)
+{
+ if (per_cu == nullptr)
+ throw_error (GENERIC_ERROR,
+ _("%s evaluation requires a compilation unit."), op_name);
+}
+
/* See expr.h. */
CORE_ADDR
start, length);
}
+/* See expr.h. */
+
+struct type *
+dwarf_expr_context::get_base_type (cu_offset die_cu_off)
+{
+ if (per_cu == nullptr)
+ return builtin_type (this->gdbarch)->builtin_int;
+
+ struct type *result = dwarf2_get_die_type (die_cu_off, this->per_cu,
+ this->per_objfile);
+
+ if (result == nullptr)
+ error (_("Could not find type for operation"));
+
+ return result;
+}
+
/* Require that TYPE be an integral type; throw an exception if not. */
static void
case DW_OP_addrx:
case DW_OP_GNU_addr_index:
+ ensure_have_per_cu (this->per_cu, "DW_OP_addrx");
+
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
- result = this->get_addr_index (uoffset);
+ result = dwarf2_read_addr_index (this->per_cu, this->per_objfile,
+ uoffset);
result += this->per_objfile->objfile->text_section_offset ();
result_val = value_from_ulongest (address_type, result);
break;
case DW_OP_GNU_const_index:
+ ensure_have_per_cu (this->per_cu, "DW_OP_GNU_const_index");
+
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
- result = this->get_addr_index (uoffset);
+ result = dwarf2_read_addr_index (this->per_cu, this->per_objfile,
+ uoffset);
result_val = value_from_ulongest (address_type, result);
break;
case DW_OP_GNU_implicit_pointer:
{
int64_t len;
+ ensure_have_per_cu (this->per_cu, "DW_OP_implicit_pointer");
- if (this->ref_addr_size == -1)
- error (_("DWARF-2 expression error: DW_OP_implicit_pointer "
- "is not allowed in frame context"));
+ int ref_addr_size = this->per_cu->ref_addr_size ();
/* The referred-to DIE of sect_offset kind. */
- this->len = extract_unsigned_integer (op_ptr, this->ref_addr_size,
- byte_order);
- op_ptr += this->ref_addr_size;
+ this->len = extract_unsigned_integer (op_ptr, ref_addr_size,
+ byte_order);
+ op_ptr += ref_addr_size;
/* The byte offset into the data. */
op_ptr = safe_read_sleb128 (op_ptr, op_end, &len);
{
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
cu_offset type_die_cu_off = (cu_offset) uoffset;
- type = get_base_type (type_die_cu_off, 0);
+ type = get_base_type (type_die_cu_off);
}
else
type = address_type;
case DW_OP_GNU_variable_value:
{
+ ensure_have_per_cu (this->per_cu, "DW_OP_GNU_variable_value");
+ int ref_addr_size = this->per_cu->ref_addr_size ();
+
sect_offset sect_off
= (sect_offset) extract_unsigned_integer (op_ptr,
- this->ref_addr_size,
+ ref_addr_size,
byte_order);
- op_ptr += this->ref_addr_size;
- result_val = value_cast (address_type,
- this->dwarf_variable_value (sect_off));
+ op_ptr += ref_addr_size;
+ result_val = sect_variable_value (sect_off, this->per_cu,
+ this->per_objfile);
+ result_val = value_cast (address_type, result_val);
}
break;
data = op_ptr;
op_ptr += n;
- type = get_base_type (type_die_cu_off, n);
+ type = get_base_type (type_die_cu_off);
+
+ if (TYPE_LENGTH (type) != n)
+ error (_("DW_OP_const_type has different sizes for type and data"));
+
result_val = value_from_contents (type, data);
}
break;
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
cu_offset type_die_cu_off = (cu_offset) uoffset;
- type = get_base_type (type_die_cu_off, 0);
+ type = get_base_type (type_die_cu_off);
result_val = this->get_reg_value (type, reg);
}
break;
if (to_underlying (type_die_cu_off) == 0)
type = address_type;
else
- type = get_base_type (type_die_cu_off, 0);
+ type = get_base_type (type_die_cu_off);
result_val = fetch (0);
pop ();
/* Target address size in bytes. */
int addr_size = 0;
- /* DW_FORM_ref_addr size in bytes. If -1 DWARF is executed from a frame
- context and operations depending on DW_FORM_ref_addr are not allowed. */
- int ref_addr_size = 0;
-
/* The current depth of dwarf expression recursion, via DW_OP_call*,
DW_OP_fbreg, DW_OP_push_object_address, etc., and the maximum
depth we'll tolerate before raising an error. */
/* Frame information used for the evaluation. */
frame_info *frame = nullptr;
+ /* Compilation unit used for the evaluation. */
+ dwarf2_per_cu_data *per_cu = nullptr;
+
/* Read LENGTH bytes at ADDR into BUF. */
virtual void read_mem (gdb_byte *buf, CORE_ADDR addr, size_t length) = 0;
subroutine. */
virtual void dwarf_call (cu_offset die_cu_off) = 0;
- /* Execute "variable value" operation on the DIE at SECT_OFF. */
- virtual struct value *dwarf_variable_value (sect_offset sect_off) = 0;
-
- /* Return the base type given by the indicated DIE at DIE_CU_OFF.
- This can throw an exception if the DIE is invalid or does not
- represent a base type. SIZE is non-zero if this function should
- verify that the resulting type has the correct size. */
- virtual struct type *get_base_type (cu_offset die_cu_off, int size)
- {
- /* Anything will do. */
- return builtin_type (this->gdbarch)->builtin_int;
- }
-
/* Push on DWARF stack an entry evaluated for DW_TAG_call_site's
parameter matching KIND and KIND_U at the caller of specified BATON.
If DEREF_SIZE is not -1 then use DW_AT_call_data_value instead of
union call_site_parameter_u kind_u,
int deref_size) = 0;
- /* Return the address indexed by DW_OP_addrx or DW_OP_GNU_addr_index.
- This can throw an exception if the index is out of range. */
- virtual CORE_ADDR get_addr_index (unsigned int index) = 0;
-
/* Return the `object address' for DW_OP_push_object_address. */
virtual CORE_ADDR get_object_address () = 0;
START and LENGTH. The result must be live until the current
expression evaluation is complete. */
void get_frame_base (const gdb_byte **start, size_t *length);
+
+ /* Return the base type given by the indicated DIE at DIE_CU_OFF.
+ This can throw an exception if the DIE is invalid or does not
+ represent a base type. */
+ struct type *get_base_type (cu_offset die_cu_off);
};
/* Return the value of register number REG (a DWARF register number),
invalid ("DW_OP_call*");
}
- struct value *dwarf_variable_value (sect_offset sect_off) override
- {
- invalid ("DW_OP_GNU_variable_value");
- }
-
- CORE_ADDR get_addr_index (unsigned int index) override
- {
- invalid ("DW_OP_addrx or DW_OP_GNU_addr_index");
- }
-
private:
void invalid (const char *op) ATTRIBUTE_NORETURN
ctx.frame = this_frame;
ctx.gdbarch = get_frame_arch (this_frame);
ctx.addr_size = addr_size;
- ctx.ref_addr_size = -1;
ctx.push_address (initial, initial_in_stack_memory);
ctx.eval (exp, len);
return nullptr;
}
-/* Given context CTX, section offset SECT_OFF, and compilation unit
- data PER_CU, execute the "variable value" operation on the DIE
- found at SECT_OFF. */
+/* See loc.h. */
-static struct value *
-sect_variable_value (struct dwarf_expr_context *ctx, sect_offset sect_off,
+struct value *
+sect_variable_value (sect_offset sect_off,
dwarf2_per_cu_data *per_cu,
dwarf2_per_objfile *per_objfile)
{
: dwarf_expr_context (per_objfile)
{}
- struct dwarf2_per_cu_data *per_cu;
CORE_ADDR obj_address;
/* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
per_cu_dwarf_call (this, die_offset, per_cu, per_objfile);
}
- /* Helper interface of sect_variable_value for
- dwarf2_evaluate_loc_desc. */
-
- struct value *dwarf_variable_value (sect_offset sect_off) override
- {
- return sect_variable_value (this, sect_off, per_cu, per_objfile);
- }
-
- struct type *get_base_type (cu_offset die_offset, int size) override
- {
- struct type *result = dwarf2_get_die_type (die_offset, per_cu, per_objfile);
- if (result == NULL)
- error (_("Could not find type for DW_OP_const_type"));
- if (size != 0 && TYPE_LENGTH (result) != size)
- error (_("DW_OP_const_type has different sizes for type and data"));
- return result;
- }
-
- /* Callback function for dwarf2_evaluate_loc_desc.
- Fetch the address indexed by DW_OP_addrx or DW_OP_GNU_addr_index. */
-
- CORE_ADDR get_addr_index (unsigned int index) override
- {
- return dwarf2_read_addr_index (per_cu, per_objfile, index);
- }
-
/* Callback function for get_object_address. Return the address of the VLA
object. */
ctx.gdbarch = per_objfile->objfile->arch ();
ctx.addr_size = per_cu->addr_size ();
- ctx.ref_addr_size = per_cu->ref_addr_size ();
try
{
ctx.gdbarch = per_objfile->objfile->arch ();
ctx.addr_size = dlbaton->per_cu->addr_size ();
- ctx.ref_addr_size = dlbaton->per_cu->ref_addr_size ();
if (push_initial_value)
ctx.push_address (ctx.obj_address, false);
const gdb_byte **start,
size_t *length);
+/* Given section offset SECT_OFF, and compilation unit data
+ PER_CU, execute the "variable value" operation on the DIE
+ found at SECT_OFF. */
+
+struct value *sect_variable_value (sect_offset sect_off,
+ dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile);
+
/* Evaluate a location description, starting at DATA and with length
SIZE, to find the current location of variable of TYPE in the context
of FRAME. */