gdb/ax.h - gdb

Global variables defined

Data types defined

Macros defined

Source code

  1. /* Definitions for expressions designed to be executed on the agent
  2.    Copyright (C) 1998-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #ifndef AGENTEXPR_H
  15. #define AGENTEXPR_H

  16. #include "doublest.h"                /* For DOUBLEST.  */
  17. #include "vec.h"

  18. /* It's sometimes useful to be able to debug programs that you can't
  19.    really stop for more than a fraction of a second.  To this end, the
  20.    user can specify a tracepoint (like a breakpoint, but you don't
  21.    stop at it), and specify a bunch of expressions to record the
  22.    values of when that tracepoint is reached.  As the program runs,
  23.    GDB collects the values.  At any point (possibly while values are
  24.    still being collected), the user can display the collected values.

  25.    This is used with remote debugging; we don't really support it on
  26.    native configurations.

  27.    This means that expressions are being evaluated by the remote agent,
  28.    which doesn't have any access to the symbol table information, and
  29.    needs to be small and simple.

  30.    The agent_expr routines and datatypes are a bytecode language
  31.    designed to be executed by the agent.  Agent expressions work in
  32.    terms of fixed-width values, operators, memory references, and
  33.    register references.  You can evaluate a agent expression just given
  34.    a bunch of memory and register values to sniff at; you don't need
  35.    any symbolic information like variable names, types, etc.

  36.    GDB translates source expressions, whose meaning depends on
  37.    symbolic information, into agent bytecode expressions, whose meaning
  38.    is independent of symbolic information.  This means the agent can
  39.    evaluate them on the fly without reference to data only available
  40.    to the host GDB.  */


  41. /* Different kinds of flaws an agent expression might have, as
  42.    detected by ax_reqs.  */
  43. enum agent_flaws
  44.   {
  45.     agent_flaw_none = 0,        /* code is good */

  46.     /* There is an invalid instruction in the stream.  */
  47.     agent_flaw_bad_instruction,

  48.     /* There is an incomplete instruction at the end of the expression.  */
  49.     agent_flaw_incomplete_instruction,

  50.     /* ax_reqs was unable to prove that every jump target is to a
  51.        valid offset.  Valid offsets are within the bounds of the
  52.        expression, and to a valid instruction boundary.  */
  53.     agent_flaw_bad_jump,

  54.     /* ax_reqs was unable to prove to its satisfaction that, for each
  55.        jump target location, the stack will have the same height whether
  56.        that location is reached via a jump or by straight execution.  */
  57.     agent_flaw_height_mismatch,

  58.     /* ax_reqs was unable to prove that every instruction following
  59.        an unconditional jump was the target of some other jump.  */
  60.     agent_flaw_hole
  61.   };

  62. /* Agent expression data structures.  */

  63. /* The type of an element of the agent expression stack.
  64.    The bytecode operation indicates which element we should access;
  65.    the value itself has no typing information.  GDB generates all
  66.    bytecode streams, so we don't have to worry about type errors.  */

  67. union agent_val
  68.   {
  69.     LONGEST l;
  70.     DOUBLEST d;
  71.   };

  72. /* A buffer containing a agent expression.  */
  73. struct agent_expr
  74.   {
  75.     /* The bytes of the expression.  */
  76.     unsigned char *buf;

  77.     /* The number of bytecode in the expression.  */
  78.     int len;

  79.     /* Allocated space available currently.  */
  80.     int size;

  81.     /* The target architecture assumed to be in effect.  */
  82.     struct gdbarch *gdbarch;

  83.     /* The address to which the expression applies.  */
  84.     CORE_ADDR scope;

  85.     /* If the following is not equal to agent_flaw_none, the rest of the
  86.        information in this structure is suspect.  */
  87.     enum agent_flaws flaw;

  88.     /* Number of elements left on stack at end; may be negative if expr
  89.        only consumes elements.  */
  90.     int final_height;

  91.     /* Maximum and minimum stack height, relative to initial height.  */
  92.     int max_height, min_height;

  93.     /* Largest `ref' or `const' opcode used, in bits.  Zero means the
  94.        expression has no such instructions.  */
  95.     int max_data_size;

  96.     /* Bit vector of registers needed.  Register R is needed iff

  97.        reg_mask[R / 8] & (1 << (R % 8))

  98.        is non-zero.  Note!  You may not assume that this bitmask is long
  99.        enough to hold bits for all the registers of the machine; the
  100.        agent expression code has no idea how many registers the machine
  101.        has.  However, the bitmask is reg_mask_len bytes long, so the
  102.        valid register numbers run from 0 to reg_mask_len * 8 - 1.

  103.        Also note that this mask may contain registers that are needed
  104.        for the original collection expression to work, but that are
  105.        not referenced by any bytecode.  This could, for example, occur
  106.        when collecting a local variable allocated to a register; the
  107.        compiler sets the mask bit and skips generating a bytecode whose
  108.        result is going to be discarded anyway.
  109.     */
  110.     int reg_mask_len;
  111.     unsigned char *reg_mask;

  112.     /* For the data tracing facility, we need to insert `trace' bytecodes
  113.        before each data fetch; this records all the memory that the
  114.        expression touches in the course of evaluation, so that memory will
  115.        be available when the user later tries to evaluate the expression
  116.        in GDB.

  117.        Setting the flag 'tracing' to non-zero enables the code that
  118.        emits the trace bytecodes at the appropriate points.  */

  119.     unsigned int tracing : 1;

  120.     /* This indicates that pointers to chars should get an added
  121.        tracenz bytecode to record nonzero bytes, up to a length that
  122.        is the value of trace_string.  */

  123.     int trace_string;
  124.   };

  125. /* Pointer to an agent_expr structure.  */
  126. typedef struct agent_expr *agent_expr_p;

  127. /* Vector of pointers to agent expressions.  */
  128. DEF_VEC_P (agent_expr_p);

  129. /* The actual values of the various bytecode operations.  */

  130. enum agent_op
  131.   {
  132. #define DEFOP(NAME, SIZE, DATA_SIZE, CONSUMED, PRODUCED, VALUE)  \
  133.     aop_ ## NAME = VALUE,
  134. #include "ax.def"
  135. #undef DEFOP
  136.     aop_last
  137.   };



  138. /* Functions for building expressions.  */

  139. /* Allocate a new, empty agent expression.  */
  140. extern struct agent_expr *new_agent_expr (struct gdbarch *, CORE_ADDR);

  141. /* Free a agent expression.  */
  142. extern void free_agent_expr (struct agent_expr *);
  143. extern struct cleanup *make_cleanup_free_agent_expr (struct agent_expr *);

  144. /* Append a simple operator OP to EXPR.  */
  145. extern void ax_simple (struct agent_expr *EXPR, enum agent_op OP);

  146. /* Append a pick operator to EXPR.  DEPTH is the stack item to pick,
  147.    with 0 being top of stack.  */
  148. extern void ax_pick (struct agent_expr *EXPR, int DEPTH);

  149. /* Append the floating-point prefix, for the next bytecode.  */
  150. #define ax_float(EXPR) (ax_simple ((EXPR), aop_float))

  151. /* Append a sign-extension instruction to EXPR, to extend an N-bit value.  */
  152. extern void ax_ext (struct agent_expr *EXPR, int N);

  153. /* Append a zero-extension instruction to EXPR, to extend an N-bit value.  */
  154. extern void ax_zero_ext (struct agent_expr *EXPR, int N);

  155. /* Append a trace_quick instruction to EXPR, to record N bytes.  */
  156. extern void ax_trace_quick (struct agent_expr *EXPR, int N);

  157. /* Append a goto op to EXPR.  OP is the actual op (must be aop_goto or
  158.    aop_if_goto).  We assume we don't know the target offset yet,
  159.    because it's probably a forward branch, so we leave space in EXPR
  160.    for the target, and return the offset in EXPR of that space, so we
  161.    can backpatch it once we do know the target offset.  Use ax_label
  162.    to do the backpatching.  */
  163. extern int ax_goto (struct agent_expr *EXPR, enum agent_op OP);

  164. /* Suppose a given call to ax_goto returns some value PATCH.  When you
  165.    know the offset TARGET that goto should jump to, call
  166.    ax_label (EXPR, PATCH, TARGET)
  167.    to patch TARGET into the ax_goto instruction.  */
  168. extern void ax_label (struct agent_expr *EXPR, int patch, int target);

  169. /* Assemble code to push a constant on the stack.  */
  170. extern void ax_const_l (struct agent_expr *EXPR, LONGEST l);
  171. extern void ax_const_d (struct agent_expr *EXPR, LONGEST d);

  172. /* Assemble code to push the value of register number REG on the
  173.    stack.  */
  174. extern void ax_reg (struct agent_expr *EXPR, int REG);

  175. /* Add the given register to the register mask of the expression.  */
  176. extern void ax_reg_mask (struct agent_expr *ax, int reg);

  177. /* Assemble code to operate on a trace state variable.  */
  178. extern void ax_tsv (struct agent_expr *expr, enum agent_op op, int num);

  179. /* Append a string to the bytecode stream.  */
  180. extern void ax_string (struct agent_expr *x, const char *str, int slen);


  181. /* Functions for printing out expressions, and otherwise debugging
  182.    things.  */

  183. /* Disassemble the expression EXPR, writing to F.  */
  184. extern void ax_print (struct ui_file *f, struct agent_expr * EXPR);

  185. /* An entry in the opcode map.  */
  186. struct aop_map
  187.   {

  188.     /* The name of the opcode.  Null means that this entry is not a
  189.        valid opcode --- a hole in the opcode space.  */
  190.     const char *name;

  191.     /* All opcodes take no operands from the bytecode stream, or take
  192.        unsigned integers of various sizes.  If this is a positive number
  193.        n, then the opcode is followed by an n-byte operand, which should
  194.        be printed as an unsigned integer.  If this is zero, then the
  195.        opcode takes no operands from the bytecode stream.

  196.        If we get more complicated opcodes in the future, don't add other
  197.        magic values of this; that's a crock.  Add an `enum encoding'
  198.        field to this, or something like that.  */
  199.     int op_size;

  200.     /* The size of the data operated upon, in bits, for bytecodes that
  201.        care about that (ref and const).  Zero for all others.  */
  202.     int data_size;

  203.     /* Number of stack elements consumed, and number produced.  */
  204.     int consumed, produced;
  205.   };

  206. /* Map of the bytecodes, indexed by bytecode number.  */
  207. extern struct aop_map aop_map[];

  208. /* Given an agent expression AX, analyze and update its requirements.  */

  209. extern void ax_reqs (struct agent_expr *ax);

  210. #endif /* AGENTEXPR_H */