GDB (xrefs)
btrace-common.h
Go to the documentation of this file.
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_COMMON_H
23 #define BTRACE_COMMON_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 "vec.h"
30 
31 /* A branch trace block.
32 
33  This represents a block of sequential control-flow. Adjacent blocks will be
34  connected via calls, returns, or jumps. The latter can be direct or
35  indirect, conditional or unconditional. Branches can further be
36  asynchronous, e.g. interrupts. */
38 {
39  /* The address of the first byte of the first instruction in the block.
40  The address may be zero if we do not know the beginning of this block,
41  such as for the first block in a delta trace. */
43 
44  /* The address of the first byte of the last instruction in the block. */
46 };
47 
48 /* Define functions operating on a vector of branch trace blocks. */
51 
52 /* Enumeration of btrace formats. */
53 
55 {
56  /* No branch trace format. */
58 
59  /* Branch trace is in Branch Trace Store (BTS) format.
60  Actually, the format is a sequence of blocks derived from BTS. */
62 
63  /* Branch trace is in Intel(R) Processor Trace format. */
65 };
66 
67 /* An enumeration of cpu vendors. */
68 
70 {
71  /* We do not know this vendor. */
73 
74  /* Intel. */
76 };
77 
78 /* A cpu identifier. */
79 
80 struct btrace_cpu
81 {
82  /* The processor vendor. */
84 
85  /* The cpu family. */
86  unsigned short family;
87 
88  /* The cpu model. */
89  unsigned char model;
90 
91  /* The cpu stepping. */
92  unsigned char stepping;
93 };
94 
95 /* A BTS configuration. */
96 
98 {
99  /* The size of the branch trace buffer in bytes. */
100  unsigned int size;
101 };
102 
103 /* An Intel(R) Processor Trace configuration. */
104 
106 {
107  /* The size of the branch trace buffer in bytes. */
108  unsigned int size;
109 };
110 
111 /* A branch tracing configuration.
112 
113  This describes the requested configuration as well as the actually
114  obtained configuration.
115  We describe the configuration for all different formats so we can
116  easily switch between formats. */
117 
119 {
120  /* The branch tracing format. */
122 
123  /* The BTS format configuration. */
125 
126  /* The Intel(R) Processor Trace format configuration. */
128 };
129 
130 /* Branch trace in BTS format. */
132 {
133  /* Branch trace is represented as a vector of branch trace blocks starting
134  with the most recent block. */
135  VEC (btrace_block_s) *blocks;
136 };
137 
138 /* Configuration information to go with the trace data. */
140 {
141  /* The processor on which the trace has been collected. */
142  struct btrace_cpu cpu;
143 };
144 
145 /* Branch trace in Intel(R) Processor Trace format. */
147 {
148  /* Some configuration information to go with the data. */
150 
151  /* The trace data. */
153 
154  /* The size of DATA in bytes. */
155  unsigned long size;
156 };
157 
158 /* The branch trace data. */
160 {
162 
163  union
164  {
165  /* Format == BTRACE_FORMAT_BTS. */
167 
168  /* Format == BTRACE_FORMAT_PT. */
170  } variant;
171 };
172 
173 /* Target specific branch trace information. */
174 struct btrace_target_info;
175 
176 /* Enumeration of btrace read types. */
177 
179 {
180  /* Send all available trace. */
182 
183  /* Send all available trace, if it changed. */
185 
186  /* Send the trace since the last request. This will fail if the trace
187  buffer overflowed. */
189 };
190 
191 /* Enumeration of btrace errors. */
192 
194 {
195  /* No error. Everything is OK. */
197 
198  /* An unknown error. */
200 
201  /* Branch tracing is not supported on this system. */
203 
204  /* The branch trace buffer overflowed; no delta read possible. */
206 };
207 
208 /* Return a string representation of FORMAT. */
209 extern const char *btrace_format_string (enum btrace_format format);
210 
211 /* Initialize DATA. */
212 extern void btrace_data_init (struct btrace_data *data);
213 
214 /* Cleanup DATA. */
215 extern void btrace_data_fini (struct btrace_data *data);
216 
217 /* Clear DATA. */
218 extern void btrace_data_clear (struct btrace_data *data);
219 
220 /* Return non-zero if DATA is empty; zero otherwise. */
221 extern int btrace_data_empty (struct btrace_data *data);
222 
223 /* Append the branch trace data from SRC to the end of DST.
224  Both SRC and DST must use the same format.
225  Returns zero on success; a negative number otherwise. */
226 extern int btrace_data_append (struct btrace_data *dst,
227  const struct btrace_data *src);
228 
229 #endif /* BTRACE_COMMON_H */
void btrace_data_clear(struct btrace_data *data)
Definition: btrace-common.c:98
struct btrace_config_bts bts
struct btrace_cpu cpu
unsigned short family
Definition: btrace-common.h:86
bfd_vma CORE_ADDR
Definition: common-types.h:41
CORE_ADDR begin
Definition: btrace-common.h:42
void btrace_data_fini(struct btrace_data *data)
Definition: btrace-common.c:55
DEF_VEC_O(btrace_block_s)
unsigned int size
struct btrace_data_bts bts
CORE_ADDR end
Definition: btrace-common.h:45
btrace_format
Definition: btrace-common.h:54
union btrace_data::@40 variant
enum btrace_cpu_vendor vendor
Definition: btrace-common.h:83
enum btrace_format format
int btrace_data_empty(struct btrace_data *data)
Definition: btrace-common.c:78
btrace_read_type
unsigned char model
Definition: btrace-common.h:89
struct btrace_data_pt pt
unsigned long size
btrace_error
VEC(btrace_block_s)*blocks
const char * btrace_format_string(enum btrace_format format)
Definition: btrace-common.c:27
struct btrace_config_pt pt
bfd_byte gdb_byte
Definition: common-types.h:38
unsigned int size
btrace_cpu_vendor
Definition: btrace-common.h:69
struct btrace_data_pt_config config
int btrace_data_append(struct btrace_data *dst, const struct btrace_data *src)
gdb_byte * data
void btrace_data_init(struct btrace_data *data)
Definition: btrace-common.c:47
unsigned char stepping
Definition: btrace-common.h:92
enum btrace_format format