/* DWARF 2 Expression Evaluator. Copyright (C) 2001-2020 Free Software Foundation, Inc. Contributed by Daniel Berlin . This file is part of GDB. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #if !defined (DWARF2EXPR_H) #define DWARF2EXPR_H #include "leb128.h" #include "gdbtypes.h" class dwarf_entry; class dwarf_entry_factory; struct dwarf2_per_objfile; /* The expression evaluator works with a dwarf_expr_context, describing its current state and its callbacks. */ struct dwarf_expr_context { /* Create a new context for the expression evaluator. We should ever only pass in the PER_OBJFILE and the ADDR_SIZE information should be retrievable from there. The PER_OBJFILE contains a pointer to the PER_BFD information anyway and the address size information must be the same for the whole BFD. */ dwarf_expr_context (struct dwarf2_per_objfile *per_objfile, int addr_size); /* Destroy dwarf entry factory object. */ virtual ~dwarf_expr_context (); /* Push ADDR onto the stack. */ void push_address (CORE_ADDR addr, bool in_stack_memory); /* Evaluate the expression at ADDR (LEN bytes long) in a given PER_CU FRAME context. AS_LVAL defines if the returned struct value is expected to be a value or a location description. Where TYPE, SUBOBJ_TYPE and SUBOBJ_OFFSET describe expected struct value representation of the evaluation result. The ADDR_INFO property can be specified to override the range of memory addresses with the passed in buffer. */ struct value *eval_exp (const gdb_byte *addr, size_t len, bool as_lval, struct dwarf2_per_cu_data *per_cu, struct frame_info *frame, const struct property_addr_info *addr_info = nullptr, struct type *type = nullptr, struct type *subobj_type = nullptr, LONGEST subobj_offset = 0); private: /* The stack of values. */ std::vector stack; /* Target architecture to use for address operations. */ struct gdbarch *gdbarch; /* Target address size in bytes. */ int addr_size; /* 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; /* 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. */ int recursion_depth, max_recursion_depth; /* We evaluate the expression in the context of this objfile. */ dwarf2_per_objfile *per_objfile; /* Frame information used for the evaluation. */ struct frame_info *frame; /* Compilation unit used for the evaluation. */ struct dwarf2_per_cu_data *per_cu; /* Property address info used for the evaluation. */ const struct property_addr_info *addr_info; /* Factory in charge of the dwarf entry's life cycle. */ dwarf_entry_factory *entry_factory; /* Evaluate the expression at ADDR (LEN bytes long). */ void eval (const gdb_byte *addr, size_t len); /* Return the type used for DWARF operations where the type is unspecified in the DWARF spec. Only certain sizes are supported. */ struct type *address_type () const; /* Push ENTRY onto the stack. */ void push (dwarf_entry *value); /* Return true if the expression stack is empty. */ bool stack_empty_p () const; /* Pop a top element of the stack and add as a composite piece. If the fallowing top element of the stack is a composite location description, the piece will be added to it. Otherwise a new composite location description will be created and the piece will be added to that composite. */ dwarf_entry *add_piece (ULONGEST bit_size, ULONGEST bit_offset); /* The engine for the expression evaluator. Using the context in this object, evaluate the expression between OP_PTR and OP_END. */ void execute_stack_op (const gdb_byte *op_ptr, const gdb_byte *op_end); /* Pop the top item off of the stack. */ void pop (); /* Retrieve the N'th item on the stack. */ dwarf_entry *fetch (int n); /* Fetch the result of the expression evaluation in a form of a struct value, where TYPE, SUBOBJ_TYPE and SUBOBJ_OFFSET describe the source level representation of that result. AS_LVAL defines if the fetched struct value is expected to be a value or a location description. */ struct value *fetch_result (struct type *type, struct type *subobj_type, LONGEST subobj_offset, bool as_lval); /* 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 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. */ struct type *get_base_type (cu_offset die_cu_off, int size); /* Execute DW_AT_location expression for the DWARF expression subroutine in the DIE at DIE_CU_OFF in the CU. Do not touch STACK while it being passed to and returned from the called DWARF subroutine. */ void dwarf_call (cu_offset die_cu_off); /* 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 DW_AT_call_value. */ void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind, union call_site_parameter_u kind_u, int deref_size); /* Apply dereference operation on the DWARF ENTRY. In the case of a value entry, the entry will be implicitly converted to the appropriate location description before the operation is applied. If the SIZE is specified, it must be equal or smaller then the TYPE type size. If SIZE is smaller then the type size, the value will be zero extended to the difference. */ dwarf_entry* dwarf_entry_deref (dwarf_entry *entry, struct type *type, size_t size = 0); /* Convert struct value to the matching DWARF entry representation. Used for non-standard DW_OP_GNU_variable_value operation support. */ dwarf_entry *gdb_value_to_dwarf_entry (struct value *value); /* Convert DWARF entry to the matching struct value representation of the given TYPE type. SUBOBJ_TYPE information if specified, will be used for more precise description of the source variable type information. Where SUBOBJ_OFFSET defines an offset into the DWARF entry contents. */ struct value *dwarf_entry_to_gdb_value (dwarf_entry *entry, struct type *type, struct type *subobj_type = nullptr, LONGEST subobj_offset = 0); }; /* Return the address type used of the GDBARCH architecture and ADDR_SIZE is expected size of the type. */ struct type *address_type (struct gdbarch *gdbarch, int addr_size); /* 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 (struct frame_info *, int); /* Check that the current operator is either at the end of an expression, or that it is followed by a composition operator or by DW_OP_GNU_uninit (which should terminate the expression). */ void dwarf_expr_require_composition (const gdb_byte *, const gdb_byte *, const char *); /* If