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