]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/ax.h
bfd/
[thirdparty/binutils-gdb.git] / gdb / ax.h
1 /* Definitions for expressions designed to be executed on the agent
2 Copyright (C) 1998, 1999, 2000, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef AGENTEXPR_H
21 #define AGENTEXPR_H
22
23 #include "doublest.h" /* For DOUBLEST. */
24
25 /* It's sometimes useful to be able to debug programs that you can't
26 really stop for more than a fraction of a second. To this end, the
27 user can specify a tracepoint (like a breakpoint, but you don't
28 stop at it), and specify a bunch of expressions to record the
29 values of when that tracepoint is reached. As the program runs,
30 GDB collects the values. At any point (possibly while values are
31 still being collected), the user can display the collected values.
32
33 This is used with remote debugging; we don't really support it on
34 native configurations.
35
36 This means that expressions are being evaluated by the remote agent,
37 which doesn't have any access to the symbol table information, and
38 needs to be small and simple.
39
40 The agent_expr routines and datatypes are a bytecode language
41 designed to be executed by the agent. Agent expressions work in
42 terms of fixed-width values, operators, memory references, and
43 register references. You can evaluate a agent expression just given
44 a bunch of memory and register values to sniff at; you don't need
45 any symbolic information like variable names, types, etc.
46
47 GDB translates source expressions, whose meaning depends on
48 symbolic information, into agent bytecode expressions, whose meaning
49 is independent of symbolic information. This means the agent can
50 evaluate them on the fly without reference to data only available
51 to the host GDB. */
52 \f
53
54 /* Different kinds of flaws an agent expression might have, as
55 detected by ax_reqs. */
56 enum agent_flaws
57 {
58 agent_flaw_none = 0, /* code is good */
59
60 /* There is an invalid instruction in the stream. */
61 agent_flaw_bad_instruction,
62
63 /* There is an incomplete instruction at the end of the expression. */
64 agent_flaw_incomplete_instruction,
65
66 /* ax_reqs was unable to prove that every jump target is to a
67 valid offset. Valid offsets are within the bounds of the
68 expression, and to a valid instruction boundary. */
69 agent_flaw_bad_jump,
70
71 /* ax_reqs was unable to prove to its satisfaction that, for each
72 jump target location, the stack will have the same height whether
73 that location is reached via a jump or by straight execution. */
74 agent_flaw_height_mismatch,
75
76 /* ax_reqs was unable to prove that every instruction following
77 an unconditional jump was the target of some other jump. */
78 agent_flaw_hole
79 };
80
81 /* Agent expression data structures. */
82
83 /* The type of an element of the agent expression stack.
84 The bytecode operation indicates which element we should access;
85 the value itself has no typing information. GDB generates all
86 bytecode streams, so we don't have to worry about type errors. */
87
88 union agent_val
89 {
90 LONGEST l;
91 DOUBLEST d;
92 };
93
94 /* A buffer containing a agent expression. */
95 struct agent_expr
96 {
97 /* The bytes of the expression. */
98 unsigned char *buf;
99
100 /* The number of bytecode in the expression. */
101 int len;
102
103 /* Allocated space available currently. */
104 int size;
105
106 /* The target architecture assumed to be in effect. */
107 struct gdbarch *gdbarch;
108
109 /* The address to which the expression applies. */
110 CORE_ADDR scope;
111
112 /* If the following is not equal to agent_flaw_none, the rest of the
113 information in this structure is suspect. */
114 enum agent_flaws flaw;
115
116 /* Number of elements left on stack at end; may be negative if expr
117 only consumes elements. */
118 int final_height;
119
120 /* Maximum and minimum stack height, relative to initial height. */
121 int max_height, min_height;
122
123 /* Largest `ref' or `const' opcode used, in bits. Zero means the
124 expression has no such instructions. */
125 int max_data_size;
126
127 /* Bit vector of registers needed. Register R is needed iff
128
129 reg_mask[R / 8] & (1 << (R % 8))
130
131 is non-zero. Note! You may not assume that this bitmask is long
132 enough to hold bits for all the registers of the machine; the
133 agent expression code has no idea how many registers the machine
134 has. However, the bitmask is reg_mask_len bytes long, so the
135 valid register numbers run from 0 to reg_mask_len * 8 - 1.
136
137 Also note that this mask may contain registers that are needed
138 for the original collection expression to work, but that are
139 not referenced by any bytecode. This could, for example, occur
140 when collecting a local variable allocated to a register; the
141 compiler sets the mask bit and skips generating a bytecode whose
142 result is going to be discarded anyway.
143 */
144 int reg_mask_len;
145 unsigned char *reg_mask;
146 };
147
148 /* The actual values of the various bytecode operations.
149
150 Other independent implementations of the agent bytecode engine will
151 rely on the exact values of these enums, and may not be recompiled
152 when we change this table. The numeric values should remain fixed
153 whenever possible. Thus, we assign them values explicitly here (to
154 allow gaps to form safely), and the disassembly table in
155 agentexpr.h behaves like an opcode map. If you want to see them
156 grouped logically, see doc/agentexpr.texi. */
157
158 enum agent_op
159 {
160 aop_float = 0x01,
161 aop_add = 0x02,
162 aop_sub = 0x03,
163 aop_mul = 0x04,
164 aop_div_signed = 0x05,
165 aop_div_unsigned = 0x06,
166 aop_rem_signed = 0x07,
167 aop_rem_unsigned = 0x08,
168 aop_lsh = 0x09,
169 aop_rsh_signed = 0x0a,
170 aop_rsh_unsigned = 0x0b,
171 aop_trace = 0x0c,
172 aop_trace_quick = 0x0d,
173 aop_log_not = 0x0e,
174 aop_bit_and = 0x0f,
175 aop_bit_or = 0x10,
176 aop_bit_xor = 0x11,
177 aop_bit_not = 0x12,
178 aop_equal = 0x13,
179 aop_less_signed = 0x14,
180 aop_less_unsigned = 0x15,
181 aop_ext = 0x16,
182 aop_ref8 = 0x17,
183 aop_ref16 = 0x18,
184 aop_ref32 = 0x19,
185 aop_ref64 = 0x1a,
186 aop_ref_float = 0x1b,
187 aop_ref_double = 0x1c,
188 aop_ref_long_double = 0x1d,
189 aop_l_to_d = 0x1e,
190 aop_d_to_l = 0x1f,
191 aop_if_goto = 0x20,
192 aop_goto = 0x21,
193 aop_const8 = 0x22,
194 aop_const16 = 0x23,
195 aop_const32 = 0x24,
196 aop_const64 = 0x25,
197 aop_reg = 0x26,
198 aop_end = 0x27,
199 aop_dup = 0x28,
200 aop_pop = 0x29,
201 aop_zero_ext = 0x2a,
202 aop_swap = 0x2b,
203 aop_getv = 0x2c,
204 aop_setv = 0x2d,
205 aop_tracev = 0x2e,
206 aop_trace16 = 0x30,
207 aop_last
208 };
209 \f
210
211
212 /* Functions for building expressions. */
213
214 /* Allocate a new, empty agent expression. */
215 extern struct agent_expr *new_agent_expr (struct gdbarch *, CORE_ADDR);
216
217 /* Free a agent expression. */
218 extern void free_agent_expr (struct agent_expr *);
219 extern struct cleanup *make_cleanup_free_agent_expr (struct agent_expr *);
220
221 /* Append a simple operator OP to EXPR. */
222 extern void ax_simple (struct agent_expr *EXPR, enum agent_op OP);
223
224 /* Append the floating-point prefix, for the next bytecode. */
225 #define ax_float(EXPR) (ax_simple ((EXPR), aop_float))
226
227 /* Append a sign-extension instruction to EXPR, to extend an N-bit value. */
228 extern void ax_ext (struct agent_expr *EXPR, int N);
229
230 /* Append a zero-extension instruction to EXPR, to extend an N-bit value. */
231 extern void ax_zero_ext (struct agent_expr *EXPR, int N);
232
233 /* Append a trace_quick instruction to EXPR, to record N bytes. */
234 extern void ax_trace_quick (struct agent_expr *EXPR, int N);
235
236 /* Append a goto op to EXPR. OP is the actual op (must be aop_goto or
237 aop_if_goto). We assume we don't know the target offset yet,
238 because it's probably a forward branch, so we leave space in EXPR
239 for the target, and return the offset in EXPR of that space, so we
240 can backpatch it once we do know the target offset. Use ax_label
241 to do the backpatching. */
242 extern int ax_goto (struct agent_expr *EXPR, enum agent_op OP);
243
244 /* Suppose a given call to ax_goto returns some value PATCH. When you
245 know the offset TARGET that goto should jump to, call
246 ax_label (EXPR, PATCH, TARGET)
247 to patch TARGET into the ax_goto instruction. */
248 extern void ax_label (struct agent_expr *EXPR, int patch, int target);
249
250 /* Assemble code to push a constant on the stack. */
251 extern void ax_const_l (struct agent_expr *EXPR, LONGEST l);
252 extern void ax_const_d (struct agent_expr *EXPR, LONGEST d);
253
254 /* Assemble code to push the value of register number REG on the
255 stack. */
256 extern void ax_reg (struct agent_expr *EXPR, int REG);
257
258 /* Add the given register to the register mask of the expression. */
259 extern void ax_reg_mask (struct agent_expr *ax, int reg);
260
261 /* Assemble code to operate on a trace state variable. */
262 extern void ax_tsv (struct agent_expr *expr, enum agent_op op, int num);
263 \f
264
265 /* Functions for printing out expressions, and otherwise debugging
266 things. */
267
268 /* Disassemble the expression EXPR, writing to F. */
269 extern void ax_print (struct ui_file *f, struct agent_expr * EXPR);
270
271 /* An entry in the opcode map. */
272 struct aop_map
273 {
274
275 /* The name of the opcode. Null means that this entry is not a
276 valid opcode --- a hole in the opcode space. */
277 char *name;
278
279 /* All opcodes take no operands from the bytecode stream, or take
280 unsigned integers of various sizes. If this is a positive number
281 n, then the opcode is followed by an n-byte operand, which should
282 be printed as an unsigned integer. If this is zero, then the
283 opcode takes no operands from the bytecode stream.
284
285 If we get more complicated opcodes in the future, don't add other
286 magic values of this; that's a crock. Add an `enum encoding'
287 field to this, or something like that. */
288 int op_size;
289
290 /* The size of the data operated upon, in bits, for bytecodes that
291 care about that (ref and const). Zero for all others. */
292 int data_size;
293
294 /* Number of stack elements consumed, and number produced. */
295 int consumed, produced;
296 };
297
298 /* Map of the bytecodes, indexed by bytecode number. */
299 extern struct aop_map aop_map[];
300
301 /* Given an agent expression AX, analyze and update its requirements. */
302
303 extern void ax_reqs (struct agent_expr *ax);
304
305 #endif /* AGENTEXPR_H */