Import gdb-7.10.1
[dragonfly.git] / contrib / gdb-7 / gdb / nat / linux-btrace.h
1 /* Linux-dependent part of branch trace support for GDB, and GDBserver.
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 LINUX_BTRACE_H
23 #define LINUX_BTRACE_H
24
25 #include "btrace-common.h"
26 #include "vec.h"
27 #if HAVE_LINUX_PERF_EVENT_H
28 #  include <linux/perf_event.h>
29 #endif
30
31 struct target_ops;
32
33 #if HAVE_LINUX_PERF_EVENT_H
34 /* A Linux perf event buffer.  */
35 struct perf_event_buffer
36 {
37   /* The mapped memory.  */
38   const uint8_t *mem;
39
40   /* The size of the mapped memory in bytes.  */
41   unsigned long long size;
42
43   /* A pointer to the data_head field for this buffer. */
44   volatile unsigned long long *data_head;
45
46   /* The data_head value from the last read.  */
47   unsigned long long last_head;
48 };
49
50 /* Branch trace target information for BTS tracing.  */
51 struct btrace_tinfo_bts
52 {
53   /* The Linux perf_event configuration for collecting the branch trace.  */
54   struct perf_event_attr attr;
55
56   /* The perf event file.  */
57   int file;
58
59   /* The perf event configuration page. */
60   volatile struct perf_event_mmap_page *header;
61
62   /* The BTS perf event buffer.  */
63   struct perf_event_buffer bts;
64 };
65
66 /* Branch trace target information for Intel(R) Processor Trace.  */
67 struct btrace_tinfo_pt
68 {
69   /* The Linux perf_event configuration for collecting the branch trace.  */
70   struct perf_event_attr attr;
71
72   /* The perf event file.  */
73   int file;
74
75   /* The perf event configuration page. */
76   volatile struct perf_event_mmap_page *header;
77
78   /* The trace perf event buffer.  */
79   struct perf_event_buffer pt;
80 };
81 #endif /* HAVE_LINUX_PERF_EVENT_H */
82
83 /* Branch trace target information per thread.  */
84 struct btrace_target_info
85 {
86   /* The ptid of this thread.  */
87   ptid_t ptid;
88
89   /* The obtained branch trace configuration.  */
90   struct btrace_config conf;
91
92 #if HAVE_LINUX_PERF_EVENT_H
93   /* The branch tracing format specific information.  */
94   union
95   {
96     /* CONF.FORMAT == BTRACE_FORMAT_BTS.  */
97     struct btrace_tinfo_bts bts;
98
99     /* CONF.FORMAT == BTRACE_FORMAT_PT.  */
100     struct btrace_tinfo_pt pt;
101   } variant;
102 #endif /* HAVE_LINUX_PERF_EVENT_H */
103
104   /* The size of a pointer in bits for this thread.
105      The information is used to identify kernel addresses in order to skip
106      records from/to kernel space.  */
107   int ptr_bits;
108 };
109
110 /* See to_supports_btrace in target.h.  */
111 extern int linux_supports_btrace (struct target_ops *, enum btrace_format);
112
113 /* See to_enable_btrace in target.h.  */
114 extern struct btrace_target_info *
115   linux_enable_btrace (ptid_t ptid, const struct btrace_config *conf);
116
117 /* See to_disable_btrace in target.h.  */
118 extern enum btrace_error linux_disable_btrace (struct btrace_target_info *ti);
119
120 /* See to_read_btrace in target.h.  */
121 extern enum btrace_error linux_read_btrace (struct btrace_data *btrace,
122                                             struct btrace_target_info *btinfo,
123                                             enum btrace_read_type type);
124
125 /* See to_btrace_conf in target.h.  */
126 extern const struct btrace_config *
127   linux_btrace_conf (const struct btrace_target_info *);
128
129 #endif /* LINUX_BTRACE_H */