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