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