| 1 | /* GDB-specific functions for operating on agent expressions |
| 2 | Copyright (C) 1998, 1999, 2000, 2007 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GDB. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | Boston, MA 02110-1301, USA. */ |
| 20 | |
| 21 | #ifndef AX_GDB_H |
| 22 | #define AX_GDB_H |
| 23 | |
| 24 | struct expression; |
| 25 | |
| 26 | /* Types and enums */ |
| 27 | |
| 28 | /* GDB stores expressions in the form of a flattened tree (struct |
| 29 | expression), so we just walk that tree and generate agent bytecodes |
| 30 | as we go along. |
| 31 | |
| 32 | GDB's normal evaluation uses struct value, which contains the |
| 33 | expression's value as well as its address or the register it came |
| 34 | from. The `+' operator uses the value, whereas the unary `&' |
| 35 | operator will use the address portion. The `=' operator will use |
| 36 | the address or register number of its left hand side. |
| 37 | |
| 38 | The issues are different when generating agent bytecode. Given a |
| 39 | variable reference expression, we should not necessarily generate |
| 40 | code to fetch its value, because the next operator may be `=' or |
| 41 | unary `&'. Instead, when we recurse on a subexpression, we |
| 42 | indicate whether we want that expression to produce an lvalue or an |
| 43 | rvalue. If we requested an lvalue, then the recursive call tells |
| 44 | us whether it generated code to compute an address on the stack, or |
| 45 | whether the lvalue lives in a register. |
| 46 | |
| 47 | The `axs' prefix here means `agent expression, static', because |
| 48 | this is all static analysis of the expression, i.e. analysis which |
| 49 | doesn't depend on the contents of memory and registers. */ |
| 50 | |
| 51 | |
| 52 | /* Different kinds of agent expression static values. */ |
| 53 | enum axs_lvalue_kind |
| 54 | { |
| 55 | /* We generated code to compute the subexpression's value. |
| 56 | Constants and arithmetic operators yield this. */ |
| 57 | axs_rvalue, |
| 58 | |
| 59 | /* We generated code to yield the subexpression's value's address on |
| 60 | the top of the stack. If the caller needs an rvalue, it should |
| 61 | call require_rvalue to produce the rvalue from this address. */ |
| 62 | axs_lvalue_memory, |
| 63 | |
| 64 | /* We didn't generate any code, and the stack is undisturbed, |
| 65 | because the subexpression's value lives in a register; u.reg is |
| 66 | the register number. If the caller needs an rvalue, it should |
| 67 | call require_rvalue to produce the rvalue from this register |
| 68 | number. */ |
| 69 | axs_lvalue_register |
| 70 | }; |
| 71 | |
| 72 | /* Structure describing what we got from a subexpression. Think of |
| 73 | this as parallel to value.h's enum lval_type, except that we're |
| 74 | describing a value which will exist when the expression is |
| 75 | evaluated in the future, not a value we have in our hand. */ |
| 76 | struct axs_value |
| 77 | { |
| 78 | enum axs_lvalue_kind kind; /* see above */ |
| 79 | |
| 80 | /* The type of the subexpression. Even if lvalue == axs_lvalue_memory, |
| 81 | this is the type of the value itself; the value on the stack is a |
| 82 | "pointer to" an object of this type. */ |
| 83 | struct type *type; |
| 84 | |
| 85 | union |
| 86 | { |
| 87 | /* if kind == axs_lvalue_register, this is the register number */ |
| 88 | int reg; |
| 89 | } |
| 90 | u; |
| 91 | }; |
| 92 | \f |
| 93 | |
| 94 | /* Translating GDB expressions into agent expressions. */ |
| 95 | |
| 96 | /* Given a GDB expression EXPR, translate it into the agent bytecode, |
| 97 | and return it. FLAGS are from enum expr_to_agent_flags. */ |
| 98 | extern struct agent_expr *expr_to_agent (struct expression *EXPR, |
| 99 | struct axs_value *VALUE); |
| 100 | |
| 101 | /* Given a GDB expression EXPR denoting an lvalue in memory, produce a |
| 102 | string of agent bytecode which will leave its address and size on |
| 103 | the top of stack. Return the agent expression. */ |
| 104 | extern struct agent_expr *expr_to_address_and_size (struct expression *EXPR); |
| 105 | |
| 106 | /* Given a GDB expression EXPR, return bytecode to trace its value. |
| 107 | The result will use the `trace' and `trace_quick' bytecodes to |
| 108 | record the value of all memory touched by the expression, and leave |
| 109 | no values on the stack. The caller can then use the ax_reqs |
| 110 | function to discover which registers the expression uses. */ |
| 111 | extern struct agent_expr *gen_trace_for_expr (CORE_ADDR, struct expression *); |
| 112 | |
| 113 | #endif /* AX_GDB_H */ |