Automatic date update in version.in
[deliverable/binutils-gdb.git] / gdb / common / btrace-common.c
CommitLineData
734b0e4b
MM
1/* Copyright (C) 2014-2015 Free Software Foundation, Inc.
2
3 Contributed by Intel Corp. <markus.t.metzger@intel.com>
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "common-defs.h"
21#include "btrace-common.h"
22
23
24/* See btrace-common.h. */
25
26const char *
27btrace_format_string (enum btrace_format format)
28{
29 switch (format)
30 {
31 case BTRACE_FORMAT_NONE:
32 return _("No or unknown format");
33
34 case BTRACE_FORMAT_BTS:
35 return _("Branch Trace Store");
b20a6524
MM
36
37 case BTRACE_FORMAT_PT:
38 return _("Intel(R) Processor Trace");
734b0e4b
MM
39 }
40
41 internal_error (__FILE__, __LINE__, _("Unknown branch trace format"));
42}
43
44/* See btrace-common.h. */
45
46void
47btrace_data_init (struct btrace_data *data)
48{
49 data->format = BTRACE_FORMAT_NONE;
50}
51
52/* See btrace-common.h. */
53
54void
55btrace_data_fini (struct btrace_data *data)
56{
57 switch (data->format)
58 {
59 case BTRACE_FORMAT_NONE:
60 /* Nothing to do. */
61 return;
62
63 case BTRACE_FORMAT_BTS:
64 VEC_free (btrace_block_s, data->variant.bts.blocks);
65 return;
b20a6524
MM
66
67 case BTRACE_FORMAT_PT:
68 xfree (data->variant.pt.data);
69 return;
734b0e4b
MM
70 }
71
72 internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
73}
74
75/* See btrace-common.h. */
76
77int
78btrace_data_empty (struct btrace_data *data)
79{
80 switch (data->format)
81 {
82 case BTRACE_FORMAT_NONE:
83 return 1;
84
85 case BTRACE_FORMAT_BTS:
86 return VEC_empty (btrace_block_s, data->variant.bts.blocks);
b20a6524
MM
87
88 case BTRACE_FORMAT_PT:
89 return (data->variant.pt.size == 0);
734b0e4b
MM
90 }
91
92 internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
93}
9be54cae
MM
94
95/* See btrace-common.h. */
96
97void
98btrace_data_clear (struct btrace_data *data)
99{
100 btrace_data_fini (data);
101 btrace_data_init (data);
102}
103
104/* See btrace-common.h. */
105
106int
107btrace_data_append (struct btrace_data *dst,
108 const struct btrace_data *src)
109{
110 switch (src->format)
111 {
112 case BTRACE_FORMAT_NONE:
113 return 0;
114
115 case BTRACE_FORMAT_BTS:
116 switch (dst->format)
117 {
118 default:
119 return -1;
120
121 case BTRACE_FORMAT_NONE:
122 dst->format = BTRACE_FORMAT_BTS;
123 dst->variant.bts.blocks = NULL;
124
125 /* Fall-through. */
126 case BTRACE_FORMAT_BTS:
127 {
128 unsigned int blk;
129
130 /* We copy blocks in reverse order to have the oldest block at
131 index zero. */
132 blk = VEC_length (btrace_block_s, src->variant.bts.blocks);
133 while (blk != 0)
134 {
135 btrace_block_s *block;
136
137 block = VEC_index (btrace_block_s, src->variant.bts.blocks,
138 --blk);
139
140 VEC_safe_push (btrace_block_s, dst->variant.bts.blocks, block);
141 }
142 }
143 }
144 return 0;
145
146 case BTRACE_FORMAT_PT:
147 switch (dst->format)
148 {
149 default:
150 return -1;
151
152 case BTRACE_FORMAT_NONE:
153 dst->format = BTRACE_FORMAT_PT;
154 dst->variant.pt.data = NULL;
155 dst->variant.pt.size = 0;
156
157 /* fall-through. */
158 case BTRACE_FORMAT_BTS:
159 {
160 gdb_byte *data;
161 unsigned long size;
162
163 size = src->variant.pt.size + dst->variant.pt.size;
164 data = xmalloc (size);
165
166 memcpy (data, dst->variant.pt.data, dst->variant.pt.size);
167 memcpy (data + dst->variant.pt.size, src->variant.pt.data,
168 src->variant.pt.size);
169
170 xfree (dst->variant.pt.data);
171
172 dst->variant.pt.data = data;
173 dst->variant.pt.size = size;
174 }
175 }
176 return 0;
177 }
178
179 internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
180}
This page took 0.060938 seconds and 4 git commands to generate.