146283Sdfr/* GDB-specific functions for operating on agent expressions 298944Sobrien Copyright 1998, 1999, 2000 Free Software Foundation, Inc. 346283Sdfr 498944Sobrien This file is part of GDB. 546283Sdfr 698944Sobrien This program is free software; you can redistribute it and/or modify 798944Sobrien it under the terms of the GNU General Public License as published by 898944Sobrien the Free Software Foundation; either version 2 of the License, or 998944Sobrien (at your option) any later version. 1046283Sdfr 1198944Sobrien This program is distributed in the hope that it will be useful, 1298944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1398944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1498944Sobrien GNU General Public License for more details. 1546283Sdfr 1698944Sobrien You should have received a copy of the GNU General Public License 1798944Sobrien along with this program; if not, write to the Free Software 1898944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 1998944Sobrien Boston, MA 02111-1307, USA. */ 2046283Sdfr 2146283Sdfr#ifndef AX_GDB_H 2246283Sdfr#define AX_GDB_H 2346283Sdfr 24130803Smarcelstruct expression; 25130803Smarcel 2646283Sdfr/* Types and enums */ 2746283Sdfr 2846283Sdfr/* GDB stores expressions in the form of a flattened tree (struct 2946283Sdfr expression), so we just walk that tree and generate agent bytecodes 3046283Sdfr as we go along. 3146283Sdfr 3246283Sdfr GDB's normal evaluation uses struct value, which contains the 3346283Sdfr expression's value as well as its address or the register it came 3446283Sdfr from. The `+' operator uses the value, whereas the unary `&' 3546283Sdfr operator will use the address portion. The `=' operator will use 3646283Sdfr the address or register number of its left hand side. 3746283Sdfr 3846283Sdfr The issues are different when generating agent bytecode. Given a 3946283Sdfr variable reference expression, we should not necessarily generate 4046283Sdfr code to fetch its value, because the next operator may be `=' or 4146283Sdfr unary `&'. Instead, when we recurse on a subexpression, we 4246283Sdfr indicate whether we want that expression to produce an lvalue or an 4346283Sdfr rvalue. If we requested an lvalue, then the recursive call tells 4446283Sdfr us whether it generated code to compute an address on the stack, or 4546283Sdfr whether the lvalue lives in a register. 4646283Sdfr 4746283Sdfr The `axs' prefix here means `agent expression, static', because 4846283Sdfr this is all static analysis of the expression, i.e. analysis which 4946283Sdfr doesn't depend on the contents of memory and registers. */ 5046283Sdfr 5146283Sdfr 5246283Sdfr/* Different kinds of agent expression static values. */ 5398944Sobrienenum axs_lvalue_kind 5498944Sobrien { 5598944Sobrien /* We generated code to compute the subexpression's value. 5698944Sobrien Constants and arithmetic operators yield this. */ 5798944Sobrien axs_rvalue, 5846283Sdfr 5998944Sobrien /* We generated code to yield the subexpression's value's address on 6098944Sobrien the top of the stack. If the caller needs an rvalue, it should 6198944Sobrien call require_rvalue to produce the rvalue from this address. */ 6298944Sobrien axs_lvalue_memory, 6346283Sdfr 6498944Sobrien /* We didn't generate any code, and the stack is undisturbed, 6598944Sobrien because the subexpression's value lives in a register; u.reg is 6698944Sobrien the register number. If the caller needs an rvalue, it should 6798944Sobrien call require_rvalue to produce the rvalue from this register 6898944Sobrien number. */ 6998944Sobrien axs_lvalue_register 7098944Sobrien }; 7146283Sdfr 7246283Sdfr/* Structure describing what we got from a subexpression. Think of 7346283Sdfr this as parallel to value.h's enum lval_type, except that we're 7446283Sdfr describing a value which will exist when the expression is 7546283Sdfr evaluated in the future, not a value we have in our hand. */ 7698944Sobrienstruct axs_value 7798944Sobrien { 7898944Sobrien enum axs_lvalue_kind kind; /* see above */ 7946283Sdfr 8098944Sobrien /* The type of the subexpression. Even if lvalue == axs_lvalue_memory, 8198944Sobrien this is the type of the value itself; the value on the stack is a 8298944Sobrien "pointer to" an object of this type. */ 8398944Sobrien struct type *type; 8446283Sdfr 8598944Sobrien union 8698944Sobrien { 8798944Sobrien /* if kind == axs_lvalue_register, this is the register number */ 8898944Sobrien int reg; 8998944Sobrien } 9098944Sobrien u; 9198944Sobrien }; 9298944Sobrien 9346283Sdfr 9446283Sdfr/* Translating GDB expressions into agent expressions. */ 9546283Sdfr 9646283Sdfr/* Given a GDB expression EXPR, translate it into the agent bytecode, 9746283Sdfr and return it. FLAGS are from enum expr_to_agent_flags. */ 9898944Sobrienextern struct agent_expr *expr_to_agent (struct expression *EXPR, 9998944Sobrien struct axs_value *VALUE); 10046283Sdfr 10146283Sdfr/* Given a GDB expression EXPR denoting an lvalue in memory, produce a 10246283Sdfr string of agent bytecode which will leave its address and size on 10346283Sdfr the top of stack. Return the agent expression. */ 10498944Sobrienextern struct agent_expr *expr_to_address_and_size (struct expression *EXPR); 10546283Sdfr 10646283Sdfr/* Given a GDB expression EXPR, return bytecode to trace its value. 10746283Sdfr The result will use the `trace' and `trace_quick' bytecodes to 10846283Sdfr record the value of all memory touched by the expression, and leave 10946283Sdfr no values on the stack. The caller can then use the ax_reqs 11046283Sdfr function to discover which registers the expression uses. */ 11198944Sobrienextern struct agent_expr *gen_trace_for_expr (CORE_ADDR, struct expression *); 11246283Sdfr 11346283Sdfr#endif /* AX_GDB_H */ 114