aboutsummaryrefslogtreecommitdiff
path: root/gdb/btrace.h
blob: 9bd71764eb43359930f3adb58adfa3a91f36f8a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* Branch trace support for GDB, the GNU debugger.

   Copyright (C) 2013-2014 Free Software Foundation, Inc.

   Contributed by Intel Corp. <markus.t.metzger@intel.com>.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#ifndef BTRACE_H
#define BTRACE_H

/* Branch tracing (btrace) is a per-thread control-flow execution trace of the
   inferior.  For presentation purposes, the branch trace is represented as a
   list of sequential control-flow blocks, one such list per thread.  */

#include "btrace-common.h"

struct thread_info;

/* A branch trace instruction.

   This represents a single instruction in a branch trace.  */
struct btrace_inst
{
  /* The address of this instruction.  */
  CORE_ADDR pc;
};

/* A branch trace function.

   This represents a function segment in a branch trace, i.e. a consecutive
   number of instructions belonging to the same function.  */
struct btrace_func
{
  /* The full and minimal symbol for the function.  One of them may be NULL.  */
  struct minimal_symbol *msym;
  struct symbol *sym;

  /* The source line range of this function segment (both inclusive).  */
  int lbegin, lend;

  /* The instruction number range in the instruction trace corresponding
     to this function segment (both inclusive).  */
  unsigned int ibegin, iend;
};

/* Branch trace may also be represented as a vector of:

   - branch trace instructions starting with the oldest instruction.
   - branch trace functions starting with the oldest function.  */
typedef struct btrace_inst btrace_inst_s;
typedef struct btrace_func btrace_func_s;

/* Define functions operating on branch trace vectors.  */
DEF_VEC_O (btrace_inst_s);
DEF_VEC_O (btrace_func_s);

/* Branch trace iteration state for "record instruction-history".  */
struct btrace_insn_iterator
{
  /* The instruction index range from begin (inclusive) to end (exclusive)
     that has been covered last time.
     If end < begin, the branch trace has just been updated.  */
  unsigned int begin;
  unsigned int end;
};

/* Branch trace iteration state for "record function-call-history".  */
struct btrace_func_iterator
{
  /* The function index range from begin (inclusive) to end (exclusive)
     that has been covered last time.
     If end < begin, the branch trace has just been updated.  */
  unsigned int begin;
  unsigned int end;
};

/* Branch trace information per thread.

   This represents the branch trace configuration as well as the entry point
   into the branch trace data.  For the latter, it also contains the index into
   an array of branch trace blocks used for iterating though the branch trace
   blocks of a thread.  */
struct btrace_thread_info
{
  /* The target branch trace information for this thread.

     This contains the branch trace configuration as well as any
     target-specific information necessary for implementing branch tracing on
     the underlying architecture.  */
  struct btrace_target_info *target;

  /* The current branch trace for this thread.  */
  VEC (btrace_block_s) *btrace;
  VEC (btrace_inst_s) *itrace;
  VEC (btrace_func_s) *ftrace;

  /* The instruction history iterator.  */
  struct btrace_insn_iterator insn_iterator;

  /* The function call history iterator.  */
  struct btrace_func_iterator func_iterator;
};

/* Enable branch tracing for a thread.  */
extern void btrace_enable (struct thread_info *tp);

/* Disable branch tracing for a thread.
   This will also delete the current branch trace data.  */
extern void btrace_disable (struct thread_info *);

/* Disable branch tracing for a thread during teardown.
   This is similar to btrace_disable, except that it will use
   target_teardown_btrace instead of target_disable_btrace.  */
extern void btrace_teardown (struct thread_info *);

/* Fetch the branch trace for a single thread.  */
extern void btrace_fetch (struct thread_info *);

/* Clear the branch trace for a single thread.  */
extern void btrace_clear (struct thread_info *);

/* Clear the branch trace for all threads when an object file goes away.  */
extern void btrace_free_objfile (struct objfile *);

/* Parse a branch trace xml document into a block vector.  */
extern VEC (btrace_block_s) *parse_xml_btrace (const char*);

#endif /* BTRACE_H */