]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/ax.h
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / ax.h
CommitLineData
c906108c 1/* Definitions for expressions designed to be executed on the agent
1d506c26 2 Copyright (C) 1998-2024 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
1a5c2598
TT
19#ifndef AX_H
20#define AX_H
c906108c
SS
21
22/* It's sometimes useful to be able to debug programs that you can't
23 really stop for more than a fraction of a second. To this end, the
24 user can specify a tracepoint (like a breakpoint, but you don't
25 stop at it), and specify a bunch of expressions to record the
26 values of when that tracepoint is reached. As the program runs,
27 GDB collects the values. At any point (possibly while values are
28 still being collected), the user can display the collected values.
29
30 This is used with remote debugging; we don't really support it on
31 native configurations.
32
33 This means that expressions are being evaluated by the remote agent,
34 which doesn't have any access to the symbol table information, and
35 needs to be small and simple.
36
37 The agent_expr routines and datatypes are a bytecode language
38 designed to be executed by the agent. Agent expressions work in
39 terms of fixed-width values, operators, memory references, and
40 register references. You can evaluate a agent expression just given
41 a bunch of memory and register values to sniff at; you don't need
42 any symbolic information like variable names, types, etc.
43
44 GDB translates source expressions, whose meaning depends on
45 symbolic information, into agent bytecode expressions, whose meaning
46 is independent of symbolic information. This means the agent can
47 evaluate them on the fly without reference to data only available
48 to the host GDB. */
c906108c 49\f
c5aa993b 50
35c9c7ba
SS
51/* Different kinds of flaws an agent expression might have, as
52 detected by ax_reqs. */
53enum agent_flaws
54 {
55 agent_flaw_none = 0, /* code is good */
56
57 /* There is an invalid instruction in the stream. */
58 agent_flaw_bad_instruction,
59
60 /* There is an incomplete instruction at the end of the expression. */
61 agent_flaw_incomplete_instruction,
62
63 /* ax_reqs was unable to prove that every jump target is to a
64 valid offset. Valid offsets are within the bounds of the
65 expression, and to a valid instruction boundary. */
66 agent_flaw_bad_jump,
67
68 /* ax_reqs was unable to prove to its satisfaction that, for each
69 jump target location, the stack will have the same height whether
70 that location is reached via a jump or by straight execution. */
71 agent_flaw_height_mismatch,
72
73 /* ax_reqs was unable to prove that every instruction following
74 an unconditional jump was the target of some other jump. */
75 agent_flaw_hole
76 };
77
c906108c
SS
78/* Agent expression data structures. */
79
c906108c 80/* A buffer containing a agent expression. */
c5aa993b
JM
81struct agent_expr
82 {
833177a4 83 /* Construct an empty agent expression. */
b0b5ba6b
TT
84 agent_expr (struct gdbarch *gdbarch, CORE_ADDR scope)
85 : gdbarch (gdbarch),
da25448d 86 scope (scope)
b0b5ba6b 87 { }
833177a4 88
35c9c7ba 89 /* The bytes of the expression. */
6f96f485 90 gdb::byte_vector buf;
35c9c7ba
SS
91
92 /* The target architecture assumed to be in effect. */
93 struct gdbarch *gdbarch;
94
95 /* The address to which the expression applies. */
c5aa993b 96 CORE_ADDR scope;
c906108c 97
35c9c7ba
SS
98 /* If the following is not equal to agent_flaw_none, the rest of the
99 information in this structure is suspect. */
100 enum agent_flaws flaw;
101
102 /* Number of elements left on stack at end; may be negative if expr
103 only consumes elements. */
104 int final_height;
105
106 /* Maximum and minimum stack height, relative to initial height. */
107 int max_height, min_height;
108
109 /* Largest `ref' or `const' opcode used, in bits. Zero means the
110 expression has no such instructions. */
111 int max_data_size;
112
113 /* Bit vector of registers needed. Register R is needed iff
a2bbca9f
TT
114 reg_mask[R] is non-zero. Note! You may not assume that this
115 bitmask is long enough to hold bits for all the registers of
116 the machine; the agent expression code has no idea how many
117 registers the machine has.
35c9c7ba
SS
118
119 Also note that this mask may contain registers that are needed
120 for the original collection expression to work, but that are
121 not referenced by any bytecode. This could, for example, occur
122 when collecting a local variable allocated to a register; the
123 compiler sets the mask bit and skips generating a bytecode whose
124 result is going to be discarded anyway.
125 */
a2bbca9f 126 std::vector<bool> reg_mask;
92bc6a20
TT
127
128 /* For the data tracing facility, we need to insert `trace' bytecodes
129 before each data fetch; this records all the memory that the
130 expression touches in the course of evaluation, so that memory will
131 be available when the user later tries to evaluate the expression
132 in GDB.
133
da25448d 134 Setting the flag 'tracing' to true enables the code that
92bc6a20
TT
135 emits the trace bytecodes at the appropriate points. */
136
da25448d 137 bool tracing = false;
92bc6a20
TT
138
139 /* This indicates that pointers to chars should get an added
140 tracenz bytecode to record nonzero bytes, up to a length that
141 is the value of trace_string. */
142
b0b5ba6b 143 int trace_string = 0;
35c9c7ba 144 };
c906108c 145
833177a4 146/* An agent_expr owning pointer. */
6c73cd95 147typedef std::unique_ptr<agent_expr> agent_expr_up;
833177a4 148
94d5e490 149/* The actual values of the various bytecode operations. */
c906108c 150
c5aa993b
JM
151enum agent_op
152 {
94d5e490
TT
153#define DEFOP(NAME, SIZE, DATA_SIZE, CONSUMED, PRODUCED, VALUE) \
154 aop_ ## NAME = VALUE,
268a13a5 155#include "gdbsupport/ax.def"
94d5e490 156#undef DEFOP
c5aa993b
JM
157 };
158\f
c906108c
SS
159
160
c906108c
SS
161/* Functions for building expressions. */
162
70b8286a
SM
163/* Append a raw byte to EXPR. */
164extern void ax_raw_byte (struct agent_expr *expr, gdb_byte byte);
165
c906108c 166/* Append a simple operator OP to EXPR. */
a14ed312 167extern void ax_simple (struct agent_expr *EXPR, enum agent_op OP);
c906108c 168
c7f96d2b
TT
169/* Append a pick operator to EXPR. DEPTH is the stack item to pick,
170 with 0 being top of stack. */
171extern void ax_pick (struct agent_expr *EXPR, int DEPTH);
172
c906108c
SS
173/* Append the floating-point prefix, for the next bytecode. */
174#define ax_float(EXPR) (ax_simple ((EXPR), aop_float))
175
176/* Append a sign-extension instruction to EXPR, to extend an N-bit value. */
a14ed312 177extern void ax_ext (struct agent_expr *EXPR, int N);
c906108c
SS
178
179/* Append a zero-extension instruction to EXPR, to extend an N-bit value. */
a14ed312 180extern void ax_zero_ext (struct agent_expr *EXPR, int N);
c906108c
SS
181
182/* Append a trace_quick instruction to EXPR, to record N bytes. */
a14ed312 183extern void ax_trace_quick (struct agent_expr *EXPR, int N);
c906108c
SS
184
185/* Append a goto op to EXPR. OP is the actual op (must be aop_goto or
186 aop_if_goto). We assume we don't know the target offset yet,
187 because it's probably a forward branch, so we leave space in EXPR
188 for the target, and return the offset in EXPR of that space, so we
189 can backpatch it once we do know the target offset. Use ax_label
190 to do the backpatching. */
a14ed312 191extern int ax_goto (struct agent_expr *EXPR, enum agent_op OP);
c906108c
SS
192
193/* Suppose a given call to ax_goto returns some value PATCH. When you
194 know the offset TARGET that goto should jump to, call
c5aa993b 195 ax_label (EXPR, PATCH, TARGET)
c906108c 196 to patch TARGET into the ax_goto instruction. */
a14ed312 197extern void ax_label (struct agent_expr *EXPR, int patch, int target);
c906108c
SS
198
199/* Assemble code to push a constant on the stack. */
a14ed312
KB
200extern void ax_const_l (struct agent_expr *EXPR, LONGEST l);
201extern void ax_const_d (struct agent_expr *EXPR, LONGEST d);
c906108c
SS
202
203/* Assemble code to push the value of register number REG on the
204 stack. */
a14ed312 205extern void ax_reg (struct agent_expr *EXPR, int REG);
f61e138d 206
35c9c7ba
SS
207/* Add the given register to the register mask of the expression. */
208extern void ax_reg_mask (struct agent_expr *ax, int reg);
209
f61e138d
SS
210/* Assemble code to operate on a trace state variable. */
211extern void ax_tsv (struct agent_expr *expr, enum agent_op op, int num);
d3ce09f5
SS
212
213/* Append a string to the bytecode stream. */
741d92cf 214extern void ax_string (struct agent_expr *x, const char *str, int slen);
c906108c 215\f
c5aa993b 216
c906108c
SS
217/* Functions for printing out expressions, and otherwise debugging
218 things. */
219
220/* Disassemble the expression EXPR, writing to F. */
d9fcf2fb 221extern void ax_print (struct ui_file *f, struct agent_expr * EXPR);
c906108c 222
35c9c7ba 223/* Given an agent expression AX, analyze and update its requirements. */
c906108c 224
35c9c7ba 225extern void ax_reqs (struct agent_expr *ax);
c906108c 226
1a5c2598 227#endif /* AX_H */