GDB (API)
/home/stan/gdb/src/gdb/ax.h
Go to the documentation of this file.
00001 /* Definitions for expressions designed to be executed on the agent
00002    Copyright (C) 1998-2013 Free Software Foundation, Inc.
00003 
00004    This file is part of GDB.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 3 of the License, or
00009    (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00018 
00019 #ifndef AGENTEXPR_H
00020 #define AGENTEXPR_H
00021 
00022 #include "doublest.h"           /* For DOUBLEST.  */
00023 #include "vec.h"
00024 
00025 /* It's sometimes useful to be able to debug programs that you can't
00026    really stop for more than a fraction of a second.  To this end, the
00027    user can specify a tracepoint (like a breakpoint, but you don't
00028    stop at it), and specify a bunch of expressions to record the
00029    values of when that tracepoint is reached.  As the program runs,
00030    GDB collects the values.  At any point (possibly while values are
00031    still being collected), the user can display the collected values.
00032 
00033    This is used with remote debugging; we don't really support it on
00034    native configurations.
00035 
00036    This means that expressions are being evaluated by the remote agent,
00037    which doesn't have any access to the symbol table information, and
00038    needs to be small and simple.
00039 
00040    The agent_expr routines and datatypes are a bytecode language
00041    designed to be executed by the agent.  Agent expressions work in
00042    terms of fixed-width values, operators, memory references, and
00043    register references.  You can evaluate a agent expression just given
00044    a bunch of memory and register values to sniff at; you don't need
00045    any symbolic information like variable names, types, etc.
00046 
00047    GDB translates source expressions, whose meaning depends on
00048    symbolic information, into agent bytecode expressions, whose meaning
00049    is independent of symbolic information.  This means the agent can
00050    evaluate them on the fly without reference to data only available
00051    to the host GDB.  */
00052 
00053 
00054 /* Different kinds of flaws an agent expression might have, as
00055    detected by ax_reqs.  */
00056 enum agent_flaws
00057   {
00058     agent_flaw_none = 0,        /* code is good */
00059 
00060     /* There is an invalid instruction in the stream.  */
00061     agent_flaw_bad_instruction,
00062 
00063     /* There is an incomplete instruction at the end of the expression.  */
00064     agent_flaw_incomplete_instruction,
00065 
00066     /* ax_reqs was unable to prove that every jump target is to a
00067        valid offset.  Valid offsets are within the bounds of the
00068        expression, and to a valid instruction boundary.  */
00069     agent_flaw_bad_jump,
00070 
00071     /* ax_reqs was unable to prove to its satisfaction that, for each
00072        jump target location, the stack will have the same height whether
00073        that location is reached via a jump or by straight execution.  */
00074     agent_flaw_height_mismatch,
00075 
00076     /* ax_reqs was unable to prove that every instruction following
00077        an unconditional jump was the target of some other jump.  */
00078     agent_flaw_hole
00079   };
00080 
00081 /* Agent expression data structures.  */
00082 
00083 /* The type of an element of the agent expression stack.
00084    The bytecode operation indicates which element we should access;
00085    the value itself has no typing information.  GDB generates all
00086    bytecode streams, so we don't have to worry about type errors.  */
00087 
00088 union agent_val
00089   {
00090     LONGEST l;
00091     DOUBLEST d;
00092   };
00093 
00094 /* A buffer containing a agent expression.  */
00095 struct agent_expr
00096   {
00097     /* The bytes of the expression.  */
00098     unsigned char *buf;
00099 
00100     /* The number of bytecode in the expression.  */
00101     int len;
00102 
00103     /* Allocated space available currently.  */
00104     int size;
00105 
00106     /* The target architecture assumed to be in effect.  */
00107     struct gdbarch *gdbarch;
00108 
00109     /* The address to which the expression applies.  */
00110     CORE_ADDR scope;
00111 
00112     /* If the following is not equal to agent_flaw_none, the rest of the
00113        information in this structure is suspect.  */
00114     enum agent_flaws flaw;
00115 
00116     /* Number of elements left on stack at end; may be negative if expr
00117        only consumes elements.  */
00118     int final_height;
00119 
00120     /* Maximum and minimum stack height, relative to initial height.  */
00121     int max_height, min_height;
00122 
00123     /* Largest `ref' or `const' opcode used, in bits.  Zero means the
00124        expression has no such instructions.  */
00125     int max_data_size;
00126 
00127     /* Bit vector of registers needed.  Register R is needed iff
00128 
00129        reg_mask[R / 8] & (1 << (R % 8))
00130 
00131        is non-zero.  Note!  You may not assume that this bitmask is long
00132        enough to hold bits for all the registers of the machine; the
00133        agent expression code has no idea how many registers the machine
00134        has.  However, the bitmask is reg_mask_len bytes long, so the
00135        valid register numbers run from 0 to reg_mask_len * 8 - 1.
00136 
00137        Also note that this mask may contain registers that are needed
00138        for the original collection expression to work, but that are
00139        not referenced by any bytecode.  This could, for example, occur
00140        when collecting a local variable allocated to a register; the
00141        compiler sets the mask bit and skips generating a bytecode whose
00142        result is going to be discarded anyway.
00143     */
00144     int reg_mask_len;
00145     unsigned char *reg_mask;
00146 
00147     /* For the data tracing facility, we need to insert `trace' bytecodes
00148        before each data fetch; this records all the memory that the
00149        expression touches in the course of evaluation, so that memory will
00150        be available when the user later tries to evaluate the expression
00151        in GDB.
00152 
00153        Setting the flag 'tracing' to non-zero enables the code that
00154        emits the trace bytecodes at the appropriate points.  */
00155 
00156     unsigned int tracing : 1;
00157 
00158     /* This indicates that pointers to chars should get an added
00159        tracenz bytecode to record nonzero bytes, up to a length that
00160        is the value of trace_string.  */
00161 
00162     int trace_string;
00163   };
00164 
00165 /* Pointer to an agent_expr structure.  */
00166 typedef struct agent_expr *agent_expr_p;
00167 
00168 /* Vector of pointers to agent expressions.  */
00169 DEF_VEC_P (agent_expr_p);
00170 
00171 /* The actual values of the various bytecode operations.  */
00172 
00173 enum agent_op
00174   {
00175 #define DEFOP(NAME, SIZE, DATA_SIZE, CONSUMED, PRODUCED, VALUE)  \
00176     aop_ ## NAME = VALUE,
00177 #include "ax.def"
00178 #undef DEFOP
00179     aop_last
00180   };
00181 
00182 
00183 
00184 /* Functions for building expressions.  */
00185 
00186 /* Allocate a new, empty agent expression.  */
00187 extern struct agent_expr *new_agent_expr (struct gdbarch *, CORE_ADDR);
00188 
00189 /* Free a agent expression.  */
00190 extern void free_agent_expr (struct agent_expr *);
00191 extern struct cleanup *make_cleanup_free_agent_expr (struct agent_expr *);
00192 
00193 /* Append a simple operator OP to EXPR.  */
00194 extern void ax_simple (struct agent_expr *EXPR, enum agent_op OP);
00195 
00196 /* Append a pick operator to EXPR.  DEPTH is the stack item to pick,
00197    with 0 being top of stack.  */
00198 extern void ax_pick (struct agent_expr *EXPR, int DEPTH);
00199 
00200 /* Append the floating-point prefix, for the next bytecode.  */
00201 #define ax_float(EXPR) (ax_simple ((EXPR), aop_float))
00202 
00203 /* Append a sign-extension instruction to EXPR, to extend an N-bit value.  */
00204 extern void ax_ext (struct agent_expr *EXPR, int N);
00205 
00206 /* Append a zero-extension instruction to EXPR, to extend an N-bit value.  */
00207 extern void ax_zero_ext (struct agent_expr *EXPR, int N);
00208 
00209 /* Append a trace_quick instruction to EXPR, to record N bytes.  */
00210 extern void ax_trace_quick (struct agent_expr *EXPR, int N);
00211 
00212 /* Append a goto op to EXPR.  OP is the actual op (must be aop_goto or
00213    aop_if_goto).  We assume we don't know the target offset yet,
00214    because it's probably a forward branch, so we leave space in EXPR
00215    for the target, and return the offset in EXPR of that space, so we
00216    can backpatch it once we do know the target offset.  Use ax_label
00217    to do the backpatching.  */
00218 extern int ax_goto (struct agent_expr *EXPR, enum agent_op OP);
00219 
00220 /* Suppose a given call to ax_goto returns some value PATCH.  When you
00221    know the offset TARGET that goto should jump to, call
00222    ax_label (EXPR, PATCH, TARGET)
00223    to patch TARGET into the ax_goto instruction.  */
00224 extern void ax_label (struct agent_expr *EXPR, int patch, int target);
00225 
00226 /* Assemble code to push a constant on the stack.  */
00227 extern void ax_const_l (struct agent_expr *EXPR, LONGEST l);
00228 extern void ax_const_d (struct agent_expr *EXPR, LONGEST d);
00229 
00230 /* Assemble code to push the value of register number REG on the
00231    stack.  */
00232 extern void ax_reg (struct agent_expr *EXPR, int REG);
00233 
00234 /* Add the given register to the register mask of the expression.  */
00235 extern void ax_reg_mask (struct agent_expr *ax, int reg);
00236 
00237 /* Assemble code to operate on a trace state variable.  */
00238 extern void ax_tsv (struct agent_expr *expr, enum agent_op op, int num);
00239 
00240 /* Append a string to the bytecode stream.  */
00241 extern void ax_string (struct agent_expr *x, const char *str, int slen);
00242 
00243 
00244 /* Functions for printing out expressions, and otherwise debugging
00245    things.  */
00246 
00247 /* Disassemble the expression EXPR, writing to F.  */
00248 extern void ax_print (struct ui_file *f, struct agent_expr * EXPR);
00249 
00250 /* An entry in the opcode map.  */
00251 struct aop_map
00252   {
00253 
00254     /* The name of the opcode.  Null means that this entry is not a
00255        valid opcode --- a hole in the opcode space.  */
00256     const char *name;
00257 
00258     /* All opcodes take no operands from the bytecode stream, or take
00259        unsigned integers of various sizes.  If this is a positive number
00260        n, then the opcode is followed by an n-byte operand, which should
00261        be printed as an unsigned integer.  If this is zero, then the
00262        opcode takes no operands from the bytecode stream.
00263 
00264        If we get more complicated opcodes in the future, don't add other
00265        magic values of this; that's a crock.  Add an `enum encoding'
00266        field to this, or something like that.  */
00267     int op_size;
00268 
00269     /* The size of the data operated upon, in bits, for bytecodes that
00270        care about that (ref and const).  Zero for all others.  */
00271     int data_size;
00272 
00273     /* Number of stack elements consumed, and number produced.  */
00274     int consumed, produced;
00275   };
00276 
00277 /* Map of the bytecodes, indexed by bytecode number.  */
00278 extern struct aop_map aop_map[];
00279 
00280 /* Given an agent expression AX, analyze and update its requirements.  */
00281 
00282 extern void ax_reqs (struct agent_expr *ax);
00283 
00284 #endif /* AGENTEXPR_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines