diff options
author | Zoran Zaric <zoran.zaric@amd.com> | 2020-09-14 17:02:29 +0100 |
---|---|---|
committer | Zoran Zaric <zoran.zaric@amd.com> | 2021-08-05 16:39:36 +0100 |
commit | a580d9604bb71c19741465f2e3a46c5a07672be0 (patch) | |
tree | 90f1099bf62a413710f2e0f464fe96ece9da0666 /gdb/dwarf2/expr.c | |
parent | 6c7779b34b38ca71df9460c07bc4c03d01dfaa0b (diff) | |
download | binutils-a580d9604bb71c19741465f2e3a46c5a07672be0.zip binutils-a580d9604bb71c19741465f2e3a46c5a07672be0.tar.gz binutils-a580d9604bb71c19741465f2e3a46c5a07672be0.tar.bz2 |
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.
Diffstat (limited to 'gdb/dwarf2/expr.c')
-rw-r--r-- | gdb/dwarf2/expr.c | 72 |
1 files changed, 56 insertions, 16 deletions
diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 4427c53..812dac08 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -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 (); |