mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-26 01:07:52 +00:00
Move compilation unit info to dwarf_expr_context
This patch moves the compilation unit context information and support
from dwarf_expr_executor and dwarf_evaluate_loc_desc to
dwarf_expr_context evaluator. The idea is to report an error when a
given operation requires a compilation unit information to be resolved,
which is not available.
With this change, it also makes sense to always acquire ref_addr_size
information from the compilation unit context, considering that all
DWARF operations that refer to that information require a compilation
unit context to be present during their evaluation.
gdb/ChangeLog:
* dwarf2/expr.c (ensure_have_per_cu): New function.
(dwarf_expr_context::dwarf_expr_context): Add compilation unit
context information.
(dwarf_expr_context::get_base_type): Move from
dwarf_evaluate_loc_desc.
(dwarf_expr_context::get_addr_index): Remove method.
(dwarf_expr_context::dwarf_variable_value): Remove method.
(dwarf_expr_context::execute_stack_op): Call compilation unit
context info check. Inline get_addr_index and
dwarf_variable_value methods.
* dwarf2/expr.h (struct dwarf_expr_context): Add compilation
context info.
(dwarf_expr_context::get_addr_index): Remove method.
(dwarf_expr_context::dwarf_variable_value): Remove method.
(dwarf_expr_context::ref_addr_size): Remove member.
* dwarf2/frame.c (dwarf_expr_executor::get_addr_index): Remove
method.
(dwarf_expr_executor::dwarf_variable_value): Remove method.
* dwarf2/loc.c (sect_variable_value): Expose function.
(dwarf_evaluate_loc_desc::get_addr_index): Remove method.
(dwarf_evaluate_loc_desc::dwarf_variable_value): Remove method.
(class dwarf_evaluate_loc_desc): Move compilation unit context
information to dwarf_expr_context class.
* dwarf2/loc.h (sect_variable_value): Expose function.
This commit is contained in:
@@ -68,6 +68,16 @@ ensure_have_frame (frame_info *frame, const char *op_name)
|
||||
_("%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
|
||||
@@ -197,6 +207,23 @@ dwarf_expr_context::get_frame_base (const gdb_byte **start,
|
||||
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
|
||||
@@ -693,14 +720,20 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
|
||||
|
||||
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;
|
||||
|
||||
@@ -830,15 +863,14 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
|
||||
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);
|
||||
@@ -1004,7 +1036,7 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
|
||||
{
|
||||
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;
|
||||
@@ -1327,13 +1359,17 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
|
||||
|
||||
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;
|
||||
|
||||
@@ -1403,7 +1439,11 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
|
||||
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;
|
||||
@@ -1417,7 +1457,7 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
|
||||
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;
|
||||
@@ -1435,7 +1475,7 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
|
||||
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 ();
|
||||
|
||||
@@ -137,10 +137,6 @@ struct dwarf_expr_context
|
||||
/* 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. */
|
||||
@@ -189,6 +185,9 @@ struct dwarf_expr_context
|
||||
/* 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;
|
||||
|
||||
@@ -208,19 +207,6 @@ struct dwarf_expr_context
|
||||
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
|
||||
@@ -229,10 +215,6 @@ struct dwarf_expr_context
|
||||
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;
|
||||
|
||||
@@ -255,6 +237,11 @@ private:
|
||||
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),
|
||||
|
||||
@@ -259,16 +259,6 @@ public:
|
||||
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
|
||||
@@ -290,7 +280,6 @@ execute_stack_op (const gdb_byte *exp, ULONGEST len, int addr_size,
|
||||
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);
|
||||
|
||||
@@ -651,12 +651,10 @@ compute_var_value (const char *name)
|
||||
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)
|
||||
{
|
||||
@@ -696,7 +694,6 @@ public:
|
||||
: 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
|
||||
@@ -722,32 +719,6 @@ public:
|
||||
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. */
|
||||
|
||||
@@ -2237,7 +2208,6 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
|
||||
|
||||
ctx.gdbarch = per_objfile->objfile->arch ();
|
||||
ctx.addr_size = per_cu->addr_size ();
|
||||
ctx.ref_addr_size = per_cu->ref_addr_size ();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -2504,7 +2474,6 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
|
||||
|
||||
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);
|
||||
|
||||
@@ -53,6 +53,14 @@ extern void func_get_frame_base_dwarf_block (struct symbol *framefunc,
|
||||
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. */
|
||||
|
||||
Reference in New Issue
Block a user