1130803Smarcel/* Dwarf2 Expression Evaluator 2130803Smarcel Copyright 2001, 2002, 2003 Free Software Foundation, Inc. 3130803Smarcel Contributed by Daniel Berlin (dan@dberlin.org) 4130803Smarcel This file is part of GDB. 5130803Smarcel 6130803Smarcel This program is free software; you can redistribute it and/or modify 7130803Smarcel it under the terms of the GNU General Public License as published by 8130803Smarcel the Free Software Foundation; either version 2 of the License, or 9130803Smarcel (at your option) any later version. 10130803Smarcel 11130803Smarcel This program is distributed in the hope that it will be useful, 12130803Smarcel but WITHOUT ANY WARRANTY; without even the implied warranty of 13130803Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14130803Smarcel GNU General Public License for more details. 15130803Smarcel 16130803Smarcel You should have received a copy of the GNU General Public License 17130803Smarcel along with this program; if not, write to the Free Software 18130803Smarcel Foundation, Inc., 59 Temple Place - Suite 330, 19130803Smarcel Boston, MA 02111-1307, USA. */ 20130803Smarcel 21130803Smarcel#if !defined (DWARF2EXPR_H) 22130803Smarcel#define DWARF2EXPR_H 23130803Smarcel 24130803Smarcel/* The expression evaluator works with a dwarf_expr_context, describing 25130803Smarcel its current state and its callbacks. */ 26130803Smarcelstruct dwarf_expr_context 27130803Smarcel{ 28130803Smarcel /* The stack of values, allocated with xmalloc. */ 29130803Smarcel CORE_ADDR *stack; 30130803Smarcel 31130803Smarcel /* The number of values currently pushed on the stack, and the 32130803Smarcel number of elements allocated to the stack. */ 33130803Smarcel int stack_len, stack_allocated; 34130803Smarcel 35130803Smarcel /* An opaque argument provided by the caller, which will be passed 36130803Smarcel to all of the callback functions. */ 37130803Smarcel void *baton; 38130803Smarcel 39130803Smarcel /* Return the value of register number REGNUM. */ 40130803Smarcel CORE_ADDR (*read_reg) (void *baton, int regnum); 41130803Smarcel 42130803Smarcel /* Read LENGTH bytes at ADDR into BUF. */ 43130803Smarcel void (*read_mem) (void *baton, char *buf, CORE_ADDR addr, 44130803Smarcel size_t length); 45130803Smarcel 46130803Smarcel /* Return the location expression for the frame base attribute, in 47130803Smarcel START and LENGTH. The result must be live until the current 48130803Smarcel expression evaluation is complete. */ 49130803Smarcel void (*get_frame_base) (void *baton, unsigned char **start, 50130803Smarcel size_t *length); 51130803Smarcel 52130803Smarcel /* Return the thread-local storage address for 53130803Smarcel DW_OP_GNU_push_tls_address. */ 54130803Smarcel CORE_ADDR (*get_tls_address) (void *baton, CORE_ADDR offset); 55130803Smarcel 56130803Smarcel#if 0 57130803Smarcel /* Not yet implemented. */ 58130803Smarcel 59130803Smarcel /* Return the location expression for the dwarf expression 60130803Smarcel subroutine in the die at OFFSET in the current compilation unit. 61130803Smarcel The result must be live until the current expression evaluation 62130803Smarcel is complete. */ 63130803Smarcel unsigned char *(*get_subr) (void *baton, off_t offset, size_t *length); 64130803Smarcel 65130803Smarcel /* Return the `object address' for DW_OP_push_object_address. */ 66130803Smarcel CORE_ADDR (*get_object_address) (void *baton); 67130803Smarcel#endif 68130803Smarcel 69130803Smarcel /* The current depth of dwarf expression recursion, via DW_OP_call*, 70130803Smarcel DW_OP_fbreg, DW_OP_push_object_address, etc., and the maximum 71130803Smarcel depth we'll tolerate before raising an error. */ 72130803Smarcel int recursion_depth, max_recursion_depth; 73130803Smarcel 74130803Smarcel /* Non-zero if the result is in a register. The register number 75130803Smarcel will be on the expression stack. */ 76130803Smarcel int in_reg; 77130803Smarcel}; 78130803Smarcel 79130803Smarcelstruct dwarf_expr_context *new_dwarf_expr_context (void); 80130803Smarcelvoid free_dwarf_expr_context (struct dwarf_expr_context *ctx); 81130803Smarcel 82130803Smarcelvoid dwarf_expr_push (struct dwarf_expr_context *ctx, CORE_ADDR value); 83130803Smarcelvoid dwarf_expr_pop (struct dwarf_expr_context *ctx); 84130803Smarcelvoid dwarf_expr_eval (struct dwarf_expr_context *ctx, unsigned char *addr, 85130803Smarcel size_t len); 86130803SmarcelCORE_ADDR dwarf_expr_fetch (struct dwarf_expr_context *ctx, int n); 87130803Smarcel 88130803Smarcel 89130803Smarcelunsigned char *read_uleb128 (unsigned char *buf, unsigned char *buf_end, 90130803Smarcel ULONGEST * r); 91130803Smarcelunsigned char *read_sleb128 (unsigned char *buf, unsigned char *buf_end, 92130803Smarcel LONGEST * r); 93130803SmarcelCORE_ADDR dwarf2_read_address (unsigned char *buf, unsigned char *buf_end, 94130803Smarcel int *bytes_read); 95130803Smarcel 96130803Smarcel#endif 97