record-btrace: add bts buffer size configuration option
[external/binutils.git] / gdb / common / btrace-common.h
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.  */
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
64 /* A BTS configuration.  */
65
66 struct btrace_config_bts
67 {
68   /* The size of the branch trace buffer in bytes.  */
69   unsigned int size;
70 };
71
72 /* A branch tracing configuration.
73
74    This describes the requested configuration as well as the actually
75    obtained configuration.
76    We describe the configuration for all different formats so we can
77    easily switch between formats.  */
78
79 struct btrace_config
80 {
81   /* The branch tracing format.  */
82   enum btrace_format format;
83
84   /* The BTS format configuration.  */
85   struct btrace_config_bts bts;
86 };
87
88 /* Branch trace in BTS format.  */
89 struct btrace_data_bts
90 {
91   /* Branch trace is represented as a vector of branch trace blocks starting
92      with the most recent block.  */
93   VEC (btrace_block_s) *blocks;
94 };
95
96 /* The branch trace data.  */
97 struct btrace_data
98 {
99   enum btrace_format format;
100
101   union
102   {
103     /* Format == BTRACE_FORMAT_BTS.  */
104     struct btrace_data_bts bts;
105   } variant;
106 };
107
108 /* Target specific branch trace information.  */
109 struct btrace_target_info;
110
111 /* Enumeration of btrace read types.  */
112
113 enum btrace_read_type
114 {
115   /* Send all available trace.  */
116   BTRACE_READ_ALL,
117
118   /* Send all available trace, if it changed.  */
119   BTRACE_READ_NEW,
120
121   /* Send the trace since the last request.  This will fail if the trace
122      buffer overflowed.  */
123   BTRACE_READ_DELTA
124 };
125
126 /* Enumeration of btrace errors.  */
127
128 enum btrace_error
129 {
130   /* No error.  Everything is OK.  */
131   BTRACE_ERR_NONE,
132
133   /* An unknown error.  */
134   BTRACE_ERR_UNKNOWN,
135
136   /* Branch tracing is not supported on this system.  */
137   BTRACE_ERR_NOT_SUPPORTED,
138
139   /* The branch trace buffer overflowed; no delta read possible.  */
140   BTRACE_ERR_OVERFLOW
141 };
142
143 /* Return a string representation of FORMAT.  */
144 extern const char *btrace_format_string (enum btrace_format format);
145
146 /* Initialize DATA.  */
147 extern void btrace_data_init (struct btrace_data *data);
148
149 /* Cleanup DATA.  */
150 extern void btrace_data_fini (struct btrace_data *data);
151
152 /* Return non-zero if DATA is empty; zero otherwise.  */
153 extern int btrace_data_empty (struct btrace_data *data);
154
155 #endif /* BTRACE_COMMON_H */