#include "gdbsupport/underlying.h"
#include "gdbsupport/byte-vector.h"
-static struct value *dwarf2_evaluate_loc_desc_full (struct type *type,
- struct frame_info *frame,
- const gdb_byte *data,
- size_t size,
- struct dwarf2_per_cu_data *per_cu,
- struct type *subobj_type,
- LONGEST subobj_byte_offset);
+static struct value *dwarf2_evaluate_loc_desc_full
+ (struct type *type, struct frame_info *frame, const gdb_byte *data,
+ size_t size, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile,
+ struct type *subobj_type, LONGEST subobj_byte_offset);
static struct call_site_parameter *dwarf_expr_reg_to_entry_parameter
(struct frame_info *frame,
enum call_site_parameter_kind kind,
union call_site_parameter_u kind_u,
- struct dwarf2_per_cu_data **per_cu_return);
+ dwarf2_per_cu_data **per_cu_return,
+ dwarf2_per_objfile **per_objfile_return);
static struct value *indirect_synthetic_pointer
(sect_offset die, LONGEST byte_offset,
- struct dwarf2_per_cu_data *per_cu,
+ dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile,
struct frame_info *frame,
struct type *type, bool resolve_abstract_p = false);
The result indicates the kind of entry found. */
static enum debug_loc_kind
-decode_debug_loclists_addresses (struct dwarf2_per_cu_data *per_cu,
+decode_debug_loclists_addresses (dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile,
const gdb_byte *loc_ptr,
const gdb_byte *buf_end,
const gdb_byte **new_ptr,
loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64);
if (loc_ptr == NULL)
return DEBUG_LOC_BUFFER_OVERFLOW;
- *high = dwarf2_read_addr_index (per_cu, u64);
+ *high = dwarf2_read_addr_index (per_cu, per_objfile, u64);
*new_ptr = loc_ptr;
return DEBUG_LOC_BASE_ADDRESS;
case DW_LLE_startx_length:
loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64);
if (loc_ptr == NULL)
return DEBUG_LOC_BUFFER_OVERFLOW;
- *low = dwarf2_read_addr_index (per_cu, u64);
+ *low = dwarf2_read_addr_index (per_cu, per_objfile, u64);
*high = *low;
loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64);
if (loc_ptr == NULL)
The result indicates the kind of entry found. */
static enum debug_loc_kind
-decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data *per_cu,
+decode_debug_loc_dwo_addresses (dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile,
const gdb_byte *loc_ptr,
const gdb_byte *buf_end,
const gdb_byte **new_ptr,
loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &high_index);
if (loc_ptr == NULL)
return DEBUG_LOC_BUFFER_OVERFLOW;
- *high = dwarf2_read_addr_index (per_cu, high_index);
+ *high = dwarf2_read_addr_index (per_cu, per_objfile, high_index);
*new_ptr = loc_ptr;
return DEBUG_LOC_BASE_ADDRESS;
case DW_LLE_GNU_start_end_entry:
loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &low_index);
if (loc_ptr == NULL)
return DEBUG_LOC_BUFFER_OVERFLOW;
- *low = dwarf2_read_addr_index (per_cu, low_index);
+ *low = dwarf2_read_addr_index (per_cu, per_objfile, low_index);
loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &high_index);
if (loc_ptr == NULL)
return DEBUG_LOC_BUFFER_OVERFLOW;
- *high = dwarf2_read_addr_index (per_cu, high_index);
+ *high = dwarf2_read_addr_index (per_cu, per_objfile, high_index);
*new_ptr = loc_ptr;
return DEBUG_LOC_START_END;
case DW_LLE_GNU_start_length_entry:
loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &low_index);
if (loc_ptr == NULL)
return DEBUG_LOC_BUFFER_OVERFLOW;
- *low = dwarf2_read_addr_index (per_cu, low_index);
+ *low = dwarf2_read_addr_index (per_cu, per_objfile, low_index);
if (loc_ptr + 4 > buf_end)
return DEBUG_LOC_BUFFER_OVERFLOW;
*high = *low;
dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
size_t *locexpr_length, CORE_ADDR pc)
{
- struct objfile *objfile = baton->per_cu->objfile ();
+ dwarf2_per_objfile *per_objfile = baton->per_objfile;
+ struct objfile *objfile = per_objfile->objfile;
struct gdbarch *gdbarch = objfile->arch ();
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
unsigned int addr_size = baton->per_cu->addr_size ();
int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
/* Adjust base_address for relocatable objects. */
- CORE_ADDR base_offset = baton->per_cu->text_offset ();
+ CORE_ADDR base_offset = baton->per_objfile->objfile->text_section_offset ();
CORE_ADDR base_address = baton->base_address + base_offset;
const gdb_byte *loc_ptr, *buf_end;
if (baton->per_cu->version () < 5 && baton->from_dwo)
kind = decode_debug_loc_dwo_addresses (baton->per_cu,
+ baton->per_objfile,
loc_ptr, buf_end, &new_ptr,
&low, &high, byte_order);
else if (baton->per_cu->version () < 5)
signed_addr_p);
else
kind = decode_debug_loclists_addresses (baton->per_cu,
+ baton->per_objfile,
loc_ptr, buf_end, &new_ptr,
&low, &high, byte_order,
addr_size, signed_addr_p);
SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location
(framefunc, get_frame_pc (frame), &start, &length);
result = dwarf2_evaluate_loc_desc (type, frame, start, length,
- dlbaton->per_cu);
+ dlbaton->per_cu, dlbaton->per_objfile);
/* The DW_AT_frame_base attribute contains a location description which
computes the base address itself. However, the call to
SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location
(framefunc, get_frame_pc (frame), &start, &length);
result = dwarf2_evaluate_loc_desc (type, frame, start, length,
- dlbaton->per_cu);
+ dlbaton->per_cu, dlbaton->per_objfile);
/* The DW_AT_frame_base attribute contains a location description which
computes the base address itself. However, the call to
static void
per_cu_dwarf_call (struct dwarf_expr_context *ctx, cu_offset die_offset,
- struct dwarf2_per_cu_data *per_cu)
+ dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
{
struct dwarf2_locexpr_baton block;
- block = dwarf2_fetch_die_loc_cu_off (die_offset, per_cu,
+ block = dwarf2_fetch_die_loc_cu_off (die_offset, per_cu, per_objfile,
get_frame_pc_for_per_cu_dwarf_call,
ctx);
static struct value *
sect_variable_value (struct dwarf_expr_context *ctx, sect_offset sect_off,
- struct dwarf2_per_cu_data *per_cu)
+ dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile)
{
- struct type *die_type = dwarf2_fetch_die_type_sect_off (sect_off, per_cu);
+ struct type *die_type
+ = dwarf2_fetch_die_type_sect_off (sect_off, per_cu, per_objfile);
if (die_type == NULL)
error (_("Bad DW_OP_GNU_variable_value DIE."));
/* Note: Things still work when the following test is removed. This
test and error is here to conform to the proposed specification. */
- if (TYPE_CODE (die_type) != TYPE_CODE_INT
- && TYPE_CODE (die_type) != TYPE_CODE_PTR)
+ if (die_type->code () != TYPE_CODE_INT
+ && die_type->code () != TYPE_CODE_PTR)
error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer."));
struct type *type = lookup_pointer_type (die_type);
struct frame_info *frame = get_selected_frame (_("No frame selected."));
- return indirect_synthetic_pointer (sect_off, 0, per_cu, frame, type, true);
+ return indirect_synthetic_pointer (sect_off, 0, per_cu, per_objfile, frame,
+ type, true);
}
class dwarf_evaluate_loc_desc : public dwarf_expr_context
{
- public:
+public:
+ dwarf_evaluate_loc_desc (dwarf2_per_objfile *per_objfile)
+ : dwarf_expr_context (per_objfile)
+ {}
struct frame_info *frame;
struct dwarf2_per_cu_data *per_cu;
current thread's thread-local storage with offset OFFSET. */
CORE_ADDR get_tls_address (CORE_ADDR offset) override
{
- struct objfile *objfile = per_cu->objfile ();
-
- return target_translate_tls_address (objfile, offset);
+ return target_translate_tls_address (per_objfile->objfile, offset);
}
/* Helper interface of per_cu_dwarf_call for
void dwarf_call (cu_offset die_offset) override
{
- per_cu_dwarf_call (this, die_offset, per_cu);
+ per_cu_dwarf_call (this, die_offset, per_cu, per_objfile);
}
/* Helper interface of sect_variable_value for
struct value *dwarf_variable_value (sect_offset sect_off) override
{
- return sect_variable_value (this, sect_off, per_cu);
+ 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);
+ 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)
CORE_ADDR get_addr_index (unsigned int index) override
{
- return dwarf2_read_addr_index (per_cu, index);
+ return dwarf2_read_addr_index (per_cu, per_objfile, index);
}
/* Callback function for get_object_address. Return the address of the VLA
int deref_size) override
{
struct frame_info *caller_frame;
- struct dwarf2_per_cu_data *caller_per_cu;
+ dwarf2_per_cu_data *caller_per_cu;
+ dwarf2_per_objfile *caller_per_objfile;
struct call_site_parameter *parameter;
const gdb_byte *data_src;
size_t size;
caller_frame = get_prev_frame (frame);
parameter = dwarf_expr_reg_to_entry_parameter (frame, kind, kind_u,
- &caller_per_cu);
+ &caller_per_cu,
+ &caller_per_objfile);
data_src = deref_size == -1 ? parameter->value : parameter->data_value;
size = deref_size == -1 ? parameter->value_size : parameter->data_value_size;
throw_error (NO_ENTRY_VALUE_ERROR,
_("Cannot resolve DW_AT_call_data_value"));
+ /* We are about to evaluate an expression in the context of the caller
+ of the current frame. This evaluation context may be different from
+ the current (callee's) context), so temporarily set the caller's context.
+
+ It is possible for the caller to be from a different objfile from the
+ callee if the call is made through a function pointer. */
scoped_restore save_frame = make_scoped_restore (&this->frame,
caller_frame);
scoped_restore save_per_cu = make_scoped_restore (&this->per_cu,
caller_per_cu);
scoped_restore save_obj_addr = make_scoped_restore (&this->obj_address,
(CORE_ADDR) 0);
+ scoped_restore save_per_objfile = make_scoped_restore (&this->per_objfile,
+ caller_per_objfile);
scoped_restore save_arch = make_scoped_restore (&this->gdbarch);
- this->gdbarch = per_cu->objfile ()->arch ();
+ this->gdbarch = this->per_objfile->objfile->arch ();
scoped_restore save_addr_size = make_scoped_restore (&this->addr_size);
- this->addr_size = per_cu->addr_size ();
- scoped_restore save_offset = make_scoped_restore (&this->offset);
- this->offset = per_cu->text_offset ();
+ this->addr_size = this->per_cu->addr_size ();
this->eval (data_src, size);
}
caller_core_addr_type = builtin_type (caller_arch)->builtin_func_ptr;
val = dwarf2_evaluate_loc_desc (caller_core_addr_type, caller_frame,
dwarf_block->data, dwarf_block->size,
- dwarf_block->per_cu);
+ dwarf_block->per_cu,
+ dwarf_block->per_objfile);
/* DW_AT_call_target is a DWARF expression, not a DWARF location. */
if (VALUE_LVAL (val) == lval_memory)
return value_address (val);
paddress (gdbarch, addr));
type = SYMBOL_TYPE (sym);
- gdb_assert (TYPE_CODE (type) == TYPE_CODE_FUNC);
+ gdb_assert (type->code () == TYPE_CODE_FUNC);
gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC);
return sym;
dwarf_expr_reg_to_entry_parameter (struct frame_info *frame,
enum call_site_parameter_kind kind,
union call_site_parameter_u kind_u,
- struct dwarf2_per_cu_data **per_cu_return)
+ dwarf2_per_cu_data **per_cu_return,
+ dwarf2_per_objfile **per_objfile_return)
{
CORE_ADDR func_addr, caller_pc;
struct gdbarch *gdbarch;
}
*per_cu_return = call_site->per_cu;
+ *per_objfile_return = call_site->per_objfile;
return parameter;
}
dwarf_entry_parameter_to_value (struct call_site_parameter *parameter,
CORE_ADDR deref_size, struct type *type,
struct frame_info *caller_frame,
- struct dwarf2_per_cu_data *per_cu)
+ dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile)
{
const gdb_byte *data_src;
gdb_byte *data;
memcpy (data, data_src, size);
data[size] = DW_OP_stack_value;
- return dwarf2_evaluate_loc_desc (type, caller_frame, data, size + 1, per_cu);
+ return dwarf2_evaluate_loc_desc (type, caller_frame, data, size + 1, per_cu,
+ per_objfile);
}
/* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
struct frame_info *caller_frame = get_prev_frame (frame);
struct value *outer_val, *target_val, *val;
struct call_site_parameter *parameter;
- struct dwarf2_per_cu_data *caller_per_cu;
+ dwarf2_per_cu_data *caller_per_cu;
+ dwarf2_per_objfile *caller_per_objfile;
parameter = dwarf_expr_reg_to_entry_parameter (frame, kind, kind_u,
- &caller_per_cu);
+ &caller_per_cu,
+ &caller_per_objfile);
outer_val = dwarf_entry_parameter_to_value (parameter, -1 /* deref_size */,
type, caller_frame,
- caller_per_cu);
+ caller_per_cu,
+ caller_per_objfile);
/* Check if DW_AT_call_data_value cannot be used. If it should be
used and it is not available do not fall back to OUTER_VAL - dereferencing
target_val = dwarf_entry_parameter_to_value (parameter,
TYPE_LENGTH (target_type),
target_type, caller_frame,
- caller_per_cu);
+ caller_per_cu,
+ caller_per_objfile);
val = allocate_computed_value (type, &entry_data_value_funcs,
release_value (target_val).release ());
/* Reference count. */
int refc = 0;
+ /* The objfile from which this closure's expression came. */
+ dwarf2_per_objfile *per_objfile = nullptr;
+
/* The CU from which this closure's expression came. */
struct dwarf2_per_cu_data *per_cu = NULL;
PIECES. */
static struct piece_closure *
-allocate_piece_closure (struct dwarf2_per_cu_data *per_cu,
+allocate_piece_closure (dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile,
std::vector<dwarf_expr_piece> &&pieces,
struct frame_info *frame)
{
struct piece_closure *c = new piece_closure;
c->refc = 1;
+ /* We must capture this here due to sharing of DWARF state. */
+ c->per_objfile = per_objfile;
c->per_cu = per_cu;
c->pieces = std::move (pieces);
if (frame == NULL)
break;
}
- struct objfile *objfile = c->per_cu->objfile ();
- struct gdbarch *objfile_gdbarch = objfile->arch ();
+ gdbarch *objfile_gdbarch = c->per_objfile->objfile->arch ();
ULONGEST stack_value_size_bits
= 8 * TYPE_LENGTH (value_type (p->v.value));
static struct value *
fetch_const_value_from_synthetic_pointer (sect_offset die, LONGEST byte_offset,
- struct dwarf2_per_cu_data *per_cu,
+ dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile,
struct type *type)
{
struct value *result = NULL;
LONGEST len;
auto_obstack temp_obstack;
- bytes = dwarf2_fetch_constant_bytes (die, per_cu, &temp_obstack, &len);
+ bytes = dwarf2_fetch_constant_bytes (die, per_cu, per_objfile,
+ &temp_obstack, &len);
if (bytes != NULL)
{
static struct value *
indirect_synthetic_pointer (sect_offset die, LONGEST byte_offset,
- struct dwarf2_per_cu_data *per_cu,
+ dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile,
struct frame_info *frame, struct type *type,
bool resolve_abstract_p)
{
/* Fetch the location expression of the DIE we're pointing to. */
struct dwarf2_locexpr_baton baton
- = dwarf2_fetch_die_loc_sect_off (die, per_cu,
+ = dwarf2_fetch_die_loc_sect_off (die, per_cu, per_objfile,
get_frame_address_in_block_wrapper, frame,
resolve_abstract_p);
/* Get type of pointed-to DIE. */
- struct type *orig_type = dwarf2_fetch_die_type_sect_off (die, per_cu);
+ struct type *orig_type = dwarf2_fetch_die_type_sect_off (die, per_cu,
+ per_objfile);
if (orig_type == NULL)
invalid_synthetic_pointer ();
if (baton.data != NULL)
return dwarf2_evaluate_loc_desc_full (orig_type, frame, baton.data,
baton.size, baton.per_cu,
+ baton.per_objfile,
TYPE_TARGET_TYPE (type),
byte_offset);
else
return fetch_const_value_from_synthetic_pointer (die, byte_offset, per_cu,
- type);
+ per_objfile, type);
}
/* An implementation of an lval_funcs method to indirect through a
enum bfd_endian byte_order;
type = check_typedef (value_type (value));
- if (TYPE_CODE (type) != TYPE_CODE_PTR)
+ if (type->code () != TYPE_CODE_PTR)
return NULL;
bit_length = 8 * TYPE_LENGTH (type);
return indirect_synthetic_pointer (piece->v.ptr.die_sect_off,
byte_offset, c->per_cu,
- frame, type);
+ c->per_objfile, frame, type);
}
/* Implementation of the coerce_ref method of lval_funcs for synthetic C++
return indirect_synthetic_pointer
(closure->pieces[0].v.ptr.die_sect_off,
closure->pieces[0].v.ptr.offset,
- closure->per_cu, frame, type);
+ closure->per_cu, closure->per_objfile, frame, type);
}
else
{
static struct value *
dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
const gdb_byte *data, size_t size,
- struct dwarf2_per_cu_data *per_cu,
+ dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile,
struct type *subobj_type,
LONGEST subobj_byte_offset)
{
struct value *retval;
- struct objfile *objfile = per_cu->objfile ();
if (subobj_type == NULL)
{
if (size == 0)
return allocate_optimized_out_value (subobj_type);
- dwarf_evaluate_loc_desc ctx;
+ dwarf_evaluate_loc_desc ctx (per_objfile);
ctx.frame = frame;
ctx.per_cu = per_cu;
ctx.obj_address = 0;
scoped_value_mark free_values;
- ctx.gdbarch = objfile->arch ();
+ ctx.gdbarch = per_objfile->objfile->arch ();
ctx.addr_size = per_cu->addr_size ();
ctx.ref_addr_size = per_cu->ref_addr_size ();
- ctx.offset = per_cu->text_offset ();
try
{
if (bit_size > 8 * TYPE_LENGTH (type))
invalid_synthetic_pointer ();
- c = allocate_piece_closure (per_cu, std::move (ctx.pieces), frame);
+ c = allocate_piece_closure (per_cu, per_objfile, std::move (ctx.pieces),
+ frame);
/* We must clean up the value chain after creating the piece
closure but before allocating the result. */
free_values.free_to_mark ();
the operation. Therefore, we do the conversion here
since the type is readily available. */
- switch (TYPE_CODE (subobj_type))
+ switch (subobj_type->code ())
{
case TYPE_CODE_FUNC:
case TYPE_CODE_METHOD:
size_t n = TYPE_LENGTH (value_type (value));
size_t len = TYPE_LENGTH (subobj_type);
size_t max = TYPE_LENGTH (type);
- struct gdbarch *objfile_gdbarch = objfile->arch ();
+ gdbarch *objfile_gdbarch = per_objfile->objfile->arch ();
if (subobj_byte_offset + len > max)
invalid_synthetic_pointer ();
struct value *
dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
const gdb_byte *data, size_t size,
- struct dwarf2_per_cu_data *per_cu)
+ dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile)
{
return dwarf2_evaluate_loc_desc_full (type, frame, data, size, per_cu,
- NULL, 0);
+ per_objfile, NULL, 0);
}
-/* Evaluates a dwarf expression and stores the result in VAL, expecting
- that the dwarf expression only produces a single CORE_ADDR. FRAME is the
- frame in which the expression is evaluated. ADDR is a context (location of
- a variable) and might be needed to evaluate the location expression.
- Returns 1 on success, 0 otherwise. */
+/* A specialization of dwarf_evaluate_loc_desc that is used by
+ dwarf2_locexpr_baton_eval. This subclass exists to handle the case
+ where a caller of dwarf2_locexpr_baton_eval passes in some data,
+ but with the address being 0. In this situation, we arrange for
+ memory reads to come from the passed-in buffer. */
+
+struct evaluate_for_locexpr_baton : public dwarf_evaluate_loc_desc
+{
+ evaluate_for_locexpr_baton (dwarf2_per_objfile *per_objfile)
+ : dwarf_evaluate_loc_desc (per_objfile)
+ {}
+
+ /* The data that was passed in. */
+ gdb::array_view<const gdb_byte> data_view;
+
+ CORE_ADDR get_object_address () override
+ {
+ if (data_view.data () == nullptr && obj_address == 0)
+ error (_("Location address is not set."));
+ return obj_address;
+ }
+
+ void read_mem (gdb_byte *buf, CORE_ADDR addr, size_t len) override
+ {
+ if (len == 0)
+ return;
+
+ /* Prefer the passed-in memory, if it exists. */
+ CORE_ADDR offset = addr - obj_address;
+ if (offset < data_view.size () && offset + len <= data_view.size ())
+ {
+ memcpy (buf, data_view.data (), len);
+ return;
+ }
+
+ read_memory (addr, buf, len);
+ }
+};
+
+/* Evaluates a dwarf expression and stores the result in VAL,
+ expecting that the dwarf expression only produces a single
+ CORE_ADDR. FRAME is the frame in which the expression is
+ evaluated. ADDR_STACK is a context (location of a variable) and
+ might be needed to evaluate the location expression.
+ PUSH_INITIAL_VALUE is true if the address (either from ADDR_STACK,
+ or the default of 0) should be pushed on the DWARF expression
+ evaluation stack before evaluating the expression; this is required
+ by certain forms of DWARF expression. Returns 1 on success, 0
+ otherwise. */
static int
dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
struct frame_info *frame,
- CORE_ADDR addr,
- CORE_ADDR *valp)
+ const struct property_addr_info *addr_stack,
+ CORE_ADDR *valp,
+ bool push_initial_value)
{
- struct objfile *objfile;
-
if (dlbaton == NULL || dlbaton->size == 0)
return 0;
- dwarf_evaluate_loc_desc ctx;
+ dwarf2_per_objfile *per_objfile = dlbaton->per_objfile;
+ evaluate_for_locexpr_baton ctx (per_objfile);
ctx.frame = frame;
ctx.per_cu = dlbaton->per_cu;
- ctx.obj_address = addr;
-
- objfile = dlbaton->per_cu->objfile ();
+ if (addr_stack == nullptr)
+ ctx.obj_address = 0;
+ else
+ {
+ ctx.obj_address = addr_stack->addr;
+ ctx.data_view = addr_stack->valaddr;
+ }
- ctx.gdbarch = objfile->arch ();
+ ctx.gdbarch = per_objfile->objfile->arch ();
ctx.addr_size = dlbaton->per_cu->addr_size ();
ctx.ref_addr_size = dlbaton->per_cu->ref_addr_size ();
- ctx.offset = dlbaton->per_cu->text_offset ();
+
+ if (push_initial_value)
+ ctx.push_address (ctx.obj_address, false);
try
{
dwarf2_evaluate_property (const struct dynamic_prop *prop,
struct frame_info *frame,
const struct property_addr_info *addr_stack,
- CORE_ADDR *value)
+ CORE_ADDR *value,
+ bool push_initial_value)
{
if (prop == NULL)
return false;
= (const struct dwarf2_property_baton *) prop->data.baton;
gdb_assert (baton->property_type != NULL);
- if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame,
- addr_stack ? addr_stack->addr : 0,
- value))
+ if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame, addr_stack,
+ value, push_initial_value))
{
if (baton->locexpr.is_reference)
{
if (data != NULL)
{
val = dwarf2_evaluate_loc_desc (baton->property_type, frame, data,
- size, baton->loclist.per_cu);
+ size, baton->loclist.per_cu,
+ baton->loclist.per_objfile);
if (!value_optimized_out (val))
{
*value = value_as_address (val);
}
if (pinfo == NULL)
error (_("cannot find reference address for offset property"));
- if (pinfo->valaddr != NULL)
+ if (pinfo->valaddr.data () != NULL)
val = value_from_contents
(baton->offset_info.type,
- pinfo->valaddr + baton->offset_info.offset);
+ pinfo->valaddr.data () + baton->offset_info.offset);
else
val = value_at (baton->offset_info.type,
pinfo->addr + baton->offset_info.offset);
= (struct dwarf2_property_baton *) prop->data.baton;
const gdb_byte *data;
size_t size;
- struct dwarf2_per_cu_data *per_cu;
+ dwarf2_per_cu_data *per_cu;
+ dwarf2_per_objfile *per_objfile;
if (prop->kind == PROP_LOCEXPR)
{
data = baton->locexpr.data;
size = baton->locexpr.size;
per_cu = baton->locexpr.per_cu;
+ per_objfile = baton->locexpr.per_objfile;
}
else
{
data = dwarf2_find_location_expression (&baton->loclist, &size, pc);
per_cu = baton->loclist.per_cu;
+ per_objfile = baton->loclist.per_objfile;
}
compile_dwarf_bounds_to_c (stream, result_name, prop, sym, pc,
gdbarch, registers_used,
per_cu->addr_size (),
- data, data + size, per_cu);
+ data, data + size, per_cu, per_objfile);
}
\f
class symbol_needs_eval_context : public dwarf_expr_context
{
- public:
+public:
+ symbol_needs_eval_context (dwarf2_per_objfile *per_objfile)
+ : dwarf_expr_context (per_objfile)
+ {}
enum symbol_needs_kind needs;
struct dwarf2_per_cu_data *per_cu;
void dwarf_call (cu_offset die_offset) override
{
- per_cu_dwarf_call (this, die_offset, per_cu);
+ per_cu_dwarf_call (this, die_offset, per_cu, per_objfile);
}
/* Helper interface of sect_variable_value for
struct value *dwarf_variable_value (sect_offset sect_off) override
{
- return sect_variable_value (this, sect_off, per_cu);
+ return sect_variable_value (this, sect_off, per_cu, per_objfile);
}
/* DW_OP_entry_value accesses require a caller, therefore a
static enum symbol_needs_kind
dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size,
- struct dwarf2_per_cu_data *per_cu)
+ dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile)
{
int in_reg;
- struct objfile *objfile = per_cu->objfile ();
scoped_value_mark free_values;
- symbol_needs_eval_context ctx;
+ symbol_needs_eval_context ctx (per_objfile);
ctx.needs = SYMBOL_NEEDS_NONE;
ctx.per_cu = per_cu;
- ctx.gdbarch = objfile->arch ();
+ ctx.gdbarch = per_objfile->objfile->arch ();
ctx.addr_size = per_cu->addr_size ();
ctx.ref_addr_size = per_cu->ref_addr_size ();
- ctx.offset = per_cu->text_offset ();
ctx.eval (data, size);
dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
unsigned int addr_size, const gdb_byte *op_ptr,
const gdb_byte *op_end,
- struct dwarf2_per_cu_data *per_cu)
+ dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile)
{
gdbarch *arch = expr->gdbarch;
std::vector<int> dw_labels, patches;
index, not an address. We don't support things like
branching between the address and the TLS op. */
if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
- uoffset += per_cu->text_offset ();
+ uoffset += per_objfile->objfile->text_section_offset ();
ax_const_l (expr, uoffset);
break;
op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
dwarf2_compile_expr_to_ax (expr, loc, addr_size, datastart,
- datastart + datalen, per_cu);
+ datastart + datalen, per_cu,
+ per_objfile);
if (loc->kind == axs_lvalue_register)
require_rvalue (expr, loc);
/* Another expression. */
ax_const_l (expr, text_offset);
dwarf2_compile_expr_to_ax (expr, loc, addr_size, cfa_start,
- cfa_end, per_cu);
+ cfa_end, per_cu, per_objfile);
}
loc->kind = axs_lvalue_memory;
op_ptr += size;
cu_offset cuoffset = (cu_offset) uoffset;
- block = dwarf2_fetch_die_loc_cu_off (cuoffset, per_cu,
+ block = dwarf2_fetch_die_loc_cu_off (cuoffset, per_cu, per_objfile,
get_ax_pc, expr);
/* DW_OP_call_ref is currently not supported. */
gdb_assert (block.per_cu == per_cu);
dwarf2_compile_expr_to_ax (expr, loc, addr_size, block.data,
- block.data + block.size, per_cu);
+ block.data + block.size, per_cu,
+ per_objfile);
}
break;
struct value *val;
val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, dlbaton->data,
- dlbaton->size, dlbaton->per_cu);
+ dlbaton->size, dlbaton->per_cu,
+ dlbaton->per_objfile);
return val;
}
= (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
return dwarf2_loc_desc_get_symbol_read_needs (dlbaton->data, dlbaton->size,
- dlbaton->per_cu);
+ dlbaton->per_cu,
+ dlbaton->per_objfile);
}
/* Return true if DATA points to the end of a piece. END is one past
static const gdb_byte *
locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
- CORE_ADDR addr, struct objfile *objfile,
- struct dwarf2_per_cu_data *per_cu,
+ CORE_ADDR addr, dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile,
const gdb_byte *data, const gdb_byte *end,
unsigned int addr_size)
{
+ objfile *objfile = per_objfile->objfile;
struct gdbarch *gdbarch = objfile->arch ();
size_t leb128_size;
uint64_t offset;
data = safe_read_uleb128 (data + 1, end, &offset);
- offset = dwarf2_read_addr_index (per_cu, offset);
+ offset = dwarf2_read_addr_index (per_cu, per_objfile, offset);
fprintf_filtered (stream,
_("a thread-local variable at offset 0x%s "
"in the thread-local storage for `%s'"),
int offset_size, const gdb_byte *start,
const gdb_byte *data, const gdb_byte *end,
int indent, int all,
- struct dwarf2_per_cu_data *per_cu)
+ dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile)
{
while (data < end
&& (all
data = safe_read_uleb128 (data, end, &ul);
cu_offset offset = (cu_offset) ul;
- type = dwarf2_get_die_type (offset, per_cu);
+ type = dwarf2_get_die_type (offset, per_cu, per_objfile);
fprintf_filtered (stream, "<");
type_print (type, "", stream, -1);
fprintf_filtered (stream, " [0x%s]> %d",
data = safe_read_uleb128 (data, end, &ul);
cu_offset type_die = (cu_offset) ul;
- type = dwarf2_get_die_type (type_die, per_cu);
+ type = dwarf2_get_die_type (type_die, per_cu, per_objfile);
fprintf_filtered (stream, "<");
type_print (type, "", stream, -1);
fprintf_filtered (stream, " [0x%s]>",
data = safe_read_uleb128 (data, end, &ul);
cu_offset type_die = (cu_offset) ul;
- type = dwarf2_get_die_type (type_die, per_cu);
+ type = dwarf2_get_die_type (type_die, per_cu, per_objfile);
fprintf_filtered (stream, "<");
type_print (type, "", stream, -1);
fprintf_filtered (stream, " [0x%s]> [$%s]",
{
struct type *type;
- type = dwarf2_get_die_type (type_die, per_cu);
+ type = dwarf2_get_die_type (type_die, per_cu, per_objfile);
fprintf_filtered (stream, "<");
type_print (type, "", stream, -1);
fprintf_filtered (stream, " [0x%s]>",
fputc_filtered ('\n', stream);
disassemble_dwarf_expression (stream, arch, addr_size, offset_size,
start, data, data + ul, indent + 2,
- all, per_cu);
+ all, per_cu, per_objfile);
data += ul;
continue;
case DW_OP_addrx:
case DW_OP_GNU_addr_index:
data = safe_read_uleb128 (data, end, &ul);
- ul = dwarf2_read_addr_index (per_cu, ul);
+ ul = dwarf2_read_addr_index (per_cu, per_objfile, ul);
fprintf_filtered (stream, " 0x%s", phex_nz (ul, addr_size));
break;
case DW_OP_GNU_const_index:
data = safe_read_uleb128 (data, end, &ul);
- ul = dwarf2_read_addr_index (per_cu, ul);
+ ul = dwarf2_read_addr_index (per_cu, per_objfile, ul);
fprintf_filtered (stream, " %s", pulongest (ul));
break;
locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr,
struct ui_file *stream,
const gdb_byte *data, size_t size,
- struct objfile *objfile, unsigned int addr_size,
- int offset_size, struct dwarf2_per_cu_data *per_cu)
+ unsigned int addr_size,
+ int offset_size, dwarf2_per_cu_data *per_cu,
+ dwarf2_per_objfile *per_objfile)
{
const gdb_byte *end = data + size;
int first_piece = 1, bad = 0;
+ objfile *objfile = per_objfile->objfile;
while (data < end)
{
if (!dwarf_always_disassemble)
{
data = locexpr_describe_location_piece (symbol, stream,
- addr, objfile, per_cu,
+ addr, per_cu, per_objfile,
data, end, addr_size);
/* If we printed anything, or if we have an empty piece,
then don't disassemble. */
addr_size, offset_size, data,
data, end, 0,
dwarf_always_disassemble,
- per_cu);
+ per_cu, per_objfile);
}
if (data < end)
{
struct dwarf2_locexpr_baton *dlbaton
= (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
- struct objfile *objfile = dlbaton->per_cu->objfile ();
unsigned int addr_size = dlbaton->per_cu->addr_size ();
int offset_size = dlbaton->per_cu->offset_size ();
locexpr_describe_location_1 (symbol, addr, stream,
dlbaton->data, dlbaton->size,
- objfile, addr_size, offset_size,
- dlbaton->per_cu);
+ addr_size, offset_size,
+ dlbaton->per_cu, dlbaton->per_objfile);
}
/* Describe the location of SYMBOL as an agent value in VALUE, generating
value->optimized_out = 1;
else
dwarf2_compile_expr_to_ax (ax, value, addr_size, dlbaton->data,
- dlbaton->data + dlbaton->size, dlbaton->per_cu);
+ dlbaton->data + dlbaton->size, dlbaton->per_cu,
+ dlbaton->per_objfile);
}
/* symbol_computed_ops 'generate_c_location' method. */
compile_dwarf_expr_to_c (stream, result_name,
sym, pc, gdbarch, registers_used, addr_size,
dlbaton->data, dlbaton->data + dlbaton->size,
- dlbaton->per_cu);
+ dlbaton->per_cu, dlbaton->per_objfile);
}
/* The set of location functions used with the DWARF-2 expression
data = dwarf2_find_location_expression (dlbaton, &size, pc);
val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, data, size,
- dlbaton->per_cu);
+ dlbaton->per_cu, dlbaton->per_objfile);
return val;
}
struct dwarf2_loclist_baton *dlbaton
= (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
const gdb_byte *loc_ptr, *buf_end;
- struct objfile *objfile = dlbaton->per_cu->objfile ();
+ dwarf2_per_objfile *per_objfile = dlbaton->per_objfile;
+ struct objfile *objfile = per_objfile->objfile;
struct gdbarch *gdbarch = objfile->arch ();
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
unsigned int addr_size = dlbaton->per_cu->addr_size ();
int offset_size = dlbaton->per_cu->offset_size ();
int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
/* Adjust base_address for relocatable objects. */
- CORE_ADDR base_offset = dlbaton->per_cu->text_offset ();
+ CORE_ADDR base_offset = objfile->text_section_offset ();
CORE_ADDR base_address = dlbaton->base_address + base_offset;
int done = 0;
if (dlbaton->per_cu->version () < 5 && dlbaton->from_dwo)
kind = decode_debug_loc_dwo_addresses (dlbaton->per_cu,
+ dlbaton->per_objfile,
loc_ptr, buf_end, &new_ptr,
&low, &high, byte_order);
else if (dlbaton->per_cu->version () < 5)
signed_addr_p);
else
kind = decode_debug_loclists_addresses (dlbaton->per_cu,
+ dlbaton->per_objfile,
loc_ptr, buf_end, &new_ptr,
&low, &high, byte_order,
addr_size, signed_addr_p);
/* Now describe this particular location. */
locexpr_describe_location_1 (symbol, low, stream, loc_ptr, length,
- objfile, addr_size, offset_size,
- dlbaton->per_cu);
+ addr_size, offset_size,
+ dlbaton->per_cu, dlbaton->per_objfile);
fprintf_filtered (stream, "\n");
value->optimized_out = 1;
else
dwarf2_compile_expr_to_ax (ax, value, addr_size, data, data + size,
- dlbaton->per_cu);
+ dlbaton->per_cu, dlbaton->per_objfile);
}
/* symbol_computed_ops 'generate_c_location' method. */
compile_dwarf_expr_to_c (stream, result_name,
sym, pc, gdbarch, registers_used, addr_size,
data, data + size,
- dlbaton->per_cu);
+ dlbaton->per_cu,
+ dlbaton->per_objfile);
}
/* The set of location functions used with the DWARF-2 expression