record btrace: add configuration struct
[deliverable/binutils-gdb.git] / gdb / btrace.h
1 /* Branch trace support for GDB, the GNU debugger.
2
3 Copyright (C) 2013-2015 Free Software Foundation, Inc.
4
5 Contributed by Intel Corp. <markus.t.metzger@intel.com>.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #ifndef BTRACE_H
23 #define BTRACE_H
24
25 /* Branch tracing (btrace) is a per-thread control-flow execution trace of the
26 inferior. For presentation purposes, the branch trace is represented as a
27 list of sequential control-flow blocks, one such list per thread. */
28
29 #include "btrace-common.h"
30
31 struct thread_info;
32 struct btrace_function;
33
34 /* A branch trace instruction.
35
36 This represents a single instruction in a branch trace. */
37 struct btrace_insn
38 {
39 /* The address of this instruction. */
40 CORE_ADDR pc;
41 };
42
43 /* A vector of branch trace instructions. */
44 typedef struct btrace_insn btrace_insn_s;
45 DEF_VEC_O (btrace_insn_s);
46
47 /* A doubly-linked list of branch trace function segments. */
48 struct btrace_func_link
49 {
50 struct btrace_function *prev;
51 struct btrace_function *next;
52 };
53
54 /* Flags for btrace function segments. */
55 enum btrace_function_flag
56 {
57 /* The 'up' link interpretation.
58 If set, it points to the function segment we returned to.
59 If clear, it points to the function segment we called from. */
60 BFUN_UP_LINKS_TO_RET = (1 << 0),
61
62 /* The 'up' link points to a tail call. This obviously only makes sense
63 if bfun_up_links_to_ret is clear. */
64 BFUN_UP_LINKS_TO_TAILCALL = (1 << 1)
65 };
66
67 /* A branch trace function segment.
68
69 This represents a function segment in a branch trace, i.e. a consecutive
70 number of instructions belonging to the same function.
71
72 We do not allow function segments without any instructions. */
73 struct btrace_function
74 {
75 /* The full and minimal symbol for the function. Both may be NULL. */
76 struct minimal_symbol *msym;
77 struct symbol *sym;
78
79 /* The previous and next segment belonging to the same function.
80 If a function calls another function, the former will have at least
81 two segments: one before the call and another after the return. */
82 struct btrace_func_link segment;
83
84 /* The previous and next function in control flow order. */
85 struct btrace_func_link flow;
86
87 /* The directly preceding function segment in a (fake) call stack. */
88 struct btrace_function *up;
89
90 /* The instructions in this function segment.
91 The instruction vector will never be empty. */
92 VEC (btrace_insn_s) *insn;
93
94 /* The instruction number offset for the first instruction in this
95 function segment. */
96 unsigned int insn_offset;
97
98 /* The function number in control-flow order. */
99 unsigned int number;
100
101 /* The function level in a back trace across the entire branch trace.
102 A caller's level is one lower than the level of its callee.
103
104 Levels can be negative if we see returns for which we have not seen
105 the corresponding calls. The branch trace thread information provides
106 a fixup to normalize function levels so the smallest level is zero. */
107 int level;
108
109 /* The source line range of this function segment (both inclusive). */
110 int lbegin, lend;
111
112 /* A bit-vector of btrace_function_flag. */
113 enum btrace_function_flag flags;
114 };
115
116 /* A branch trace instruction iterator. */
117 struct btrace_insn_iterator
118 {
119 /* The branch trace function segment containing the instruction.
120 Will never be NULL. */
121 const struct btrace_function *function;
122
123 /* The index into the function segment's instruction vector. */
124 unsigned int index;
125 };
126
127 /* A branch trace function call iterator. */
128 struct btrace_call_iterator
129 {
130 /* The branch trace information for this thread. Will never be NULL. */
131 const struct btrace_thread_info *btinfo;
132
133 /* The branch trace function segment.
134 This will be NULL for the iterator pointing to the end of the trace. */
135 const struct btrace_function *function;
136 };
137
138 /* Branch trace iteration state for "record instruction-history". */
139 struct btrace_insn_history
140 {
141 /* The branch trace instruction range from BEGIN (inclusive) to
142 END (exclusive) that has been covered last time. */
143 struct btrace_insn_iterator begin;
144 struct btrace_insn_iterator end;
145 };
146
147 /* Branch trace iteration state for "record function-call-history". */
148 struct btrace_call_history
149 {
150 /* The branch trace function range from BEGIN (inclusive) to END (exclusive)
151 that has been covered last time. */
152 struct btrace_call_iterator begin;
153 struct btrace_call_iterator end;
154 };
155
156 /* Branch trace thread flags. */
157 enum btrace_thread_flag
158 {
159 /* The thread is to be stepped forwards. */
160 BTHR_STEP = (1 << 0),
161
162 /* The thread is to be stepped backwards. */
163 BTHR_RSTEP = (1 << 1),
164
165 /* The thread is to be continued forwards. */
166 BTHR_CONT = (1 << 2),
167
168 /* The thread is to be continued backwards. */
169 BTHR_RCONT = (1 << 3),
170
171 /* The thread is to be moved. */
172 BTHR_MOVE = (BTHR_STEP | BTHR_RSTEP | BTHR_CONT | BTHR_RCONT)
173 };
174
175 /* Branch trace information per thread.
176
177 This represents the branch trace configuration as well as the entry point
178 into the branch trace data. For the latter, it also contains the index into
179 an array of branch trace blocks used for iterating though the branch trace
180 blocks of a thread. */
181 struct btrace_thread_info
182 {
183 /* The target branch trace information for this thread.
184
185 This contains the branch trace configuration as well as any
186 target-specific information necessary for implementing branch tracing on
187 the underlying architecture. */
188 struct btrace_target_info *target;
189
190 /* The current branch trace for this thread (both inclusive).
191
192 The last instruction of END is the current instruction, which is not
193 part of the execution history.
194 Both will be NULL if there is no branch trace available. If there is
195 branch trace available, both will be non-NULL. */
196 struct btrace_function *begin;
197 struct btrace_function *end;
198
199 /* The function level offset. When added to each function's LEVEL,
200 this normalizes the function levels such that the smallest level
201 becomes zero. */
202 int level;
203
204 /* A bit-vector of btrace_thread_flag. */
205 enum btrace_thread_flag flags;
206
207 /* The instruction history iterator. */
208 struct btrace_insn_history *insn_history;
209
210 /* The function call history iterator. */
211 struct btrace_call_history *call_history;
212
213 /* The current replay position. NULL if not replaying. */
214 struct btrace_insn_iterator *replay;
215 };
216
217 /* Enable branch tracing for a thread. */
218 extern void btrace_enable (struct thread_info *tp,
219 const struct btrace_config *conf);
220
221 /* Get the branch trace configuration for a thread.
222 Return NULL if branch tracing is not enabled for that thread. */
223 extern const struct btrace_config *
224 btrace_conf (const struct btrace_thread_info *);
225
226 /* Disable branch tracing for a thread.
227 This will also delete the current branch trace data. */
228 extern void btrace_disable (struct thread_info *);
229
230 /* Disable branch tracing for a thread during teardown.
231 This is similar to btrace_disable, except that it will use
232 target_teardown_btrace instead of target_disable_btrace. */
233 extern void btrace_teardown (struct thread_info *);
234
235 /* Fetch the branch trace for a single thread. */
236 extern void btrace_fetch (struct thread_info *);
237
238 /* Clear the branch trace for a single thread. */
239 extern void btrace_clear (struct thread_info *);
240
241 /* Clear the branch trace for all threads when an object file goes away. */
242 extern void btrace_free_objfile (struct objfile *);
243
244 /* Parse a branch trace xml document XML into DATA. */
245 extern void parse_xml_btrace (struct btrace_data *data, const char *xml);
246
247 /* Parse a branch trace configuration xml document XML into CONF. */
248 extern void parse_xml_btrace_conf (struct btrace_config *conf, const char *xml);
249
250 /* Dereference a branch trace instruction iterator. Return a pointer to the
251 instruction the iterator points to. */
252 extern const struct btrace_insn *
253 btrace_insn_get (const struct btrace_insn_iterator *);
254
255 /* Return the instruction number for a branch trace iterator.
256 Returns one past the maximum instruction number for the end iterator.
257 Returns zero if the iterator does not point to a valid instruction. */
258 extern unsigned int btrace_insn_number (const struct btrace_insn_iterator *);
259
260 /* Initialize a branch trace instruction iterator to point to the begin/end of
261 the branch trace. Throws an error if there is no branch trace. */
262 extern void btrace_insn_begin (struct btrace_insn_iterator *,
263 const struct btrace_thread_info *);
264 extern void btrace_insn_end (struct btrace_insn_iterator *,
265 const struct btrace_thread_info *);
266
267 /* Increment/decrement a branch trace instruction iterator by at most STRIDE
268 instructions. Return the number of instructions by which the instruction
269 iterator has been advanced.
270 Returns zero, if the operation failed or STRIDE had been zero. */
271 extern unsigned int btrace_insn_next (struct btrace_insn_iterator *,
272 unsigned int stride);
273 extern unsigned int btrace_insn_prev (struct btrace_insn_iterator *,
274 unsigned int stride);
275
276 /* Compare two branch trace instruction iterators.
277 Return a negative number if LHS < RHS.
278 Return zero if LHS == RHS.
279 Return a positive number if LHS > RHS. */
280 extern int btrace_insn_cmp (const struct btrace_insn_iterator *lhs,
281 const struct btrace_insn_iterator *rhs);
282
283 /* Find an instruction in the function branch trace by its number.
284 If the instruction is found, initialize the branch trace instruction
285 iterator to point to this instruction and return non-zero.
286 Return zero otherwise. */
287 extern int btrace_find_insn_by_number (struct btrace_insn_iterator *,
288 const struct btrace_thread_info *,
289 unsigned int number);
290
291 /* Dereference a branch trace call iterator. Return a pointer to the
292 function the iterator points to or NULL if the interator points past
293 the end of the branch trace. */
294 extern const struct btrace_function *
295 btrace_call_get (const struct btrace_call_iterator *);
296
297 /* Return the function number for a branch trace call iterator.
298 Returns one past the maximum function number for the end iterator.
299 Returns zero if the iterator does not point to a valid function. */
300 extern unsigned int btrace_call_number (const struct btrace_call_iterator *);
301
302 /* Initialize a branch trace call iterator to point to the begin/end of
303 the branch trace. Throws an error if there is no branch trace. */
304 extern void btrace_call_begin (struct btrace_call_iterator *,
305 const struct btrace_thread_info *);
306 extern void btrace_call_end (struct btrace_call_iterator *,
307 const struct btrace_thread_info *);
308
309 /* Increment/decrement a branch trace call iterator by at most STRIDE function
310 segments. Return the number of function segments by which the call
311 iterator has been advanced.
312 Returns zero, if the operation failed or STRIDE had been zero. */
313 extern unsigned int btrace_call_next (struct btrace_call_iterator *,
314 unsigned int stride);
315 extern unsigned int btrace_call_prev (struct btrace_call_iterator *,
316 unsigned int stride);
317
318 /* Compare two branch trace call iterators.
319 Return a negative number if LHS < RHS.
320 Return zero if LHS == RHS.
321 Return a positive number if LHS > RHS. */
322 extern int btrace_call_cmp (const struct btrace_call_iterator *lhs,
323 const struct btrace_call_iterator *rhs);
324
325 /* Find a function in the function branch trace by its NUMBER.
326 If the function is found, initialize the branch trace call
327 iterator to point to this function and return non-zero.
328 Return zero otherwise. */
329 extern int btrace_find_call_by_number (struct btrace_call_iterator *,
330 const struct btrace_thread_info *,
331 unsigned int number);
332
333 /* Set the branch trace instruction history from BEGIN (inclusive) to
334 END (exclusive). */
335 extern void btrace_set_insn_history (struct btrace_thread_info *,
336 const struct btrace_insn_iterator *begin,
337 const struct btrace_insn_iterator *end);
338
339 /* Set the branch trace function call history from BEGIN (inclusive) to
340 END (exclusive). */
341 extern void btrace_set_call_history (struct btrace_thread_info *,
342 const struct btrace_call_iterator *begin,
343 const struct btrace_call_iterator *end);
344
345 /* Determine if branch tracing is currently replaying TP. */
346 extern int btrace_is_replaying (struct thread_info *tp);
347
348 /* Return non-zero if the branch trace for TP is empty; zero otherwise. */
349 extern int btrace_is_empty (struct thread_info *tp);
350
351 /* Create a cleanup for DATA. */
352 extern struct cleanup *make_cleanup_btrace_data (struct btrace_data *data);
353
354 #endif /* BTRACE_H */
This page took 0.082559 seconds and 4 git commands to generate.