Commit | Line | Data |
---|---|---|
02d27625 MM |
1 | /* Branch trace support for GDB, the GNU debugger. |
2 | ||
42a4f53d | 3 | Copyright (C) 2013-2019 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 | ||
1a5c2598 TT |
22 | #ifndef COMMON_BTRACE_COMMON_H |
23 | #define COMMON_BTRACE_COMMON_H | |
02d27625 MM |
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 | ||
02d27625 MM |
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 | { | |
969c39fb MM |
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. */ | |
02d27625 MM |
42 | CORE_ADDR begin; |
43 | ||
44 | /* The address of the first byte of the last instruction in the block. */ | |
45 | CORE_ADDR end; | |
02d27625 | 46 | |
46f29a9a AB |
47 | /* Simple constructor. */ |
48 | btrace_block (CORE_ADDR begin, CORE_ADDR end) | |
49 | : begin (begin), | |
50 | end (end) | |
51 | { | |
52 | /* Nothing. */ | |
53 | } | |
54 | }; | |
02d27625 | 55 | |
734b0e4b MM |
56 | /* Enumeration of btrace formats. */ |
57 | ||
58 | enum btrace_format | |
59 | { | |
60 | /* No branch trace format. */ | |
61 | BTRACE_FORMAT_NONE, | |
62 | ||
63 | /* Branch trace is in Branch Trace Store (BTS) format. | |
64 | Actually, the format is a sequence of blocks derived from BTS. */ | |
b20a6524 MM |
65 | BTRACE_FORMAT_BTS, |
66 | ||
bc504a31 | 67 | /* Branch trace is in Intel Processor Trace format. */ |
b20a6524 | 68 | BTRACE_FORMAT_PT |
734b0e4b MM |
69 | }; |
70 | ||
afb778a2 MM |
71 | /* An enumeration of cpu vendors. */ |
72 | ||
73 | enum btrace_cpu_vendor | |
74 | { | |
75 | /* We do not know this vendor. */ | |
76 | CV_UNKNOWN, | |
77 | ||
78 | /* Intel. */ | |
79 | CV_INTEL | |
80 | }; | |
81 | ||
82 | /* A cpu identifier. */ | |
83 | ||
84 | struct btrace_cpu | |
85 | { | |
86 | /* The processor vendor. */ | |
87 | enum btrace_cpu_vendor vendor; | |
88 | ||
89 | /* The cpu family. */ | |
90 | unsigned short family; | |
91 | ||
92 | /* The cpu model. */ | |
93 | unsigned char model; | |
94 | ||
95 | /* The cpu stepping. */ | |
96 | unsigned char stepping; | |
97 | }; | |
98 | ||
d33501a5 MM |
99 | /* A BTS configuration. */ |
100 | ||
101 | struct btrace_config_bts | |
102 | { | |
e7b01ce0 MM |
103 | /* The size of the branch trace buffer in bytes. |
104 | ||
105 | This is unsigned int and not size_t since it is registered as | |
106 | control variable for "set record btrace bts buffer-size". */ | |
d33501a5 MM |
107 | unsigned int size; |
108 | }; | |
109 | ||
bc504a31 | 110 | /* An Intel Processor Trace configuration. */ |
b20a6524 MM |
111 | |
112 | struct btrace_config_pt | |
113 | { | |
e7b01ce0 MM |
114 | /* The size of the branch trace buffer in bytes. |
115 | ||
116 | This is unsigned int and not size_t since it is registered as | |
117 | control variable for "set record btrace pt buffer-size". */ | |
b20a6524 MM |
118 | unsigned int size; |
119 | }; | |
120 | ||
f4abbc16 MM |
121 | /* A branch tracing configuration. |
122 | ||
123 | This describes the requested configuration as well as the actually | |
d33501a5 MM |
124 | obtained configuration. |
125 | We describe the configuration for all different formats so we can | |
126 | easily switch between formats. */ | |
f4abbc16 MM |
127 | |
128 | struct btrace_config | |
129 | { | |
130 | /* The branch tracing format. */ | |
131 | enum btrace_format format; | |
d33501a5 MM |
132 | |
133 | /* The BTS format configuration. */ | |
134 | struct btrace_config_bts bts; | |
b20a6524 | 135 | |
bc504a31 | 136 | /* The Intel Processor Trace format configuration. */ |
b20a6524 | 137 | struct btrace_config_pt pt; |
f4abbc16 MM |
138 | }; |
139 | ||
734b0e4b MM |
140 | /* Branch trace in BTS format. */ |
141 | struct btrace_data_bts | |
142 | { | |
143 | /* Branch trace is represented as a vector of branch trace blocks starting | |
46f29a9a AB |
144 | with the most recent block. This needs to be a pointer as we place |
145 | btrace_data_bts into a union. */ | |
146 | std::vector <btrace_block> *blocks; | |
734b0e4b MM |
147 | }; |
148 | ||
b20a6524 MM |
149 | /* Configuration information to go with the trace data. */ |
150 | struct btrace_data_pt_config | |
151 | { | |
152 | /* The processor on which the trace has been collected. */ | |
153 | struct btrace_cpu cpu; | |
154 | }; | |
155 | ||
bc504a31 | 156 | /* Branch trace in Intel Processor Trace format. */ |
b20a6524 MM |
157 | struct btrace_data_pt |
158 | { | |
159 | /* Some configuration information to go with the data. */ | |
160 | struct btrace_data_pt_config config; | |
161 | ||
162 | /* The trace data. */ | |
163 | gdb_byte *data; | |
164 | ||
165 | /* The size of DATA in bytes. */ | |
e7b01ce0 | 166 | size_t size; |
b20a6524 MM |
167 | }; |
168 | ||
734b0e4b MM |
169 | /* The branch trace data. */ |
170 | struct btrace_data | |
171 | { | |
8dcc53b3 TT |
172 | btrace_data () = default; |
173 | ||
174 | ~btrace_data () | |
175 | { | |
176 | fini (); | |
177 | } | |
178 | ||
179 | btrace_data &operator= (btrace_data &&other) | |
180 | { | |
181 | if (this != &other) | |
182 | { | |
183 | fini (); | |
184 | format = other.format; | |
185 | variant = other.variant; | |
186 | other.format = BTRACE_FORMAT_NONE; | |
187 | } | |
188 | return *this; | |
189 | } | |
190 | ||
191 | /* Return true if this is empty; false otherwise. */ | |
192 | bool empty () const; | |
193 | ||
194 | /* Clear this object. */ | |
195 | void clear (); | |
196 | ||
197 | enum btrace_format format = BTRACE_FORMAT_NONE; | |
734b0e4b MM |
198 | |
199 | union | |
200 | { | |
201 | /* Format == BTRACE_FORMAT_BTS. */ | |
202 | struct btrace_data_bts bts; | |
b20a6524 MM |
203 | |
204 | /* Format == BTRACE_FORMAT_PT. */ | |
205 | struct btrace_data_pt pt; | |
734b0e4b | 206 | } variant; |
8dcc53b3 TT |
207 | |
208 | private: | |
209 | ||
210 | DISABLE_COPY_AND_ASSIGN (btrace_data); | |
211 | ||
212 | void fini (); | |
734b0e4b MM |
213 | }; |
214 | ||
02d27625 MM |
215 | /* Target specific branch trace information. */ |
216 | struct btrace_target_info; | |
217 | ||
218 | /* Enumeration of btrace read types. */ | |
219 | ||
220 | enum btrace_read_type | |
221 | { | |
222 | /* Send all available trace. */ | |
864089d2 | 223 | BTRACE_READ_ALL, |
02d27625 MM |
224 | |
225 | /* Send all available trace, if it changed. */ | |
969c39fb MM |
226 | BTRACE_READ_NEW, |
227 | ||
228 | /* Send the trace since the last request. This will fail if the trace | |
229 | buffer overflowed. */ | |
230 | BTRACE_READ_DELTA | |
231 | }; | |
232 | ||
233 | /* Enumeration of btrace errors. */ | |
234 | ||
235 | enum btrace_error | |
236 | { | |
237 | /* No error. Everything is OK. */ | |
238 | BTRACE_ERR_NONE, | |
239 | ||
240 | /* An unknown error. */ | |
241 | BTRACE_ERR_UNKNOWN, | |
242 | ||
243 | /* Branch tracing is not supported on this system. */ | |
244 | BTRACE_ERR_NOT_SUPPORTED, | |
245 | ||
246 | /* The branch trace buffer overflowed; no delta read possible. */ | |
247 | BTRACE_ERR_OVERFLOW | |
02d27625 MM |
248 | }; |
249 | ||
734b0e4b MM |
250 | /* Return a string representation of FORMAT. */ |
251 | extern const char *btrace_format_string (enum btrace_format format); | |
252 | ||
38b022b4 SM |
253 | /* Return an abbreviation string representation of FORMAT. */ |
254 | extern const char *btrace_format_short_string (enum btrace_format format); | |
255 | ||
9be54cae MM |
256 | /* Append the branch trace data from SRC to the end of DST. |
257 | Both SRC and DST must use the same format. | |
258 | Returns zero on success; a negative number otherwise. */ | |
259 | extern int btrace_data_append (struct btrace_data *dst, | |
260 | const struct btrace_data *src); | |
261 | ||
1a5c2598 | 262 | #endif /* COMMON_BTRACE_COMMON_H */ |