Don't segfault or assert on NULL tls_sec
[deliverable/binutils-gdb.git] / gdb / btrace.h
CommitLineData
02d27625
MM
1/* Branch trace support for GDB, the GNU debugger.
2
32d0add0 3 Copyright (C) 2013-2015 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
52834460
MM
156/* Branch trace thread flags. */
157enum 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
02d27625
MM
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. */
181struct 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
23a7fe75
MM
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;
02d27625 203
52834460
MM
204 /* A bit-vector of btrace_thread_flag. */
205 enum btrace_thread_flag flags;
206
02d27625 207 /* The instruction history iterator. */
23a7fe75 208 struct btrace_insn_history *insn_history;
02d27625
MM
209
210 /* The function call history iterator. */
23a7fe75 211 struct btrace_call_history *call_history;
07bbe694
MM
212
213 /* The current replay position. NULL if not replaying. */
214 struct btrace_insn_iterator *replay;
02d27625
MM
215};
216
217/* Enable branch tracing for a thread. */
218extern void btrace_enable (struct thread_info *tp);
219
220/* Disable branch tracing for a thread.
221 This will also delete the current branch trace data. */
222extern void btrace_disable (struct thread_info *);
223
224/* Disable branch tracing for a thread during teardown.
225 This is similar to btrace_disable, except that it will use
226 target_teardown_btrace instead of target_disable_btrace. */
227extern void btrace_teardown (struct thread_info *);
228
229/* Fetch the branch trace for a single thread. */
230extern void btrace_fetch (struct thread_info *);
231
232/* Clear the branch trace for a single thread. */
233extern void btrace_clear (struct thread_info *);
234
235/* Clear the branch trace for all threads when an object file goes away. */
236extern void btrace_free_objfile (struct objfile *);
237
c12a2917
MM
238/* Parse a branch trace xml document into a block vector. */
239extern VEC (btrace_block_s) *parse_xml_btrace (const char*);
240
23a7fe75
MM
241/* Dereference a branch trace instruction iterator. Return a pointer to the
242 instruction the iterator points to. */
243extern const struct btrace_insn *
244 btrace_insn_get (const struct btrace_insn_iterator *);
245
246/* Return the instruction number for a branch trace iterator.
247 Returns one past the maximum instruction number for the end iterator.
248 Returns zero if the iterator does not point to a valid instruction. */
249extern unsigned int btrace_insn_number (const struct btrace_insn_iterator *);
250
251/* Initialize a branch trace instruction iterator to point to the begin/end of
252 the branch trace. Throws an error if there is no branch trace. */
253extern void btrace_insn_begin (struct btrace_insn_iterator *,
254 const struct btrace_thread_info *);
255extern void btrace_insn_end (struct btrace_insn_iterator *,
256 const struct btrace_thread_info *);
257
258/* Increment/decrement a branch trace instruction iterator by at most STRIDE
259 instructions. Return the number of instructions by which the instruction
260 iterator has been advanced.
261 Returns zero, if the operation failed or STRIDE had been zero. */
262extern unsigned int btrace_insn_next (struct btrace_insn_iterator *,
263 unsigned int stride);
264extern unsigned int btrace_insn_prev (struct btrace_insn_iterator *,
265 unsigned int stride);
266
267/* Compare two branch trace instruction iterators.
268 Return a negative number if LHS < RHS.
269 Return zero if LHS == RHS.
270 Return a positive number if LHS > RHS. */
271extern int btrace_insn_cmp (const struct btrace_insn_iterator *lhs,
272 const struct btrace_insn_iterator *rhs);
273
274/* Find an instruction in the function branch trace by its number.
275 If the instruction is found, initialize the branch trace instruction
276 iterator to point to this instruction and return non-zero.
277 Return zero otherwise. */
278extern int btrace_find_insn_by_number (struct btrace_insn_iterator *,
279 const struct btrace_thread_info *,
280 unsigned int number);
281
282/* Dereference a branch trace call iterator. Return a pointer to the
283 function the iterator points to or NULL if the interator points past
284 the end of the branch trace. */
285extern const struct btrace_function *
286 btrace_call_get (const struct btrace_call_iterator *);
287
288/* Return the function number for a branch trace call iterator.
289 Returns one past the maximum function number for the end iterator.
290 Returns zero if the iterator does not point to a valid function. */
291extern unsigned int btrace_call_number (const struct btrace_call_iterator *);
292
293/* Initialize a branch trace call iterator to point to the begin/end of
294 the branch trace. Throws an error if there is no branch trace. */
295extern void btrace_call_begin (struct btrace_call_iterator *,
296 const struct btrace_thread_info *);
297extern void btrace_call_end (struct btrace_call_iterator *,
298 const struct btrace_thread_info *);
299
300/* Increment/decrement a branch trace call iterator by at most STRIDE function
301 segments. Return the number of function segments by which the call
302 iterator has been advanced.
303 Returns zero, if the operation failed or STRIDE had been zero. */
304extern unsigned int btrace_call_next (struct btrace_call_iterator *,
305 unsigned int stride);
306extern unsigned int btrace_call_prev (struct btrace_call_iterator *,
307 unsigned int stride);
308
309/* Compare two branch trace call iterators.
310 Return a negative number if LHS < RHS.
311 Return zero if LHS == RHS.
312 Return a positive number if LHS > RHS. */
313extern int btrace_call_cmp (const struct btrace_call_iterator *lhs,
314 const struct btrace_call_iterator *rhs);
315
316/* Find a function in the function branch trace by its NUMBER.
317 If the function is found, initialize the branch trace call
318 iterator to point to this function and return non-zero.
319 Return zero otherwise. */
320extern int btrace_find_call_by_number (struct btrace_call_iterator *,
321 const struct btrace_thread_info *,
322 unsigned int number);
323
324/* Set the branch trace instruction history from BEGIN (inclusive) to
325 END (exclusive). */
326extern void btrace_set_insn_history (struct btrace_thread_info *,
327 const struct btrace_insn_iterator *begin,
328 const struct btrace_insn_iterator *end);
329
330/* Set the branch trace function call history from BEGIN (inclusive) to
331 END (exclusive). */
332extern void btrace_set_call_history (struct btrace_thread_info *,
333 const struct btrace_call_iterator *begin,
334 const struct btrace_call_iterator *end);
335
07bbe694
MM
336/* Determine if branch tracing is currently replaying TP. */
337extern int btrace_is_replaying (struct thread_info *tp);
338
6e07b1d2
MM
339/* Return non-zero if the branch trace for TP is empty; zero otherwise. */
340extern int btrace_is_empty (struct thread_info *tp);
341
342
02d27625 343#endif /* BTRACE_H */
This page took 0.229241 seconds and 4 git commands to generate.