1 /* Copyright (C) 2014-2019 Free Software Foundation, Inc.
3 Contributed by Intel Corp. <markus.t.metzger@intel.com>
5 This file is part of GDB.
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.
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.
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/>. */
20 #include "common-defs.h"
21 #include "btrace-common.h"
24 /* See btrace-common.h. */
27 btrace_format_string (enum btrace_format format)
31 case BTRACE_FORMAT_NONE:
32 return _("No or unknown format");
34 case BTRACE_FORMAT_BTS:
35 return _("Branch Trace Store");
37 case BTRACE_FORMAT_PT:
38 return _("Intel Processor Trace");
41 internal_error (__FILE__, __LINE__, _("Unknown branch trace format"));
44 /* See btrace-common.h. */
47 btrace_format_short_string (enum btrace_format format)
51 case BTRACE_FORMAT_NONE:
54 case BTRACE_FORMAT_BTS:
57 case BTRACE_FORMAT_PT:
61 internal_error (__FILE__, __LINE__, _("Unknown branch trace format"));
64 /* See btrace-common.h. */
71 case BTRACE_FORMAT_NONE:
75 case BTRACE_FORMAT_BTS:
76 VEC_free (btrace_block_s, variant.bts.blocks);
79 case BTRACE_FORMAT_PT:
80 xfree (variant.pt.data);
84 internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
87 /* See btrace-common.h. */
90 btrace_data::empty () const
94 case BTRACE_FORMAT_NONE:
97 case BTRACE_FORMAT_BTS:
98 return VEC_empty (btrace_block_s, variant.bts.blocks);
100 case BTRACE_FORMAT_PT:
101 return (variant.pt.size == 0);
104 internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));
107 /* See btrace-common.h. */
110 btrace_data::clear ()
113 format = BTRACE_FORMAT_NONE;
116 /* See btrace-common.h. */
119 btrace_data_append (struct btrace_data *dst,
120 const struct btrace_data *src)
124 case BTRACE_FORMAT_NONE:
127 case BTRACE_FORMAT_BTS:
133 case BTRACE_FORMAT_NONE:
134 dst->format = BTRACE_FORMAT_BTS;
135 dst->variant.bts.blocks = NULL;
138 case BTRACE_FORMAT_BTS:
142 /* We copy blocks in reverse order to have the oldest block at
144 blk = VEC_length (btrace_block_s, src->variant.bts.blocks);
147 btrace_block_s *block;
149 block = VEC_index (btrace_block_s, src->variant.bts.blocks,
152 VEC_safe_push (btrace_block_s, dst->variant.bts.blocks, block);
158 case BTRACE_FORMAT_PT:
164 case BTRACE_FORMAT_NONE:
165 dst->format = BTRACE_FORMAT_PT;
166 dst->variant.pt.data = NULL;
167 dst->variant.pt.size = 0;
170 case BTRACE_FORMAT_PT:
175 size = src->variant.pt.size + dst->variant.pt.size;
176 data = (gdb_byte *) xmalloc (size);
178 memcpy (data, dst->variant.pt.data, dst->variant.pt.size);
179 memcpy (data + dst->variant.pt.size, src->variant.pt.data,
180 src->variant.pt.size);
182 xfree (dst->variant.pt.data);
184 dst->variant.pt.data = data;
185 dst->variant.pt.size = size;
191 internal_error (__FILE__, __LINE__, _("Unkown branch trace format."));