Use memmove to copy overlap memory.
[deliverable/binutils-gdb.git] / gdb / ax.h
CommitLineData
c906108c 1/* Definitions for expressions designed to be executed on the agent
4c38e0a4 2 Copyright (C) 1998, 1999, 2000, 2007, 2008, 2009, 2010
0fb0cc75 3 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 19
c906108c
SS
20#ifndef AGENTEXPR_H
21#define AGENTEXPR_H
22
d16aafd8
AC
23#include "doublest.h" /* For DOUBLEST. */
24
c906108c
SS
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. */
c906108c 52\f
c5aa993b 53
c906108c
SS
54/* Agent expression data structures. */
55
56/* The type of an element of the agent expression stack.
57 The bytecode operation indicates which element we should access;
58 the value itself has no typing information. GDB generates all
59 bytecode streams, so we don't have to worry about type errors. */
60
c5aa993b
JM
61union agent_val
62 {
63 LONGEST l;
64 DOUBLEST d;
65 };
c906108c
SS
66
67/* A buffer containing a agent expression. */
c5aa993b
JM
68struct agent_expr
69 {
70 unsigned char *buf;
71 int len; /* number of characters used */
72 int size; /* allocated size */
73 CORE_ADDR scope;
74 };
c906108c
SS
75
76
77
78
79/* The actual values of the various bytecode operations.
80
81 Other independent implementations of the agent bytecode engine will
82 rely on the exact values of these enums, and may not be recompiled
83 when we change this table. The numeric values should remain fixed
84 whenever possible. Thus, we assign them values explicitly here (to
85 allow gaps to form safely), and the disassembly table in
86 agentexpr.h behaves like an opcode map. If you want to see them
87 grouped logically, see doc/agentexpr.texi. */
88
c5aa993b
JM
89enum agent_op
90 {
91 aop_float = 0x01,
92 aop_add = 0x02,
93 aop_sub = 0x03,
94 aop_mul = 0x04,
95 aop_div_signed = 0x05,
96 aop_div_unsigned = 0x06,
97 aop_rem_signed = 0x07,
98 aop_rem_unsigned = 0x08,
99 aop_lsh = 0x09,
100 aop_rsh_signed = 0x0a,
101 aop_rsh_unsigned = 0x0b,
102 aop_trace = 0x0c,
103 aop_trace_quick = 0x0d,
104 aop_log_not = 0x0e,
105 aop_bit_and = 0x0f,
106 aop_bit_or = 0x10,
107 aop_bit_xor = 0x11,
108 aop_bit_not = 0x12,
109 aop_equal = 0x13,
110 aop_less_signed = 0x14,
111 aop_less_unsigned = 0x15,
112 aop_ext = 0x16,
113 aop_ref8 = 0x17,
114 aop_ref16 = 0x18,
115 aop_ref32 = 0x19,
116 aop_ref64 = 0x1a,
117 aop_ref_float = 0x1b,
118 aop_ref_double = 0x1c,
119 aop_ref_long_double = 0x1d,
120 aop_l_to_d = 0x1e,
121 aop_d_to_l = 0x1f,
122 aop_if_goto = 0x20,
123 aop_goto = 0x21,
124 aop_const8 = 0x22,
125 aop_const16 = 0x23,
126 aop_const32 = 0x24,
127 aop_const64 = 0x25,
128 aop_reg = 0x26,
129 aop_end = 0x27,
130 aop_dup = 0x28,
131 aop_pop = 0x29,
132 aop_zero_ext = 0x2a,
133 aop_swap = 0x2b,
f61e138d
SS
134 aop_getv = 0x2c,
135 aop_setv = 0x2d,
136 aop_tracev = 0x2e,
c5aa993b
JM
137 aop_trace16 = 0x30,
138 aop_last
139 };
140\f
c906108c
SS
141
142
c906108c
SS
143/* Functions for building expressions. */
144
145/* Allocate a new, empty agent expression. */
a14ed312 146extern struct agent_expr *new_agent_expr (CORE_ADDR);
c906108c
SS
147
148/* Free a agent expression. */
a14ed312 149extern void free_agent_expr (struct agent_expr *);
f23d52e0 150extern struct cleanup *make_cleanup_free_agent_expr (struct agent_expr *);
c906108c
SS
151
152/* Append a simple operator OP to EXPR. */
a14ed312 153extern void ax_simple (struct agent_expr *EXPR, enum agent_op OP);
c906108c
SS
154
155/* Append the floating-point prefix, for the next bytecode. */
156#define ax_float(EXPR) (ax_simple ((EXPR), aop_float))
157
158/* Append a sign-extension instruction to EXPR, to extend an N-bit value. */
a14ed312 159extern void ax_ext (struct agent_expr *EXPR, int N);
c906108c
SS
160
161/* Append a zero-extension instruction to EXPR, to extend an N-bit value. */
a14ed312 162extern void ax_zero_ext (struct agent_expr *EXPR, int N);
c906108c
SS
163
164/* Append a trace_quick instruction to EXPR, to record N bytes. */
a14ed312 165extern void ax_trace_quick (struct agent_expr *EXPR, int N);
c906108c
SS
166
167/* Append a goto op to EXPR. OP is the actual op (must be aop_goto or
168 aop_if_goto). We assume we don't know the target offset yet,
169 because it's probably a forward branch, so we leave space in EXPR
170 for the target, and return the offset in EXPR of that space, so we
171 can backpatch it once we do know the target offset. Use ax_label
172 to do the backpatching. */
a14ed312 173extern int ax_goto (struct agent_expr *EXPR, enum agent_op OP);
c906108c
SS
174
175/* Suppose a given call to ax_goto returns some value PATCH. When you
176 know the offset TARGET that goto should jump to, call
c5aa993b 177 ax_label (EXPR, PATCH, TARGET)
c906108c 178 to patch TARGET into the ax_goto instruction. */
a14ed312 179extern void ax_label (struct agent_expr *EXPR, int patch, int target);
c906108c
SS
180
181/* Assemble code to push a constant on the stack. */
a14ed312
KB
182extern void ax_const_l (struct agent_expr *EXPR, LONGEST l);
183extern void ax_const_d (struct agent_expr *EXPR, LONGEST d);
c906108c
SS
184
185/* Assemble code to push the value of register number REG on the
186 stack. */
a14ed312 187extern void ax_reg (struct agent_expr *EXPR, int REG);
f61e138d
SS
188
189/* Assemble code to operate on a trace state variable. */
190extern void ax_tsv (struct agent_expr *expr, enum agent_op op, int num);
c906108c 191\f
c5aa993b 192
c906108c
SS
193/* Functions for printing out expressions, and otherwise debugging
194 things. */
195
196/* Disassemble the expression EXPR, writing to F. */
d9fcf2fb 197extern void ax_print (struct ui_file *f, struct agent_expr * EXPR);
c906108c
SS
198
199/* An entry in the opcode map. */
c5aa993b
JM
200struct aop_map
201 {
c906108c 202
c5aa993b
JM
203 /* The name of the opcode. Null means that this entry is not a
204 valid opcode --- a hole in the opcode space. */
205 char *name;
c906108c 206
c5aa993b
JM
207 /* All opcodes take no operands from the bytecode stream, or take
208 unsigned integers of various sizes. If this is a positive number
209 n, then the opcode is followed by an n-byte operand, which should
210 be printed as an unsigned integer. If this is zero, then the
211 opcode takes no operands from the bytecode stream.
c906108c 212
c5aa993b
JM
213 If we get more complicated opcodes in the future, don't add other
214 magic values of this; that's a crock. Add an `enum encoding'
215 field to this, or something like that. */
216 int op_size;
c906108c 217
c5aa993b
JM
218 /* The size of the data operated upon, in bits, for bytecodes that
219 care about that (ref and const). Zero for all others. */
220 int data_size;
c906108c 221
c5aa993b
JM
222 /* Number of stack elements consumed, and number produced. */
223 int consumed, produced;
224 };
c906108c
SS
225
226/* Map of the bytecodes, indexed by bytecode number. */
227extern struct aop_map aop_map[];
228
229/* Different kinds of flaws an agent expression might have, as
230 detected by agent_reqs. */
c5aa993b
JM
231enum agent_flaws
232 {
233 agent_flaw_none = 0, /* code is good */
c906108c 234
c5aa993b
JM
235 /* There is an invalid instruction in the stream. */
236 agent_flaw_bad_instruction,
c906108c 237
c5aa993b
JM
238 /* There is an incomplete instruction at the end of the expression. */
239 agent_flaw_incomplete_instruction,
c906108c 240
c5aa993b
JM
241 /* agent_reqs was unable to prove that every jump target is to a
242 valid offset. Valid offsets are within the bounds of the
243 expression, and to a valid instruction boundary. */
244 agent_flaw_bad_jump,
c906108c 245
c5aa993b
JM
246 /* agent_reqs was unable to prove to its satisfaction that, for each
247 jump target location, the stack will have the same height whether
248 that location is reached via a jump or by straight execution. */
249 agent_flaw_height_mismatch,
c906108c 250
c5aa993b
JM
251 /* agent_reqs was unable to prove that every instruction following
252 an unconditional jump was the target of some other jump. */
253 agent_flaw_hole
254 };
c906108c
SS
255
256/* Structure describing the requirements of a bytecode expression. */
c5aa993b
JM
257struct agent_reqs
258 {
259
260 /* If the following is not equal to agent_flaw_none, the rest of the
261 information in this structure is suspect. */
262 enum agent_flaws flaw;
c906108c 263
c5aa993b
JM
264 /* Number of elements left on stack at end; may be negative if expr
265 only consumes elements. */
266 int final_height;
c906108c 267
c5aa993b
JM
268 /* Maximum and minimum stack height, relative to initial height. */
269 int max_height, min_height;
c906108c 270
c5aa993b
JM
271 /* Largest `ref' or `const' opcode used, in bits. Zero means the
272 expression has no such instructions. */
273 int max_data_size;
c906108c 274
c5aa993b 275 /* Bit vector of registers used. Register R is used iff
c906108c 276
c5aa993b 277 reg_mask[R / 8] & (1 << (R % 8))
c906108c 278
c5aa993b
JM
279 is non-zero. Note! You may not assume that this bitmask is long
280 enough to hold bits for all the registers of the machine; the
281 agent expression code has no idea how many registers the machine
282 has. However, the bitmask is reg_mask_len bytes long, so the
283 valid register numbers run from 0 to reg_mask_len * 8 - 1.
c906108c 284
c5aa993b 285 We're assuming eight-bit bytes. So sue me.
c906108c 286
c5aa993b
JM
287 The caller should free reg_list when done. */
288 int reg_mask_len;
289 unsigned char *reg_mask;
290 };
c906108c
SS
291
292
293/* Given an agent expression AX, fill in an agent_reqs structure REQS
294 describing it. */
a14ed312 295extern void ax_reqs (struct agent_expr *ax, struct agent_reqs *reqs);
c906108c
SS
296
297#endif /* AGENTEXPR_H */
This page took 0.570231 seconds and 4 git commands to generate.