GDBserver

btrace-common.h
Go to the documentation of this file.
1 /* Branch trace support for GDB, the GNU debugger.
2
3 Copyright (C) 2013-2018 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. */
37 struct btrace_block
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. */
42 CORE_ADDR begin;
43
44 /* The address of the first byte of the last instruction in the block. */
45 CORE_ADDR end;
46 };
47
48 /* Define functions operating on a vector of branch trace blocks. */
49 typedef struct btrace_block btrace_block_s;
50 DEF_VEC_O (btrace_block_s);
51
52 /* Enumeration of btrace formats. */
53
54 enum btrace_format
55 {
56 /* No branch trace format. */
57 BTRACE_FORMAT_NONE,
58
59 /* Branch trace is in Branch Trace Store (BTS) format.
60 Actually, the format is a sequence of blocks derived from BTS. */
61 BTRACE_FORMAT_BTS,
62
63 /* Branch trace is in Intel Processor Trace format. */
64 BTRACE_FORMAT_PT
65 };
66
67 /* An enumeration of cpu vendors. */
68
69 enum btrace_cpu_vendor
70 {
71 /* We do not know this vendor. */
72 CV_UNKNOWN,
73
74 /* Intel. */
75 CV_INTEL
76 };
77
78 /* A cpu identifier. */
79
80 struct btrace_cpu
81 {
82 /* The processor vendor. */
83 enum btrace_cpu_vendor 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
97 struct btrace_config_bts
98 {
99 /* The size of the branch trace buffer in bytes.
100
101 This is unsigned int and not size_t since it is registered as
102 control variable for "set record btrace bts buffer-size". */
103 unsigned int size;
104 };
105
106 /* An Intel Processor Trace configuration. */
107
108 struct btrace_config_pt
109 {
110 /* The size of the branch trace buffer in bytes.
111
112 This is unsigned int and not size_t since it is registered as
113 control variable for "set record btrace pt buffer-size". */
114 unsigned int size;
115 };
116
117 /* A branch tracing configuration.
118
119 This describes the requested configuration as well as the actually
120 obtained configuration.
121 We describe the configuration for all different formats so we can
122 easily switch between formats. */
123
124 struct btrace_config
125 {
126 /* The branch tracing format. */
127 enum btrace_format format;
128
129 /* The BTS format configuration. */
130 struct btrace_config_bts bts;
131
132 /* The Intel Processor Trace format configuration. */
133 struct btrace_config_pt pt;
134 };
135
136 /* Branch trace in BTS format. */
137 struct btrace_data_bts
138 {
139 /* Branch trace is represented as a vector of branch trace blocks starting
140 with the most recent block. */
141 VEC (btrace_block_s) *blocks;
142 };
143
144 /* Configuration information to go with the trace data. */
145 struct btrace_data_pt_config
146 {
147 /* The processor on which the trace has been collected. */
148 struct btrace_cpu cpu;
149 };
150
151 /* Branch trace in Intel Processor Trace format. */
152 struct btrace_data_pt
153 {
154 /* Some configuration information to go with the data. */
155 struct btrace_data_pt_config config;
156
157 /* The trace data. */
158 gdb_byte *data;
159
160 /* The size of DATA in bytes. */
161 size_t size;
162 };
163
164 /* The branch trace data. */
165 struct btrace_data
166 {
167 enum btrace_format format;
168
169 union
170 {
171 /* Format == BTRACE_FORMAT_BTS. */
172 struct btrace_data_bts bts;
173
174 /* Format == BTRACE_FORMAT_PT. */
175 struct btrace_data_pt pt;
176 } variant;
177 };
178
179 /* Target specific branch trace information. */
180 struct btrace_target_info;
181
182 /* Enumeration of btrace read types. */
183
184 enum btrace_read_type
185 {
186 /* Send all available trace. */
187 BTRACE_READ_ALL,
188
189 /* Send all available trace, if it changed. */
190 BTRACE_READ_NEW,
191
192 /* Send the trace since the last request. This will fail if the trace
193 buffer overflowed. */
194 BTRACE_READ_DELTA
195 };
196
197 /* Enumeration of btrace errors. */
198
199 enum btrace_error
200 {
201 /* No error. Everything is OK. */
202 BTRACE_ERR_NONE,
203
204 /* An unknown error. */
205 BTRACE_ERR_UNKNOWN,
206
207 /* Branch tracing is not supported on this system. */
208 BTRACE_ERR_NOT_SUPPORTED,
209
210 /* The branch trace buffer overflowed; no delta read possible. */
211 BTRACE_ERR_OVERFLOW
212 };
213
214 /* Return a string representation of FORMAT. */
215 extern const char *btrace_format_string (enum btrace_format format);
216
217 /* Return an abbreviation string representation of FORMAT. */
218 extern const char *btrace_format_short_string (enum btrace_format format);
219
220 /* Initialize DATA. */
221 extern void btrace_data_init (struct btrace_data *data);
222
223 /* Cleanup DATA. */
224 extern void btrace_data_fini (struct btrace_data *data);
225
226 /* Clear DATA. */
227 extern void btrace_data_clear (struct btrace_data *data);
228
229 /* Return non-zero if DATA is empty; zero otherwise. */
230 extern int btrace_data_empty (struct btrace_data *data);
231
232 /* Append the branch trace data from SRC to the end of DST.
233 Both SRC and DST must use the same format.
234 Returns zero on success; a negative number otherwise. */
235 extern int btrace_data_append (struct btrace_data *dst,
236 const struct btrace_data *src);
237
238 #endif /* BTRACE_COMMON_H */
btrace_data_clear
void btrace_data_clear(struct btrace_data *data)
Definition: btrace-common.c:118
btrace_config::bts
struct btrace_config_bts bts
Definition: btrace-common.h:130
BTRACE_ERR_OVERFLOW
Definition: btrace-common.h:211
BTRACE_READ_NEW
Definition: btrace-common.h:190
btrace_data_pt_config::cpu
struct btrace_cpu cpu
Definition: btrace-common.h:148
btrace_cpu::family
unsigned short family
Definition: btrace-common.h:86
btrace_target_info
Definition: linux-btrace.h:85
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
btrace_block::begin
CORE_ADDR begin
Definition: btrace-common.h:42
btrace_data_fini
void btrace_data_fini(struct btrace_data *data)
Definition: btrace-common.c:75
btrace_data_bts::VEC
VEC(btrace_block_s) *blocks
DEF_VEC_O
DEF_VEC_O(btrace_block_s)
btrace_config_pt::size
unsigned int size
Definition: btrace-common.h:114
btrace_format_short_string
const char * btrace_format_short_string(enum btrace_format format)
Definition: btrace-common.c:47
btrace_data::bts
struct btrace_data_bts bts
Definition: btrace-common.h:172
btrace_block::end
CORE_ADDR end
Definition: btrace-common.h:45
BTRACE_READ_DELTA
Definition: btrace-common.h:194
CV_INTEL
Definition: btrace-common.h:75
BTRACE_READ_ALL
Definition: btrace-common.h:187
btrace_config_pt
Definition: btrace-common.h:108
btrace_format
btrace_format
Definition: btrace-common.h:54
btrace_cpu
Definition: btrace-common.h:80
btrace_cpu::vendor
enum btrace_cpu_vendor vendor
Definition: btrace-common.h:83
btrace_data_pt
Definition: btrace-common.h:152
btrace_block
Definition: btrace-common.h:37
btrace_data_bts
Definition: btrace-common.h:137
btrace_data::variant
union btrace_data::@9 variant
btrace_data_pt_config
Definition: btrace-common.h:145
btrace_data::format
enum btrace_format format
Definition: btrace-common.h:167
btrace_data_empty
int btrace_data_empty(struct btrace_data *data)
Definition: btrace-common.c:98
btrace_read_type
btrace_read_type
Definition: btrace-common.h:184
BTRACE_FORMAT_NONE
Definition: btrace-common.h:57
btrace_cpu::model
unsigned char model
Definition: btrace-common.h:89
btrace_data::pt
struct btrace_data_pt pt
Definition: btrace-common.h:175
BTRACE_FORMAT_PT
Definition: btrace-common.h:64
btrace_error
btrace_error
Definition: btrace-common.h:199
BTRACE_ERR_NOT_SUPPORTED
Definition: btrace-common.h:208
CV_UNKNOWN
Definition: btrace-common.h:72
btrace_format_string
const char * btrace_format_string(enum btrace_format format)
Definition: btrace-common.c:27
btrace_config::pt
struct btrace_config_pt pt
Definition: btrace-common.h:133
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
BTRACE_FORMAT_BTS
Definition: btrace-common.h:61
btrace_config
Definition: btrace-common.h:124
btrace_config_bts::size
unsigned int size
Definition: btrace-common.h:103
btrace_cpu_vendor
btrace_cpu_vendor
Definition: btrace-common.h:69
btrace_data_pt::config
struct btrace_data_pt_config config
Definition: btrace-common.h:155
btrace_data_append
int btrace_data_append(struct btrace_data *dst, const struct btrace_data *src)
Definition: btrace-common.c:127
btrace_data_pt::data
gdb_byte * data
Definition: btrace-common.h:158
btrace_data_init
void btrace_data_init(struct btrace_data *data)
Definition: btrace-common.c:67
btrace_data_pt::size
size_t size
Definition: btrace-common.h:161
btrace_config_bts
Definition: btrace-common.h:97
btrace_cpu::stepping
unsigned char stepping
Definition: btrace-common.h:92
btrace_config::format
enum btrace_format format
Definition: btrace-common.h:127
BTRACE_ERR_NONE
Definition: btrace-common.h:202
BTRACE_ERR_UNKNOWN
Definition: btrace-common.h:205
vec.h
btrace_data
Definition: btrace-common.h:165