windows-nat: Don't change current_event.dwThreadId in handle_output_debug_string()
[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 #include "target/waitstatus.h" /* For enum target_stop_reason. */
31
32 struct thread_info;
33 struct btrace_function;
34
35 /* A coarse instruction classification. */
36 enum btrace_insn_class
37 {
38 /* The instruction is something not listed below. */
39 BTRACE_INSN_OTHER,
40
41 /* The instruction is a function call. */
42 BTRACE_INSN_CALL,
43
44 /* The instruction is a function return. */
45 BTRACE_INSN_RETURN,
46
47 /* The instruction is an unconditional jump. */
48 BTRACE_INSN_JUMP
49 };
50
51 /* A branch trace instruction.
52
53 This represents a single instruction in a branch trace. */
54 struct btrace_insn
55 {
56 /* The address of this instruction. */
57 CORE_ADDR pc;
58
59 /* The size of this instruction in bytes. */
60 gdb_byte size;
61
62 /* The instruction class of this instruction. */
63 enum btrace_insn_class iclass;
64 };
65
66 /* A vector of branch trace instructions. */
67 typedef struct btrace_insn btrace_insn_s;
68 DEF_VEC_O (btrace_insn_s);
69
70 /* A doubly-linked list of branch trace function segments. */
71 struct btrace_func_link
72 {
73 struct btrace_function *prev;
74 struct btrace_function *next;
75 };
76
77 /* Flags for btrace function segments. */
78 enum btrace_function_flag
79 {
80 /* The 'up' link interpretation.
81 If set, it points to the function segment we returned to.
82 If clear, it points to the function segment we called from. */
83 BFUN_UP_LINKS_TO_RET = (1 << 0),
84
85 /* The 'up' link points to a tail call. This obviously only makes sense
86 if bfun_up_links_to_ret is clear. */
87 BFUN_UP_LINKS_TO_TAILCALL = (1 << 1)
88 };
89
90 /* Decode errors for the BTS recording format. */
91 enum btrace_bts_error
92 {
93 /* The instruction trace overflowed the end of the trace block. */
94 BDE_BTS_OVERFLOW = 1,
95
96 /* The instruction size could not be determined. */
97 BDE_BTS_INSN_SIZE
98 };
99
100 /* A branch trace function segment.
101
102 This represents a function segment in a branch trace, i.e. a consecutive
103 number of instructions belonging to the same function.
104
105 In case of decode errors, we add an empty function segment to indicate
106 the gap in the trace.
107
108 We do not allow function segments without instructions otherwise. */
109 struct btrace_function
110 {
111 /* The full and minimal symbol for the function. Both may be NULL. */
112 struct minimal_symbol *msym;
113 struct symbol *sym;
114
115 /* The previous and next segment belonging to the same function.
116 If a function calls another function, the former will have at least
117 two segments: one before the call and another after the return. */
118 struct btrace_func_link segment;
119
120 /* The previous and next function in control flow order. */
121 struct btrace_func_link flow;
122
123 /* The directly preceding function segment in a (fake) call stack. */
124 struct btrace_function *up;
125
126 /* The instructions in this function segment.
127 The instruction vector will be empty if the function segment
128 represents a decode error. */
129 VEC (btrace_insn_s) *insn;
130
131 /* The error code of a decode error that led to a gap.
132 Must be zero unless INSN is empty; non-zero otherwise. */
133 int errcode;
134
135 /* The instruction number offset for the first instruction in this
136 function segment.
137 If INSN is empty this is the insn_offset of the succeding function
138 segment in control-flow order. */
139 unsigned int insn_offset;
140
141 /* The function number in control-flow order.
142 If INSN is empty indicating a gap in the trace due to a decode error,
143 we still count the gap as a function. */
144 unsigned int number;
145
146 /* The function level in a back trace across the entire branch trace.
147 A caller's level is one lower than the level of its callee.
148
149 Levels can be negative if we see returns for which we have not seen
150 the corresponding calls. The branch trace thread information provides
151 a fixup to normalize function levels so the smallest level is zero. */
152 int level;
153
154 /* A bit-vector of btrace_function_flag. */
155 enum btrace_function_flag flags;
156 };
157
158 /* A branch trace instruction iterator. */
159 struct btrace_insn_iterator
160 {
161 /* The branch trace function segment containing the instruction.
162 Will never be NULL. */
163 const struct btrace_function *function;
164
165 /* The index into the function segment's instruction vector. */
166 unsigned int index;
167 };
168
169 /* A branch trace function call iterator. */
170 struct btrace_call_iterator
171 {
172 /* The branch trace information for this thread. Will never be NULL. */
173 const struct btrace_thread_info *btinfo;
174
175 /* The branch trace function segment.
176 This will be NULL for the iterator pointing to the end of the trace. */
177 const struct btrace_function *function;
178 };
179
180 /* Branch trace iteration state for "record instruction-history". */
181 struct btrace_insn_history
182 {
183 /* The branch trace instruction range from BEGIN (inclusive) to
184 END (exclusive) that has been covered last time. */
185 struct btrace_insn_iterator begin;
186 struct btrace_insn_iterator end;
187 };
188
189 /* Branch trace iteration state for "record function-call-history". */
190 struct btrace_call_history
191 {
192 /* The branch trace function range from BEGIN (inclusive) to END (exclusive)
193 that has been covered last time. */
194 struct btrace_call_iterator begin;
195 struct btrace_call_iterator end;
196 };
197
198 /* Branch trace thread flags. */
199 enum btrace_thread_flag
200 {
201 /* The thread is to be stepped forwards. */
202 BTHR_STEP = (1 << 0),
203
204 /* The thread is to be stepped backwards. */
205 BTHR_RSTEP = (1 << 1),
206
207 /* The thread is to be continued forwards. */
208 BTHR_CONT = (1 << 2),
209
210 /* The thread is to be continued backwards. */
211 BTHR_RCONT = (1 << 3),
212
213 /* The thread is to be moved. */
214 BTHR_MOVE = (BTHR_STEP | BTHR_RSTEP | BTHR_CONT | BTHR_RCONT)
215 };
216
217 /* Branch trace information per thread.
218
219 This represents the branch trace configuration as well as the entry point
220 into the branch trace data. For the latter, it also contains the index into
221 an array of branch trace blocks used for iterating though the branch trace
222 blocks of a thread. */
223 struct btrace_thread_info
224 {
225 /* The target branch trace information for this thread.
226
227 This contains the branch trace configuration as well as any
228 target-specific information necessary for implementing branch tracing on
229 the underlying architecture. */
230 struct btrace_target_info *target;
231
232 /* The current branch trace for this thread (both inclusive).
233
234 The last instruction of END is the current instruction, which is not
235 part of the execution history.
236 Both will be NULL if there is no branch trace available. If there is
237 branch trace available, both will be non-NULL. */
238 struct btrace_function *begin;
239 struct btrace_function *end;
240
241 /* The function level offset. When added to each function's LEVEL,
242 this normalizes the function levels such that the smallest level
243 becomes zero. */
244 int level;
245
246 /* The number of gaps in the trace. */
247 unsigned int ngaps;
248
249 /* A bit-vector of btrace_thread_flag. */
250 enum btrace_thread_flag flags;
251
252 /* The instruction history iterator. */
253 struct btrace_insn_history *insn_history;
254
255 /* The function call history iterator. */
256 struct btrace_call_history *call_history;
257
258 /* The current replay position. NULL if not replaying.
259 Gaps are skipped during replay, so REPLAY always points to a valid
260 instruction. */
261 struct btrace_insn_iterator *replay;
262
263 /* Why the thread stopped, if we need to track it. */
264 enum target_stop_reason stop_reason;
265 };
266
267 /* Enable branch tracing for a thread. */
268 extern void btrace_enable (struct thread_info *tp,
269 const struct btrace_config *conf);
270
271 /* Get the branch trace configuration for a thread.
272 Return NULL if branch tracing is not enabled for that thread. */
273 extern const struct btrace_config *
274 btrace_conf (const struct btrace_thread_info *);
275
276 /* Disable branch tracing for a thread.
277 This will also delete the current branch trace data. */
278 extern void btrace_disable (struct thread_info *);
279
280 /* Disable branch tracing for a thread during teardown.
281 This is similar to btrace_disable, except that it will use
282 target_teardown_btrace instead of target_disable_btrace. */
283 extern void btrace_teardown (struct thread_info *);
284
285 /* Fetch the branch trace for a single thread. */
286 extern void btrace_fetch (struct thread_info *);
287
288 /* Clear the branch trace for a single thread. */
289 extern void btrace_clear (struct thread_info *);
290
291 /* Clear the branch trace for all threads when an object file goes away. */
292 extern void btrace_free_objfile (struct objfile *);
293
294 /* Parse a branch trace xml document XML into DATA. */
295 extern void parse_xml_btrace (struct btrace_data *data, const char *xml);
296
297 /* Parse a branch trace configuration xml document XML into CONF. */
298 extern void parse_xml_btrace_conf (struct btrace_config *conf, const char *xml);
299
300 /* Dereference a branch trace instruction iterator. Return a pointer to the
301 instruction the iterator points to.
302 May return NULL if the iterator points to a gap in the trace. */
303 extern const struct btrace_insn *
304 btrace_insn_get (const struct btrace_insn_iterator *);
305
306 /* Return the instruction number for a branch trace iterator.
307 Returns one past the maximum instruction number for the end iterator.
308 Returns zero if the iterator does not point to a valid instruction. */
309 extern unsigned int btrace_insn_number (const struct btrace_insn_iterator *);
310
311 /* Initialize a branch trace instruction iterator to point to the begin/end of
312 the branch trace. Throws an error if there is no branch trace. */
313 extern void btrace_insn_begin (struct btrace_insn_iterator *,
314 const struct btrace_thread_info *);
315 extern void btrace_insn_end (struct btrace_insn_iterator *,
316 const struct btrace_thread_info *);
317
318 /* Increment/decrement a branch trace instruction iterator by at most STRIDE
319 instructions. Return the number of instructions by which the instruction
320 iterator has been advanced.
321 Returns zero, if the operation failed or STRIDE had been zero. */
322 extern unsigned int btrace_insn_next (struct btrace_insn_iterator *,
323 unsigned int stride);
324 extern unsigned int btrace_insn_prev (struct btrace_insn_iterator *,
325 unsigned int stride);
326
327 /* Compare two branch trace instruction iterators.
328 Return a negative number if LHS < RHS.
329 Return zero if LHS == RHS.
330 Return a positive number if LHS > RHS. */
331 extern int btrace_insn_cmp (const struct btrace_insn_iterator *lhs,
332 const struct btrace_insn_iterator *rhs);
333
334 /* Find an instruction in the function branch trace by its number.
335 If the instruction is found, initialize the branch trace instruction
336 iterator to point to this instruction and return non-zero.
337 Return zero otherwise. */
338 extern int btrace_find_insn_by_number (struct btrace_insn_iterator *,
339 const struct btrace_thread_info *,
340 unsigned int number);
341
342 /* Dereference a branch trace call iterator. Return a pointer to the
343 function the iterator points to or NULL if the interator points past
344 the end of the branch trace. */
345 extern const struct btrace_function *
346 btrace_call_get (const struct btrace_call_iterator *);
347
348 /* Return the function number for a branch trace call iterator.
349 Returns one past the maximum function number for the end iterator.
350 Returns zero if the iterator does not point to a valid function. */
351 extern unsigned int btrace_call_number (const struct btrace_call_iterator *);
352
353 /* Initialize a branch trace call iterator to point to the begin/end of
354 the branch trace. Throws an error if there is no branch trace. */
355 extern void btrace_call_begin (struct btrace_call_iterator *,
356 const struct btrace_thread_info *);
357 extern void btrace_call_end (struct btrace_call_iterator *,
358 const struct btrace_thread_info *);
359
360 /* Increment/decrement a branch trace call iterator by at most STRIDE function
361 segments. Return the number of function segments by which the call
362 iterator has been advanced.
363 Returns zero, if the operation failed or STRIDE had been zero. */
364 extern unsigned int btrace_call_next (struct btrace_call_iterator *,
365 unsigned int stride);
366 extern unsigned int btrace_call_prev (struct btrace_call_iterator *,
367 unsigned int stride);
368
369 /* Compare two branch trace call iterators.
370 Return a negative number if LHS < RHS.
371 Return zero if LHS == RHS.
372 Return a positive number if LHS > RHS. */
373 extern int btrace_call_cmp (const struct btrace_call_iterator *lhs,
374 const struct btrace_call_iterator *rhs);
375
376 /* Find a function in the function branch trace by its NUMBER.
377 If the function is found, initialize the branch trace call
378 iterator to point to this function and return non-zero.
379 Return zero otherwise. */
380 extern int btrace_find_call_by_number (struct btrace_call_iterator *,
381 const struct btrace_thread_info *,
382 unsigned int number);
383
384 /* Set the branch trace instruction history from BEGIN (inclusive) to
385 END (exclusive). */
386 extern void btrace_set_insn_history (struct btrace_thread_info *,
387 const struct btrace_insn_iterator *begin,
388 const struct btrace_insn_iterator *end);
389
390 /* Set the branch trace function call history from BEGIN (inclusive) to
391 END (exclusive). */
392 extern void btrace_set_call_history (struct btrace_thread_info *,
393 const struct btrace_call_iterator *begin,
394 const struct btrace_call_iterator *end);
395
396 /* Determine if branch tracing is currently replaying TP. */
397 extern int btrace_is_replaying (struct thread_info *tp);
398
399 /* Return non-zero if the branch trace for TP is empty; zero otherwise. */
400 extern int btrace_is_empty (struct thread_info *tp);
401
402 /* Create a cleanup for DATA. */
403 extern struct cleanup *make_cleanup_btrace_data (struct btrace_data *data);
404
405 #endif /* BTRACE_H */
This page took 0.040679 seconds and 4 git commands to generate.