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