2012-01-20 Pedro Alves <palves@redhat.com>
[deliverable/binutils-gdb.git] / gdb / ax.h
CommitLineData
c906108c 1/* Definitions for expressions designed to be executed on the agent
0b302171 2 Copyright (C) 1998-2000, 2007-2012 Free Software Foundation, Inc.
c906108c 3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
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
a9762ec7 8 the Free Software Foundation; either version 3 of the License, or
c5aa993b 9 (at your option) any later version.
c906108c 10
c5aa993b
JM
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.
c906108c 15
c5aa993b 16 You should have received a copy of the GNU General Public License
a9762ec7 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 18
c906108c
SS
19#ifndef AGENTEXPR_H
20#define AGENTEXPR_H
21
d16aafd8
AC
22#include "doublest.h" /* For DOUBLEST. */
23
c906108c
SS
24/* It's sometimes useful to be able to debug programs that you can't
25 really stop for more than a fraction of a second. To this end, the
26 user can specify a tracepoint (like a breakpoint, but you don't
27 stop at it), and specify a bunch of expressions to record the
28 values of when that tracepoint is reached. As the program runs,
29 GDB collects the values. At any point (possibly while values are
30 still being collected), the user can display the collected values.
31
32 This is used with remote debugging; we don't really support it on
33 native configurations.
34
35 This means that expressions are being evaluated by the remote agent,
36 which doesn't have any access to the symbol table information, and
37 needs to be small and simple.
38
39 The agent_expr routines and datatypes are a bytecode language
40 designed to be executed by the agent. Agent expressions work in
41 terms of fixed-width values, operators, memory references, and
42 register references. You can evaluate a agent expression just given
43 a bunch of memory and register values to sniff at; you don't need
44 any symbolic information like variable names, types, etc.
45
46 GDB translates source expressions, whose meaning depends on
47 symbolic information, into agent bytecode expressions, whose meaning
48 is independent of symbolic information. This means the agent can
49 evaluate them on the fly without reference to data only available
50 to the host GDB. */
c906108c 51\f
c5aa993b 52
35c9c7ba
SS
53/* Different kinds of flaws an agent expression might have, as
54 detected by ax_reqs. */
55enum agent_flaws
56 {
57 agent_flaw_none = 0, /* code is good */
58
59 /* There is an invalid instruction in the stream. */
60 agent_flaw_bad_instruction,
61
62 /* There is an incomplete instruction at the end of the expression. */
63 agent_flaw_incomplete_instruction,
64
65 /* ax_reqs was unable to prove that every jump target is to a
66 valid offset. Valid offsets are within the bounds of the
67 expression, and to a valid instruction boundary. */
68 agent_flaw_bad_jump,
69
70 /* ax_reqs was unable to prove to its satisfaction that, for each
71 jump target location, the stack will have the same height whether
72 that location is reached via a jump or by straight execution. */
73 agent_flaw_height_mismatch,
74
75 /* ax_reqs was unable to prove that every instruction following
76 an unconditional jump was the target of some other jump. */
77 agent_flaw_hole
78 };
79
c906108c
SS
80/* Agent expression data structures. */
81
82/* The type of an element of the agent expression stack.
83 The bytecode operation indicates which element we should access;
84 the value itself has no typing information. GDB generates all
85 bytecode streams, so we don't have to worry about type errors. */
86
c5aa993b
JM
87union agent_val
88 {
89 LONGEST l;
90 DOUBLEST d;
91 };
c906108c
SS
92
93/* A buffer containing a agent expression. */
c5aa993b
JM
94struct agent_expr
95 {
35c9c7ba 96 /* The bytes of the expression. */
c5aa993b 97 unsigned char *buf;
35c9c7ba
SS
98
99 /* The number of bytecode in the expression. */
100 int len;
101
102 /* Allocated space available currently. */
103 int size;
104
105 /* The target architecture assumed to be in effect. */
106 struct gdbarch *gdbarch;
107
108 /* The address to which the expression applies. */
c5aa993b 109 CORE_ADDR scope;
c906108c 110
35c9c7ba
SS
111 /* If the following is not equal to agent_flaw_none, the rest of the
112 information in this structure is suspect. */
113 enum agent_flaws flaw;
114
115 /* Number of elements left on stack at end; may be negative if expr
116 only consumes elements. */
117 int final_height;
118
119 /* Maximum and minimum stack height, relative to initial height. */
120 int max_height, min_height;
121
122 /* Largest `ref' or `const' opcode used, in bits. Zero means the
123 expression has no such instructions. */
124 int max_data_size;
125
126 /* Bit vector of registers needed. Register R is needed iff
c906108c 127
35c9c7ba 128 reg_mask[R / 8] & (1 << (R % 8))
c906108c 129
35c9c7ba
SS
130 is non-zero. Note! You may not assume that this bitmask is long
131 enough to hold bits for all the registers of the machine; the
132 agent expression code has no idea how many registers the machine
133 has. However, the bitmask is reg_mask_len bytes long, so the
134 valid register numbers run from 0 to reg_mask_len * 8 - 1.
135
136 Also note that this mask may contain registers that are needed
137 for the original collection expression to work, but that are
138 not referenced by any bytecode. This could, for example, occur
139 when collecting a local variable allocated to a register; the
140 compiler sets the mask bit and skips generating a bytecode whose
141 result is going to be discarded anyway.
142 */
143 int reg_mask_len;
144 unsigned char *reg_mask;
145 };
c906108c 146
94d5e490 147/* The actual values of the various bytecode operations. */
c906108c 148
c5aa993b
JM
149enum agent_op
150 {
94d5e490
TT
151#define DEFOP(NAME, SIZE, DATA_SIZE, CONSUMED, PRODUCED, VALUE) \
152 aop_ ## NAME = VALUE,
153#include "ax.def"
154#undef DEFOP
c5aa993b
JM
155 aop_last
156 };
157\f
c906108c
SS
158
159
c906108c
SS
160/* Functions for building expressions. */
161
162/* Allocate a new, empty agent expression. */
35c9c7ba 163extern struct agent_expr *new_agent_expr (struct gdbarch *, CORE_ADDR);
c906108c
SS
164
165/* Free a agent expression. */
a14ed312 166extern void free_agent_expr (struct agent_expr *);
f23d52e0 167extern struct cleanup *make_cleanup_free_agent_expr (struct agent_expr *);
c906108c
SS
168
169/* Append a simple operator OP to EXPR. */
a14ed312 170extern void ax_simple (struct agent_expr *EXPR, enum agent_op OP);
c906108c 171
c7f96d2b
TT
172/* Append a pick operator to EXPR. DEPTH is the stack item to pick,
173 with 0 being top of stack. */
174extern void ax_pick (struct agent_expr *EXPR, int DEPTH);
175
c906108c
SS
176/* Append the floating-point prefix, for the next bytecode. */
177#define ax_float(EXPR) (ax_simple ((EXPR), aop_float))
178
179/* Append a sign-extension instruction to EXPR, to extend an N-bit value. */
a14ed312 180extern void ax_ext (struct agent_expr *EXPR, int N);
c906108c
SS
181
182/* Append a zero-extension instruction to EXPR, to extend an N-bit value. */
a14ed312 183extern void ax_zero_ext (struct agent_expr *EXPR, int N);
c906108c
SS
184
185/* Append a trace_quick instruction to EXPR, to record N bytes. */
a14ed312 186extern void ax_trace_quick (struct agent_expr *EXPR, int N);
c906108c
SS
187
188/* Append a goto op to EXPR. OP is the actual op (must be aop_goto or
189 aop_if_goto). We assume we don't know the target offset yet,
190 because it's probably a forward branch, so we leave space in EXPR
191 for the target, and return the offset in EXPR of that space, so we
192 can backpatch it once we do know the target offset. Use ax_label
193 to do the backpatching. */
a14ed312 194extern int ax_goto (struct agent_expr *EXPR, enum agent_op OP);
c906108c
SS
195
196/* Suppose a given call to ax_goto returns some value PATCH. When you
197 know the offset TARGET that goto should jump to, call
c5aa993b 198 ax_label (EXPR, PATCH, TARGET)
c906108c 199 to patch TARGET into the ax_goto instruction. */
a14ed312 200extern void ax_label (struct agent_expr *EXPR, int patch, int target);
c906108c
SS
201
202/* Assemble code to push a constant on the stack. */
a14ed312
KB
203extern void ax_const_l (struct agent_expr *EXPR, LONGEST l);
204extern void ax_const_d (struct agent_expr *EXPR, LONGEST d);
c906108c
SS
205
206/* Assemble code to push the value of register number REG on the
207 stack. */
a14ed312 208extern void ax_reg (struct agent_expr *EXPR, int REG);
f61e138d 209
35c9c7ba
SS
210/* Add the given register to the register mask of the expression. */
211extern void ax_reg_mask (struct agent_expr *ax, int reg);
212
f61e138d
SS
213/* Assemble code to operate on a trace state variable. */
214extern void ax_tsv (struct agent_expr *expr, enum agent_op op, int num);
c906108c 215\f
c5aa993b 216
c906108c
SS
217/* Functions for printing out expressions, and otherwise debugging
218 things. */
219
220/* Disassemble the expression EXPR, writing to F. */
d9fcf2fb 221extern void ax_print (struct ui_file *f, struct agent_expr * EXPR);
c906108c
SS
222
223/* An entry in the opcode map. */
c5aa993b
JM
224struct aop_map
225 {
c906108c 226
c5aa993b
JM
227 /* The name of the opcode. Null means that this entry is not a
228 valid opcode --- a hole in the opcode space. */
5f1e6f19 229 const char *name;
c906108c 230
c5aa993b
JM
231 /* All opcodes take no operands from the bytecode stream, or take
232 unsigned integers of various sizes. If this is a positive number
233 n, then the opcode is followed by an n-byte operand, which should
234 be printed as an unsigned integer. If this is zero, then the
235 opcode takes no operands from the bytecode stream.
c906108c 236
c5aa993b
JM
237 If we get more complicated opcodes in the future, don't add other
238 magic values of this; that's a crock. Add an `enum encoding'
239 field to this, or something like that. */
240 int op_size;
c906108c 241
c5aa993b
JM
242 /* The size of the data operated upon, in bits, for bytecodes that
243 care about that (ref and const). Zero for all others. */
244 int data_size;
c906108c 245
c5aa993b
JM
246 /* Number of stack elements consumed, and number produced. */
247 int consumed, produced;
248 };
c906108c
SS
249
250/* Map of the bytecodes, indexed by bytecode number. */
251extern struct aop_map aop_map[];
252
35c9c7ba 253/* Given an agent expression AX, analyze and update its requirements. */
c906108c 254
35c9c7ba 255extern void ax_reqs (struct agent_expr *ax);
c906108c
SS
256
257#endif /* AGENTEXPR_H */
This page took 0.669034 seconds and 4 git commands to generate.