1 /* Branch trace support for GDB, the GNU debugger.
3 Copyright (C) 2013-2024 Free Software Foundation, Inc.
5 Contributed by Intel Corp. <markus.t.metzger@intel.com>.
7 This file is part of GDB.
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.
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.
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/>. */
22 #ifndef COMMON_BTRACE_COMMON_H
23 #define COMMON_BTRACE_COMMON_H
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. */
29 /* A branch trace block.
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. */
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. */
42 /* The address of the first byte of the last instruction in the block. */
45 /* Simple constructor. */
46 btrace_block (CORE_ADDR begin
, CORE_ADDR end
)
54 /* Enumeration of btrace formats. */
58 /* No branch trace format. */
61 /* Branch trace is in Branch Trace Store (BTS) format.
62 Actually, the format is a sequence of blocks derived from BTS. */
65 /* Branch trace is in Intel Processor Trace format. */
69 /* An enumeration of cpu vendors. */
71 enum btrace_cpu_vendor
73 /* We do not know this vendor. */
83 /* A cpu identifier. */
87 /* The processor vendor. */
88 enum btrace_cpu_vendor vendor
;
91 unsigned short family
;
96 /* The cpu stepping. */
97 unsigned char stepping
;
100 /* A BTS configuration. */
102 struct btrace_config_bts
104 /* The size of the branch trace buffer in bytes.
106 This is unsigned int and not size_t since it is registered as
107 control variable for "set record btrace bts buffer-size". */
111 /* An Intel Processor Trace configuration. */
113 struct btrace_config_pt
115 /* The size of the branch trace buffer in bytes.
117 This is unsigned int and not size_t since it is registered as
118 control variable for "set record btrace pt buffer-size". */
121 /* Configuration bit for ptwrite packets.
123 If both gdb and gdbserver support this, gdb will try to enable ptwrite
124 packets when tracing is started. */
127 /* Event tracing setting. */
131 /* A branch tracing configuration.
133 This describes the requested configuration as well as the actually
134 obtained configuration.
135 We describe the configuration for all different formats so we can
136 easily switch between formats. */
140 /* The branch tracing format. */
141 enum btrace_format format
;
143 /* The BTS format configuration. */
144 struct btrace_config_bts bts
;
146 /* The Intel Processor Trace format configuration. */
147 struct btrace_config_pt pt
;
150 /* Branch trace in BTS format. */
151 struct btrace_data_bts
153 /* Branch trace is represented as a vector of branch trace blocks starting
154 with the most recent block. This needs to be a pointer as we place
155 btrace_data_bts into a union. */
156 std::vector
<btrace_block
> *blocks
;
159 /* Configuration information to go with the trace data. */
160 struct btrace_data_pt_config
162 /* The processor on which the trace has been collected. */
163 struct btrace_cpu cpu
;
166 /* Branch trace in Intel Processor Trace format. */
167 struct btrace_data_pt
169 /* Some configuration information to go with the data. */
170 struct btrace_data_pt_config config
;
172 /* The trace data. */
175 /* The size of DATA in bytes. */
179 /* The branch trace data. */
182 btrace_data () = default;
189 btrace_data
&operator= (btrace_data
&&other
)
194 format
= other
.format
;
195 variant
= other
.variant
;
196 other
.format
= BTRACE_FORMAT_NONE
;
201 /* Return true if this is empty; false otherwise. */
204 /* Clear this object. */
207 enum btrace_format format
= BTRACE_FORMAT_NONE
;
211 /* Format == BTRACE_FORMAT_BTS. */
212 struct btrace_data_bts bts
;
214 /* Format == BTRACE_FORMAT_PT. */
215 struct btrace_data_pt pt
;
220 DISABLE_COPY_AND_ASSIGN (btrace_data
);
225 /* Target specific branch trace information. */
226 struct btrace_target_info
228 btrace_target_info (ptid_t ptid
) : ptid (ptid
)
231 btrace_target_info (ptid_t ptid
, btrace_config conf
)
232 : ptid (ptid
), conf (conf
)
235 virtual ~btrace_target_info () = default;
237 /* The ptid of this thread. */
240 /* The obtained branch trace configuration. */
241 btrace_config conf
{};
244 /* Enumeration of btrace read types. */
246 enum btrace_read_type
248 /* Send all available trace. */
251 /* Send all available trace, if it changed. */
254 /* Send the trace since the last request. This will fail if the trace
255 buffer overflowed. */
259 /* Enumeration of btrace errors. */
263 /* No error. Everything is OK. */
266 /* An unknown error. */
269 /* Branch tracing is not supported on this system. */
270 BTRACE_ERR_NOT_SUPPORTED
,
272 /* The branch trace buffer overflowed; no delta read possible. */
276 /* Return a string representation of FORMAT. */
277 extern const char *btrace_format_string (enum btrace_format format
);
279 /* Return an abbreviation string representation of FORMAT. */
280 extern const char *btrace_format_short_string (enum btrace_format format
);
282 /* Append the branch trace data from SRC to the end of DST.
283 Both SRC and DST must use the same format.
284 Returns zero on success; a negative number otherwise. */
285 extern int btrace_data_append (struct btrace_data
*dst
,
286 const struct btrace_data
*src
);
288 #endif /* COMMON_BTRACE_COMMON_H */