aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2/expr.h
diff options
context:
space:
mode:
authorZoran Zaric <zoran.zaric@amd.com>2020-09-14 16:05:14 +0100
committerZoran Zaric <zoran.zaric@amd.com>2021-08-05 16:39:01 +0100
commit62e37eac1c5b9e4805d40715e7570f7146caa788 (patch)
tree2f7803ee5ad3348a4aaf2a0d38e129b32c0d6f4d /gdb/dwarf2/expr.h
parentfb4cdecb7e3b9cab8a83f3e69a9deafcf53501fe (diff)
downloadbinutils-62e37eac1c5b9e4805d40715e7570f7146caa788.zip
binutils-62e37eac1c5b9e4805d40715e7570f7146caa788.tar.gz
binutils-62e37eac1c5b9e4805d40715e7570f7146caa788.tar.bz2
Move frame context info to dwarf_expr_context
Following 15 patches in this patch series is cleaning up the design of the DWARF expression evaluator (dwarf_expr_context) to make future extensions of that evaluator easier and cleaner to implement. There are three subclasses of the dwarf_expr_context class (dwarf_expr_executor, dwarf_evaluate_loc_desc and evaluate_for_locexpr_baton). Here is a short description of each class: - dwarf_expr_executor is evaluating a DWARF expression in a context of a Call Frame Information. The overridden methods of this subclass report an error if a specific DWARF operation, represented by that method, is not allowed in a CFI context. The source code of this subclass lacks the support for composite as well as implicit pointer location description. - dwarf_evaluate_loc_desc can evaluate any expression with no restrictions. All of the methods that this subclass overrides are actually doing what they are intended to do. This subclass contains a full support for all location description types. - evaluate_for_locexpr_baton subclass is a specialization of the dwarf_evaluate_loc_desc subclass and it's function is to add support for passed in buffers. This seems to be a way to go around the fact that DWARF standard lacks a bit offset support for memory location descriptions as well as using any location description for the push object address functionality. It all comes down to this question: what is a function of a DWARF expression evaluator? Is it to evaluate the expression in a given context or to check the correctness of that expression in that context? Currently, the only reason why there is a dwarf_expr_executor subclass is to report an invalid DWARF expression in a context of a CFI, but is that what the evaluator is supposed to do considering that the evaluator is not tied to a given DWARF version? There are more and more vendor and GNU extensions that are not part of the DWARF standard, so is it that impossible to expect that some of the extensions could actually lift the previously imposed restrictions of the CFI context? Not to mention that every new DWARF version is lifting some restrictions anyway. The thing that makes more sense for an evaluator to do, is to take the context of an evaluation and checks the requirements of every operation evaluated against that context. With this approach, the evaluator would report an error only if parts of the context, necessary for the evaluation, are missing. If this approach is taken, then the unification of the dwarf_evaluate_loc_desc, dwarf_expr_executor and dwarf_expr_context is the next logical step. This makes a design of the DWARF expression evaluator cleaner and allows more flexibility when supporting future vendor and GNU extensions. Additional benefit here is that now all evaluators have access to all location description types, which means that a vendor extended CFI rules could support composite location description as well. This also means that a new evaluator interface can be changed to return a single struct value (that describes the result of the evaluation) instead of a caller poking around the dwarf_expr_context internal data for answers (like it is done currently). This patch starts the merging process by moving the frame 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 frame information to be resolved, if that information is not present. gdb/ChangeLog: * dwarf2/expr.c (ensure_have_frame): New function. (read_addr_from_reg): Add from frame.c. (dwarf_expr_context::dwarf_expr_context): Add frame info to dwarf_expr_context. (dwarf_expr_context::read_addr_from_reg): Remove. (dwarf_expr_context::get_reg_value): Move from dwarf_evaluate_loc_desc. (dwarf_expr_context::get_frame_base): Move from dwarf_evaluate_loc_desc. (dwarf_expr_context::execute_stack_op): Call frame context info check. Remove use of read_addr_from_reg method. * dwarf2/expr.h (struct dwarf_expr_context): Add frame info member, read_addr_from_reg, get_reg_value and get_frame_base declaration. (read_addr_from_reg): Move to expr.c. * dwarf2/frame.c (read_addr_from_reg): Move to dwarf_expr_context. (dwarf_expr_executor::read_addr_from_reg): Remove. (dwarf_expr_executor::get_frame_base): Remove. (dwarf_expr_executor::get_reg_value): Remove. (execute_stack_op): Use read_addr_from_reg function instead of read_addr_from_reg method. * dwarf2/loc.c (dwarf_evaluate_loc_desc::get_frame_base): Move to dwarf_expr_context. (dwarf_evaluate_loc_desc::get_reg_value): Move to dwarf_expr_context. (dwarf_evaluate_loc_desc::read_addr_from_reg): Remove. (dwarf2_locexpr_baton_eval):Use read_addr_from_reg function instead of read_addr_from_reg method.
Diffstat (limited to 'gdb/dwarf2/expr.h')
-rw-r--r--gdb/dwarf2/expr.h31
1 files changed, 17 insertions, 14 deletions
diff --git a/gdb/dwarf2/expr.h b/gdb/dwarf2/expr.h
index 60021eb..b227690 100644
--- a/gdb/dwarf2/expr.h
+++ b/gdb/dwarf2/expr.h
@@ -186,24 +186,12 @@ struct dwarf_expr_context
/* We evaluate the expression in the context of this objfile. */
dwarf2_per_objfile *per_objfile;
- /* Return the value of register number REGNUM (a DWARF register number),
- read as an address. */
- virtual CORE_ADDR read_addr_from_reg (int regnum) = 0;
-
- /* Return a value of type TYPE, stored in register number REGNUM
- of the frame associated to the given BATON.
-
- REGNUM is a DWARF register number. */
- virtual struct value *get_reg_value (struct type *type, int regnum) = 0;
+ /* Frame information used for the evaluation. */
+ frame_info *frame = nullptr;
/* Read LENGTH bytes at ADDR into BUF. */
virtual void read_mem (gdb_byte *buf, CORE_ADDR addr, size_t length) = 0;
- /* Return the location expression for the frame base attribute, in
- START and LENGTH. The result must be live until the current
- expression evaluation is complete. */
- virtual void get_frame_base (const gdb_byte **start, size_t *length) = 0;
-
/* Return the CFA for the frame. */
virtual CORE_ADDR get_frame_cfa () = 0;
@@ -259,8 +247,23 @@ private:
void add_piece (ULONGEST size, ULONGEST offset);
void execute_stack_op (const gdb_byte *op_ptr, const gdb_byte *op_end);
void pop ();
+
+ /* Return a value of type TYPE, stored in register number REGNUM
+ in a current context.
+
+ REGNUM is a DWARF register number. */
+ struct value *get_reg_value (struct type *type, int regnum);
+
+ /* Return the location expression for the frame base attribute, in
+ 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 value of register number REG (a DWARF register number),
+ read as an address in a given FRAME. */
+CORE_ADDR read_addr_from_reg (frame_info *frame, int reg);
+
void dwarf_expr_require_composition (const gdb_byte *, const gdb_byte *,
const char *);