]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/btrace.h
btrace, gdbserver: read branch trace incrementally
[thirdparty/binutils-gdb.git] / gdb / btrace.h
CommitLineData
02d27625
MM
1/* Branch trace support for GDB, the GNU debugger.
2
ecd75fc8 3 Copyright (C) 2013-2014 Free Software Foundation, Inc.
02d27625
MM
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
31struct thread_info;
23a7fe75 32struct btrace_function;
02d27625
MM
33
34/* A branch trace instruction.
35
36 This represents a single instruction in a branch trace. */
23a7fe75 37struct btrace_insn
02d27625
MM
38{
39 /* The address of this instruction. */
40 CORE_ADDR pc;
41};
42
23a7fe75
MM
43/* A vector of branch trace instructions. */
44typedef struct btrace_insn btrace_insn_s;
45DEF_VEC_O (btrace_insn_s);
46
47/* A doubly-linked list of branch trace function segments. */
48struct btrace_func_link
49{
50 struct btrace_function *prev;
51 struct btrace_function *next;
52};
53
54/* Flags for btrace function segments. */
55enum 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.
02d27625
MM
68
69 This represents a function segment in a branch trace, i.e. a consecutive
23a7fe75
MM
70 number of instructions belonging to the same function.
71
72 We do not allow function segments without any instructions. */
73struct btrace_function
02d27625 74{
23a7fe75 75 /* The full and minimal symbol for the function. Both may be NULL. */
02d27625
MM
76 struct minimal_symbol *msym;
77 struct symbol *sym;
78
23a7fe75
MM
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
02d27625
MM
109 /* The source line range of this function segment (both inclusive). */
110 int lbegin, lend;
111
23a7fe75
MM
112 /* A bit-vector of btrace_function_flag. */
113 enum btrace_function_flag flags;
02d27625
MM
114};
115
23a7fe75
MM
116/* A branch trace instruction iterator. */
117struct btrace_insn_iterator
118{
119 /* The branch trace function segment containing the instruction.
120 Will never be NULL. */
121 const struct btrace_function *function;
02d27625 122
23a7fe75
MM
123 /* The index into the function segment's instruction vector. */
124 unsigned int index;
125};
02d27625 126
23a7fe75
MM
127/* A branch trace function call iterator. */
128struct 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};
02d27625
MM
137
138/* Branch trace iteration state for "record instruction-history". */
23a7fe75 139struct btrace_insn_history
02d27625 140{
23a7fe75
MM
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;
02d27625
MM
145};
146
147/* Branch trace iteration state for "record function-call-history". */
23a7fe75 148struct btrace_call_history
02d27625 149{
23a7fe75
MM
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;
02d27625
MM
154};
155
156/* Branch trace information per thread.
157
158 This represents the branch trace configuration as well as the entry point
159 into the branch trace data. For the latter, it also contains the index into
160 an array of branch trace blocks used for iterating though the branch trace
161 blocks of a thread. */
162struct btrace_thread_info
163{
164 /* The target branch trace information for this thread.
165
166 This contains the branch trace configuration as well as any
167 target-specific information necessary for implementing branch tracing on
168 the underlying architecture. */
169 struct btrace_target_info *target;
170
23a7fe75
MM
171 /* The current branch trace for this thread (both inclusive).
172
173 The last instruction of END is the current instruction, which is not
174 part of the execution history.
175 Both will be NULL if there is no branch trace available. If there is
176 branch trace available, both will be non-NULL. */
177 struct btrace_function *begin;
178 struct btrace_function *end;
179
180 /* The function level offset. When added to each function's LEVEL,
181 this normalizes the function levels such that the smallest level
182 becomes zero. */
183 int level;
02d27625
MM
184
185 /* The instruction history iterator. */
23a7fe75 186 struct btrace_insn_history *insn_history;
02d27625
MM
187
188 /* The function call history iterator. */
23a7fe75 189 struct btrace_call_history *call_history;
07bbe694
MM
190
191 /* The current replay position. NULL if not replaying. */
192 struct btrace_insn_iterator *replay;
02d27625
MM
193};
194
195/* Enable branch tracing for a thread. */
196extern void btrace_enable (struct thread_info *tp);
197
198/* Disable branch tracing for a thread.
199 This will also delete the current branch trace data. */
200extern void btrace_disable (struct thread_info *);
201
202/* Disable branch tracing for a thread during teardown.
203 This is similar to btrace_disable, except that it will use
204 target_teardown_btrace instead of target_disable_btrace. */
205extern void btrace_teardown (struct thread_info *);
206
207/* Fetch the branch trace for a single thread. */
208extern void btrace_fetch (struct thread_info *);
209
210/* Clear the branch trace for a single thread. */
211extern void btrace_clear (struct thread_info *);
212
213/* Clear the branch trace for all threads when an object file goes away. */
214extern void btrace_free_objfile (struct objfile *);
215
c12a2917
MM
216/* Parse a branch trace xml document into a block vector. */
217extern VEC (btrace_block_s) *parse_xml_btrace (const char*);
218
23a7fe75
MM
219/* Dereference a branch trace instruction iterator. Return a pointer to the
220 instruction the iterator points to. */
221extern const struct btrace_insn *
222 btrace_insn_get (const struct btrace_insn_iterator *);
223
224/* Return the instruction number for a branch trace iterator.
225 Returns one past the maximum instruction number for the end iterator.
226 Returns zero if the iterator does not point to a valid instruction. */
227extern unsigned int btrace_insn_number (const struct btrace_insn_iterator *);
228
229/* Initialize a branch trace instruction iterator to point to the begin/end of
230 the branch trace. Throws an error if there is no branch trace. */
231extern void btrace_insn_begin (struct btrace_insn_iterator *,
232 const struct btrace_thread_info *);
233extern void btrace_insn_end (struct btrace_insn_iterator *,
234 const struct btrace_thread_info *);
235
236/* Increment/decrement a branch trace instruction iterator by at most STRIDE
237 instructions. Return the number of instructions by which the instruction
238 iterator has been advanced.
239 Returns zero, if the operation failed or STRIDE had been zero. */
240extern unsigned int btrace_insn_next (struct btrace_insn_iterator *,
241 unsigned int stride);
242extern unsigned int btrace_insn_prev (struct btrace_insn_iterator *,
243 unsigned int stride);
244
245/* Compare two branch trace instruction iterators.
246 Return a negative number if LHS < RHS.
247 Return zero if LHS == RHS.
248 Return a positive number if LHS > RHS. */
249extern int btrace_insn_cmp (const struct btrace_insn_iterator *lhs,
250 const struct btrace_insn_iterator *rhs);
251
252/* Find an instruction in the function branch trace by its number.
253 If the instruction is found, initialize the branch trace instruction
254 iterator to point to this instruction and return non-zero.
255 Return zero otherwise. */
256extern int btrace_find_insn_by_number (struct btrace_insn_iterator *,
257 const struct btrace_thread_info *,
258 unsigned int number);
259
260/* Dereference a branch trace call iterator. Return a pointer to the
261 function the iterator points to or NULL if the interator points past
262 the end of the branch trace. */
263extern const struct btrace_function *
264 btrace_call_get (const struct btrace_call_iterator *);
265
266/* Return the function number for a branch trace call iterator.
267 Returns one past the maximum function number for the end iterator.
268 Returns zero if the iterator does not point to a valid function. */
269extern unsigned int btrace_call_number (const struct btrace_call_iterator *);
270
271/* Initialize a branch trace call iterator to point to the begin/end of
272 the branch trace. Throws an error if there is no branch trace. */
273extern void btrace_call_begin (struct btrace_call_iterator *,
274 const struct btrace_thread_info *);
275extern void btrace_call_end (struct btrace_call_iterator *,
276 const struct btrace_thread_info *);
277
278/* Increment/decrement a branch trace call iterator by at most STRIDE function
279 segments. Return the number of function segments by which the call
280 iterator has been advanced.
281 Returns zero, if the operation failed or STRIDE had been zero. */
282extern unsigned int btrace_call_next (struct btrace_call_iterator *,
283 unsigned int stride);
284extern unsigned int btrace_call_prev (struct btrace_call_iterator *,
285 unsigned int stride);
286
287/* Compare two branch trace call iterators.
288 Return a negative number if LHS < RHS.
289 Return zero if LHS == RHS.
290 Return a positive number if LHS > RHS. */
291extern int btrace_call_cmp (const struct btrace_call_iterator *lhs,
292 const struct btrace_call_iterator *rhs);
293
294/* Find a function in the function branch trace by its NUMBER.
295 If the function is found, initialize the branch trace call
296 iterator to point to this function and return non-zero.
297 Return zero otherwise. */
298extern int btrace_find_call_by_number (struct btrace_call_iterator *,
299 const struct btrace_thread_info *,
300 unsigned int number);
301
302/* Set the branch trace instruction history from BEGIN (inclusive) to
303 END (exclusive). */
304extern void btrace_set_insn_history (struct btrace_thread_info *,
305 const struct btrace_insn_iterator *begin,
306 const struct btrace_insn_iterator *end);
307
308/* Set the branch trace function call history from BEGIN (inclusive) to
309 END (exclusive). */
310extern void btrace_set_call_history (struct btrace_thread_info *,
311 const struct btrace_call_iterator *begin,
312 const struct btrace_call_iterator *end);
313
07bbe694
MM
314/* Determine if branch tracing is currently replaying TP. */
315extern int btrace_is_replaying (struct thread_info *tp);
316
02d27625 317#endif /* BTRACE_H */