aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2/expr.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2020-05-27 11:14:01 -0400
committerSimon Marchi <simon.marchi@efficios.com>2020-05-27 11:15:56 -0400
commit89b07335fe42d6da84c19351ca0c34b11a3c4f8e (patch)
tree4f7d214a8f9172a131f08f953d3d9b4332be7d54 /gdb/dwarf2/expr.c
parent293e7e51145506f5f547a777242d7963f946c6ec (diff)
downloadgdb-89b07335fe42d6da84c19351ca0c34b11a3c4f8e.zip
gdb-89b07335fe42d6da84c19351ca0c34b11a3c4f8e.tar.gz
gdb-89b07335fe42d6da84c19351ca0c34b11a3c4f8e.tar.bz2
Add dwarf2_per_objfile to dwarf_expr_context and dwarf2_frame_cache
Evaluating DWARF expressions (such as location expressions) requires knowing about the current objfile. For example, it may call functions like dwarf2_fetch_die_loc_sect_off, which currently obtain the dwarf2_per_objfile object it needs from the dwarf2_per_cu_data object. However, since we are going to remove this dwarf2_per_cu_data::dwarf2_per_objfile link, these functions will need to obtain the current dwarf2_per_objfile by parmeter. If we go up the stack, we see that the DWARF expression contexts (dwarf_expr_context and the classes that derive from it) need to store the dwarf2_per_objfile, to be able to pass it to those functions that will need it. This patch adds a constructor to all these dwarf_expr_context variants, accepting a dwarf2_per_objfile parameter. This dwarf2_per_objfile generally comes from a symbol baton created earlier. For frame-related expressions, the dwarf2_per_objfile object must be passed through the dwarf2_frame_cache object. This lead to the dwarf2_frame_find_fde function returning (by parameter) a dwarf2_per_objfile object. I then realized that this made the existing "out_offset" parameter redundant. This offset is `objfile->text_section_offset ()`, so it can be recomputed from the dwarf2_per_objfile object at any time. I therefore opted to remove this output parameter, as well as the offset field of dwarf2_frame_cache. *Note*, there's one spot I'm particularly unsure about. In dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value, we would save and overwrite the offset value in the context, along with a bunch of other state. This is because we might be about to evaluate something in a different CU that the current one. If the two CUs are in the same objfile, then the text_offset is the same, as it's a property of the objfile. However, if the two CUs are possibly in different objfiles, then it means the text_offsets are different. It would also mean we would need to save and restore the dwarf2_per_objfile in the context. Is that even possible? gdb/ChangeLog: * dwarf2/expr.h (struct dwarf_expr_context) <dwarf_expr_context>: Add dwarf2_per_objfile parameter. <offset>: Remove. <per_objfile>: New member. * dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add dwarf2_per_objfile parameter. Don't set offset, set per_objfile. (dwarf_expr_context::execute_stack_op): Use offset from objfile. * dwarf2/frame.c (dwarf2_frame_find_fde): Return (by parameter) a dwarf2_per_objfile object instead of an offset. (class dwarf_expr_executor) <dwarf_expr_executor>: Add constructor. (execute_stack_op): Add dwarf2_per_objfile parameter, pass it to dwarf2_expr_executor constructor. Don't set offset. (dwarf2_fetch_cfa_info): Update. (struct dwarf2_frame_cache) <text_offset>: Remove. <per_objfile>: New field. (dwarf2_frame_cache): Update. (dwarf2_frame_prev_register): Update. * dwarf2/loc.c (class dwarf_evaluate_loc_desc) <dwarf_evaluate_loc_desc>: Add constructor. (dwarf2_evaluate_loc_desc_full): Update. (dwarf2_locexpr_baton_eval): Update. (class symbol_needs_eval_context) <symbol_needs_eval_context>: Add constructor. (dwarf2_loc_desc_get_symbol_read_needs): Update. Change-Id: I14df060669cc36ad04759f1708c6d7b1fda77727
Diffstat (limited to 'gdb/dwarf2/expr.c')
-rw-r--r--gdb/dwarf2/expr.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index 14ffae4..91ac4c0 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -27,6 +27,7 @@
#include "dwarf2.h"
#include "dwarf2/expr.h"
#include "dwarf2/loc.h"
+#include "dwarf2/read.h"
#include "gdbsupport/underlying.h"
#include "gdbarch.h"
@@ -88,17 +89,17 @@ dwarf_expr_context::address_type () const
/* Create a new context for the expression evaluator. */
-dwarf_expr_context::dwarf_expr_context ()
+dwarf_expr_context::dwarf_expr_context (dwarf2_per_objfile *per_objfile)
: gdbarch (NULL),
addr_size (0),
ref_addr_size (0),
- offset (0),
recursion_depth (0),
max_recursion_depth (0x100),
location (DWARF_VALUE_MEMORY),
len (0),
data (NULL),
- initialized (0)
+ initialized (0),
+ per_objfile (per_objfile)
{
}
@@ -631,7 +632,7 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
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)
- result += this->offset;
+ result += this->per_objfile->objfile->text_section_offset ();
result_val = value_from_ulongest (address_type, result);
break;
@@ -639,7 +640,7 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
case DW_OP_GNU_addr_index:
op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
result = this->get_addr_index (uoffset);
- result += this->offset;
+ result += this->per_objfile->objfile->text_section_offset ();
result_val = value_from_ulongest (address_type, result);
break;
case DW_OP_GNU_const_index: