GDB (xrefs)

/tmp/gdb-8.1/gdb/ax.h
Go to the documentation of this file.
1 /* Definitions for expressions designed to be executed on the agent
2 Copyright (C) 1998-2018 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
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.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19 #ifndef AGENTEXPR_H
20 #define AGENTEXPR_H
21
22 #include "vec.h"
23
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. */
51
52
53 /* Different kinds of flaws an agent expression might have, as
54 detected by ax_reqs. */
55 enum 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
80 /* Agent expression data structures. */
81
82 /* A buffer containing a agent expression. */
83 struct agent_expr
84 {
85 /* Construct an empty agent expression. */
86 explicit agent_expr (struct gdbarch *gdbarch, CORE_ADDR scope);
87
88 ~agent_expr ();
89
90 /* The bytes of the expression. */
91 unsigned char *buf;
92
93 /* The number of bytecode in the expression. */
94 int len;
95
96 /* Allocated space available currently. */
97 int size;
98
99 /* The target architecture assumed to be in effect. */
100 struct gdbarch *gdbarch;
101
102 /* The address to which the expression applies. */
103 CORE_ADDR scope;
104
105 /* If the following is not equal to agent_flaw_none, the rest of the
106 information in this structure is suspect. */
107 enum agent_flaws flaw;
108
109 /* Number of elements left on stack at end; may be negative if expr
110 only consumes elements. */
111 int final_height;
112
113 /* Maximum and minimum stack height, relative to initial height. */
114 int max_height, min_height;
115
116 /* Largest `ref' or `const' opcode used, in bits. Zero means the
117 expression has no such instructions. */
118 int max_data_size;
119
120 /* Bit vector of registers needed. Register R is needed iff
121
122 reg_mask[R / 8] & (1 << (R % 8))
123
124 is non-zero. Note! You may not assume that this bitmask is long
125 enough to hold bits for all the registers of the machine; the
126 agent expression code has no idea how many registers the machine
127 has. However, the bitmask is reg_mask_len bytes long, so the
128 valid register numbers run from 0 to reg_mask_len * 8 - 1.
129
130 Also note that this mask may contain registers that are needed
131 for the original collection expression to work, but that are
132 not referenced by any bytecode. This could, for example, occur
133 when collecting a local variable allocated to a register; the
134 compiler sets the mask bit and skips generating a bytecode whose
135 result is going to be discarded anyway.
136 */
137 int reg_mask_len;
138 unsigned char *reg_mask;
139
140 /* For the data tracing facility, we need to insert `trace' bytecodes
141 before each data fetch; this records all the memory that the
142 expression touches in the course of evaluation, so that memory will
143 be available when the user later tries to evaluate the expression
144 in GDB.
145
146 Setting the flag 'tracing' to non-zero enables the code that
147 emits the trace bytecodes at the appropriate points. */
148
149 unsigned int tracing : 1;
150
151 /* This indicates that pointers to chars should get an added
152 tracenz bytecode to record nonzero bytes, up to a length that
153 is the value of trace_string. */
154
155 int trace_string;
156 };
157
158 /* An agent_expr owning pointer. */
159 typedef std::unique_ptr<agent_expr> agent_expr_up;
160
161 /* The actual values of the various bytecode operations. */
162
163 enum agent_op
164 {
165 #define DEFOP(NAME, SIZE, DATA_SIZE, CONSUMED, PRODUCED, VALUE) \
166 aop_ ## NAME = VALUE,
167 #include "ax.def"
168 #undef DEFOP
169 aop_last
170 };
171
172
173
174 /* Functions for building expressions. */
175
176 /* Append a raw byte to EXPR. */
177 extern void ax_raw_byte (struct agent_expr *expr, gdb_byte byte);
178
179 /* Append a simple operator OP to EXPR. */
180 extern void ax_simple (struct agent_expr *EXPR, enum agent_op OP);
181
182 /* Append a pick operator to EXPR. DEPTH is the stack item to pick,
183 with 0 being top of stack. */
184 extern void ax_pick (struct agent_expr *EXPR, int DEPTH);
185
186 /* Append the floating-point prefix, for the next bytecode. */
187 #define ax_float(EXPR) (ax_simple ((EXPR), aop_float))
188
189 /* Append a sign-extension instruction to EXPR, to extend an N-bit value. */
190 extern void ax_ext (struct agent_expr *EXPR, int N);
191
192 /* Append a zero-extension instruction to EXPR, to extend an N-bit value. */
193 extern void ax_zero_ext (struct agent_expr *EXPR, int N);
194
195 /* Append a trace_quick instruction to EXPR, to record N bytes. */
196 extern void ax_trace_quick (struct agent_expr *EXPR, int N);
197
198 /* Append a goto op to EXPR. OP is the actual op (must be aop_goto or
199 aop_if_goto). We assume we don't know the target offset yet,
200 because it's probably a forward branch, so we leave space in EXPR
201 for the target, and return the offset in EXPR of that space, so we
202 can backpatch it once we do know the target offset. Use ax_label
203 to do the backpatching. */
204 extern int ax_goto (struct agent_expr *EXPR, enum agent_op OP);
205
206 /* Suppose a given call to ax_goto returns some value PATCH. When you
207 know the offset TARGET that goto should jump to, call
208 ax_label (EXPR, PATCH, TARGET)
209 to patch TARGET into the ax_goto instruction. */
210 extern void ax_label (struct agent_expr *EXPR, int patch, int target);
211
212 /* Assemble code to push a constant on the stack. */
213 extern void ax_const_l (struct agent_expr *EXPR, LONGEST l);
214 extern void ax_const_d (struct agent_expr *EXPR, LONGEST d);
215
216 /* Assemble code to push the value of register number REG on the
217 stack. */
218 extern void ax_reg (struct agent_expr *EXPR, int REG);
219
220 /* Add the given register to the register mask of the expression. */
221 extern void ax_reg_mask (struct agent_expr *ax, int reg);
222
223 /* Assemble code to operate on a trace state variable. */
224 extern void ax_tsv (struct agent_expr *expr, enum agent_op op, int num);
225
226 /* Append a string to the bytecode stream. */
227 extern void ax_string (struct agent_expr *x, const char *str, int slen);
228
229
230 /* Functions for printing out expressions, and otherwise debugging
231 things. */
232
233 /* Disassemble the expression EXPR, writing to F. */
234 extern void ax_print (struct ui_file *f, struct agent_expr * EXPR);
235
236 /* An entry in the opcode map. */
237 struct aop_map
238 {
239
240 /* The name of the opcode. Null means that this entry is not a
241 valid opcode --- a hole in the opcode space. */
242 const char *name;
243
244 /* All opcodes take no operands from the bytecode stream, or take
245 unsigned integers of various sizes. If this is a positive number
246 n, then the opcode is followed by an n-byte operand, which should
247 be printed as an unsigned integer. If this is zero, then the
248 opcode takes no operands from the bytecode stream.
249
250 If we get more complicated opcodes in the future, don't add other
251 magic values of this; that's a crock. Add an `enum encoding'
252 field to this, or something like that. */
253 int op_size;
254
255 /* The size of the data operated upon, in bits, for bytecodes that
256 care about that (ref and const). Zero for all others. */
257 int data_size;
258
259 /* Number of stack elements consumed, and number produced. */
260 int consumed, produced;
261 };
262
263 /* Map of the bytecodes, indexed by bytecode number. */
264 extern struct aop_map aop_map[];
265
266 /* Given an agent expression AX, analyze and update its requirements. */
267
268 extern void ax_reqs (struct agent_expr *ax);
269
270 #endif /* AGENTEXPR_H */
agent_expr::final_height
int final_height
Definition: ax.h:111
agent_flaws
agent_flaws
Definition: ax.h:55
gdbarch
Definition: gdbarch.c:127
agent_expr_up
std::unique_ptr< agent_expr > agent_expr_up
Definition: ax.h:159
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
ax_reg
void ax_reg(struct agent_expr *EXPR, int REG)
Definition: ax-general.c:274
ax_simple
void ax_simple(struct agent_expr *EXPR, enum agent_op OP)
Definition: ax-general.c:125
agent_expr::reg_mask
unsigned char * reg_mask
Definition: ax.h:138
ax_print
void ax_print(struct ui_file *f, struct agent_expr *EXPR)
Definition: ax-general.c:363
aop_last
Definition: ax.h:267
ax_goto
int ax_goto(struct agent_expr *EXPR, enum agent_op OP)
Definition: ax-general.c:200
agent_expr
Definition: ax.h:83
aop_map::produced
int produced
Definition: ax.h:260
agent_expr::max_height
int max_height
Definition: ax.h:114
agent_expr::gdbarch
struct gdbarch * gdbarch
Definition: ax.h:100
ui_file
Definition: ui-file.h:26
agent_expr::agent_expr
agent_expr(struct gdbarch *gdbarch, CORE_ADDR scope)
Definition: ax-general.c:40
agent_expr::flaw
enum agent_flaws flaw
Definition: ax.h:107
agent_flaw_height_mismatch
Definition: ax.h:73
agent_expr::trace_string
int trace_string
Definition: ax.h:155
agent_flaw_incomplete_instruction
Definition: ax.h:63
agent_flaw_bad_jump
Definition: ax.h:68
OP
Definition: expression.h:73
ax_trace_quick
void ax_trace_quick(struct agent_expr *EXPR, int N)
Definition: ax-general.c:180
agent_flaw_none
Definition: ax.h:57
aop_map
Definition: ax.h:237
agent_expr::tracing
unsigned int tracing
Definition: ax.h:149
ax_tsv
void ax_tsv(struct agent_expr *expr, enum agent_op op, int num)
Definition: ax-general.c:307
ax_pick
void ax_pick(struct agent_expr *EXPR, int DEPTH)
Definition: ax-general.c:134
ax_const_l
void ax_const_l(struct agent_expr *EXPR, LONGEST l)
Definition: ax-general.c:229
agent_op
agent_op
Definition: ax.h:163
ax_const_d
void ax_const_d(struct agent_expr *EXPR, LONGEST d)
Definition: ax-general.c:263
agent_expr::min_height
int min_height
Definition: ax.h:114
ax_label
void ax_label(struct agent_expr *EXPR, int patch, int target)
Definition: ax-general.c:215
ax_ext
void ax_ext(struct agent_expr *EXPR, int N)
Definition: ax-general.c:164
agent_expr::~agent_expr
~agent_expr()
Definition: ax-general.c:58
reg
Definition: regdef.h:22
ax_reqs
void ax_reqs(struct agent_expr *ax)
Definition: ax-general.c:468
ax_zero_ext
void ax_zero_ext(struct agent_expr *EXPR, int N)
Definition: ax-general.c:172
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
aop_map::data_size
int data_size
Definition: ax.h:257
aop_map::name
const char * name
Definition: ax.h:242
ax_raw_byte
void ax_raw_byte(struct agent_expr *expr, gdb_byte byte)
Definition: ax-general.c:117
agent_expr::len
int len
Definition: ax.h:94
aop_map::op_size
int op_size
Definition: ax.h:253
ax_string
void ax_string(struct agent_expr *x, const char *str, int slen)
Definition: ax-general.c:328
agent_expr::buf
unsigned char * buf
Definition: ax.h:91
agent_expr::reg_mask_len
int reg_mask_len
Definition: ax.h:137
agent_flaw_bad_instruction
Definition: ax.h:60
aop_map::consumed
int consumed
Definition: ax.h:260
ax_reg_mask
void ax_reg_mask(struct agent_expr *ax, int reg)
Definition: ax-general.c:425
agent_expr::max_data_size
int max_data_size
Definition: ax.h:118
LONGEST
long long LONGEST
Definition: common-types.h:52
agent_flaw_hole
Definition: ax.h:77
vec.h
agent_expr::scope
CORE_ADDR scope
Definition: ax.h:103
agent_expr::size
int size
Definition: ax.h:97