/* Branch trace support for GDB, the GNU debugger.
- Copyright (C) 2013-2015 Free Software Foundation, Inc.
+ Copyright (C) 2013-2016 Free Software Foundation, Inc.
Contributed by Intel Corp. <markus.t.metzger@intel.com>
{
struct btrace_function *bfun;
- bfun = xzalloc (sizeof (*bfun));
+ bfun = XCNEW (struct btrace_function);
bfun->msym = mfun;
bfun->sym = fun;
insn.pc = pc;
insn.size = size;
insn.iclass = ftrace_classify_insn (gdbarch, pc);
+ insn.flags = 0;
ftrace_update_insns (end, &insn);
}
}
+/* Return the btrace instruction flags for INSN. */
+
+static enum btrace_insn_flag
+pt_btrace_insn_flags (const struct pt_insn *insn)
+{
+ enum btrace_insn_flag flags = 0;
+
+ if (insn->speculative)
+ flags |= BTRACE_INSN_FLAG_SPECULATIVE;
+
+ return flags;
+}
+
/* Add function branch trace using DECODER. */
static void
if (errcode < 0)
{
if (errcode != -pte_eos)
- warning (_("Failed to synchronize onto the Intel(R) Processor "
+ warning (_("Failed to synchronize onto the Intel Processor "
"Trace stream: %s."), pt_errstr (pt_errcode (errcode)));
break;
}
btinsn.pc = (CORE_ADDR) insn.ip;
btinsn.size = (gdb_byte) insn.size;
btinsn.iclass = pt_reclassify_insn (insn.iclass);
+ btinsn.flags = pt_btrace_insn_flags (&insn);
ftrace_update_insns (end, &btinsn);
}
pt_insn_get_offset (decoder, &offset);
- warning (_("Failed to decode Intel(R) Processor Trace near trace "
+ warning (_("Failed to decode Intel Processor Trace near trace "
"offset 0x%" PRIx64 " near recorded PC 0x%" PRIx64 ": %s."),
offset, insn.ip, pt_errstr (pt_errcode (errcode)));
static int
btrace_pt_readmem_callback (gdb_byte *buffer, size_t size,
- const struct pt_asid *asid, CORE_ADDR pc,
+ const struct pt_asid *asid, uint64_t pc,
void *context)
{
- int errcode;
+ int result, errcode;
+ result = (int) size;
TRY
{
- errcode = target_read_code (pc, buffer, size);
+ errcode = target_read_code ((CORE_ADDR) pc, buffer, size);
if (errcode != 0)
- return -pte_nomap;
+ result = -pte_nomap;
}
CATCH (error, RETURN_MASK_ERROR)
{
- return -pte_nomap;
+ result = -pte_nomap;
}
END_CATCH
- return size;
+ return result;
}
/* Translate the vendor from one enum to another. */
btrace_add_pc (tp);
}
-/* Compute the function branch trace from Intel(R) Processor Trace. */
+/* Compute the function branch trace from Intel Processor Trace
+ format. */
static void
btrace_compute_ftrace_pt (struct thread_info *tp,
errcode = pt_cpu_errata (&config.errata, &config.cpu);
if (errcode < 0)
- error (_("Failed to configure the Intel(R) Processor Trace decoder: %s."),
+ error (_("Failed to configure the Intel Processor Trace decoder: %s."),
pt_errstr (pt_errcode (errcode)));
decoder = pt_insn_alloc_decoder (&config);
if (decoder == NULL)
- error (_("Failed to allocate the Intel(R) Processor Trace decoder."));
+ error (_("Failed to allocate the Intel Processor Trace decoder."));
TRY
{
image = pt_insn_get_image(decoder);
if (image == NULL)
- error (_("Failed to configure the Intel(R) Processor Trace decoder."));
+ error (_("Failed to configure the Intel Processor Trace decoder."));
errcode = pt_image_set_callback(image, btrace_pt_readmem_callback, NULL);
if (errcode < 0)
- error (_("Failed to configure the Intel(R) Processor Trace decoder: "
+ error (_("Failed to configure the Intel Processor Trace decoder: "
"%s."), pt_errstr (pt_errcode (errcode)));
ftrace_add_pt (decoder, &btinfo->begin, &btinfo->end, &level,
if (tp->btrace.target != NULL)
return;
+#if !defined (HAVE_LIBIPT)
+ if (conf->format == BTRACE_FORMAT_PT)
+ error (_("GDB does not support Intel Processor Trace."));
+#endif /* !defined (HAVE_LIBIPT) */
+
if (!target_supports_btrace (conf->format))
error (_("Target does not support branch tracing."));
- DEBUG ("enable thread %d (%s)", tp->num, target_pid_to_str (tp->ptid));
+ DEBUG ("enable thread %s (%s)", print_thread_id (tp),
+ target_pid_to_str (tp->ptid));
tp->btrace.target = target_enable_btrace (tp->ptid, conf);
if (btp->target == NULL)
return;
- DEBUG ("disable thread %d (%s)", tp->num, target_pid_to_str (tp->ptid));
+ DEBUG ("disable thread %s (%s)", print_thread_id (tp),
+ target_pid_to_str (tp->ptid));
target_disable_btrace (btp->target);
btp->target = NULL;
if (btp->target == NULL)
return;
- DEBUG ("teardown thread %d (%s)", tp->num, target_pid_to_str (tp->ptid));
+ DEBUG ("teardown thread %s (%s)", print_thread_id (tp),
+ target_pid_to_str (tp->ptid));
target_teardown_btrace (btp->target);
btp->target = NULL;
struct cleanup *cleanup;
int errcode;
- DEBUG ("fetch thread %d (%s)", tp->num, target_pid_to_str (tp->ptid));
+ DEBUG ("fetch thread %s (%s)", print_thread_id (tp),
+ target_pid_to_str (tp->ptid));
btinfo = &tp->btrace;
tinfo = btinfo->target;
struct btrace_thread_info *btinfo;
struct btrace_function *it, *trash;
- DEBUG ("clear thread %d (%s)", tp->num, target_pid_to_str (tp->ptid));
+ DEBUG ("clear thread %s (%s)", print_thread_id (tp),
+ target_pid_to_str (tp->ptid));
/* Make sure btrace frames that may hold a pointer into the branch
trace data are destroyed. */
const struct gdb_xml_element *element,
void *user_data, VEC (gdb_xml_value_s) *attributes)
{
- const char *version = xml_find_attribute (attributes, "version")->value;
+ const char *version
+ = (const char *) xml_find_attribute (attributes, "version")->value;
if (strcmp (version, "1.0") != 0)
gdb_xml_error (parser, _("Unsupported btrace version: \"%s\""), version);
struct btrace_block *block;
ULONGEST *begin, *end;
- btrace = user_data;
+ btrace = (struct btrace_data *) user_data;
switch (btrace->format)
{
gdb_xml_error (parser, _("Btrace format error."));
}
- begin = xml_find_attribute (attributes, "begin")->value;
- end = xml_find_attribute (attributes, "end")->value;
+ begin = (ULONGEST *) xml_find_attribute (attributes, "begin")->value;
+ end = (ULONGEST *) xml_find_attribute (attributes, "end")->value;
block = VEC_safe_push (btrace_block_s, btrace->variant.bts.blocks, NULL);
block->begin = *begin;
static void
parse_xml_raw (struct gdb_xml_parser *parser, const char *body_text,
- gdb_byte **pdata, unsigned long *psize)
+ gdb_byte **pdata, size_t *psize)
{
struct cleanup *cleanup;
gdb_byte *data, *bin;
- unsigned long size;
- size_t len;
+ size_t len, size;
len = strlen (body_text);
- size = len / 2;
-
- if ((size_t) size * 2 != len)
+ if (len % 2 != 0)
gdb_xml_error (parser, _("Bad raw data size."));
- bin = data = xmalloc (size);
+ size = len / 2;
+
+ bin = data = (gdb_byte *) xmalloc (size);
cleanup = make_cleanup (xfree, data);
/* We use hex encoding - see common/rsp-low.h. */
const char *vendor;
ULONGEST *family, *model, *stepping;
- vendor = xml_find_attribute (attributes, "vendor")->value;
- family = xml_find_attribute (attributes, "family")->value;
- model = xml_find_attribute (attributes, "model")->value;
- stepping = xml_find_attribute (attributes, "stepping")->value;
+ vendor = (const char *) xml_find_attribute (attributes, "vendor")->value;
+ family = (ULONGEST *) xml_find_attribute (attributes, "family")->value;
+ model = (ULONGEST *) xml_find_attribute (attributes, "model")->value;
+ stepping = (ULONGEST *) xml_find_attribute (attributes, "stepping")->value;
- btrace = user_data;
+ btrace = (struct btrace_data *) user_data;
if (strcmp (vendor, "GenuineIntel") == 0)
btrace->variant.pt.config.cpu.vendor = CV_INTEL;
{
struct btrace_data *btrace;
- btrace = user_data;
+ btrace = (struct btrace_data *) user_data;
parse_xml_raw (parser, body_text, &btrace->variant.pt.data,
&btrace->variant.pt.size);
}
{
struct btrace_data *btrace;
- btrace = user_data;
+ btrace = (struct btrace_data *) user_data;
btrace->format = BTRACE_FORMAT_PT;
btrace->variant.pt.config.cpu.vendor = CV_UNKNOWN;
btrace->variant.pt.data = NULL;
struct btrace_config *conf;
struct gdb_xml_value *size;
- conf = user_data;
+ conf = (struct btrace_config *) user_data;
conf->format = BTRACE_FORMAT_BTS;
conf->bts.size = 0;
struct btrace_config *conf;
struct gdb_xml_value *size;
- conf = user_data;
+ conf = (struct btrace_config *) user_data;
conf->format = BTRACE_FORMAT_PT;
conf->pt.size = 0;
const struct btrace_insn_iterator *end)
{
if (btinfo->insn_history == NULL)
- btinfo->insn_history = xzalloc (sizeof (*btinfo->insn_history));
+ btinfo->insn_history = XCNEW (struct btrace_insn_history);
btinfo->insn_history->begin = *begin;
btinfo->insn_history->end = *end;
gdb_assert (begin->btinfo == end->btinfo);
if (btinfo->call_history == NULL)
- btinfo->call_history = xzalloc (sizeof (*btinfo->call_history));
+ btinfo->call_history = XCNEW (struct btrace_call_history);
btinfo->call_history->begin = *begin;
btinfo->call_history->end = *end;
static void
do_btrace_data_cleanup (void *arg)
{
- btrace_data_fini (arg);
+ btrace_data_fini ((struct btrace_data *) arg);
}
/* See btrace.h. */
break;
case ppt_pip:
- printf_unfiltered (("pip %" PRIx64 ""), packet->payload.pip.cr3);
+ printf_unfiltered (("pip %" PRIx64 "%s"), packet->payload.pip.cr3,
+ packet->payload.pip.nr ? (" nr") : (""));
break;
case ppt_tsc:
printf_unfiltered (("ovf"));
break;
+ case ppt_stop:
+ printf_unfiltered (("stop"));
+ break;
+
+ case ppt_vmcs:
+ printf_unfiltered (("vmcs %" PRIx64 ""), packet->payload.vmcs.base);
+ break;
+
+ case ppt_tma:
+ printf_unfiltered (("tma %x %x"), packet->payload.tma.ctc,
+ packet->payload.tma.fc);
+ break;
+
+ case ppt_mtc:
+ printf_unfiltered (("mtc %x"), packet->payload.mtc.ctc);
+ break;
+
+ case ppt_cyc:
+ printf_unfiltered (("cyc %" PRIx64 ""), packet->payload.cyc.value);
+ break;
+
+ case ppt_mnt:
+ printf_unfiltered (("mnt %" PRIx64 ""), packet->payload.mnt.payload);
+ break;
}
}
}
if (errcode != -pte_eos)
- warning (_("Failed to synchronize onto the Intel(R) Processor Trace "
+ warning (_("Failed to synchronize onto the Intel Processor Trace "
"stream: %s."), pt_errstr (pt_errcode (errcode)));
}
errcode = pt_cpu_errata (&config.errata, &config.cpu);
if (errcode < 0)
- error (_("Failed to configure the Intel(R) Processor Trace decoder: %s."),
+ error (_("Failed to configure the Intel Processor Trace decoder: %s."),
pt_errstr (pt_errcode (errcode)));
decoder = pt_pkt_alloc_decoder (&config);
if (decoder == NULL)
- error (_("Failed to allocate the Intel(R) Processor Trace decoder."));
+ error (_("Failed to allocate the Intel Processor Trace decoder."));
TRY
{
0, &maintenance_set_cmdlist);
add_prefix_cmd ("pt", class_maintenance, maint_btrace_pt_set_cmd, _("\
-Set Intel(R) Processor Trace specific variables."),
+Set Intel Processor Trace specific variables."),
&maint_btrace_pt_set_cmdlist, "maintenance set btrace pt ",
0, &maint_btrace_set_cmdlist);
0, &maintenance_show_cmdlist);
add_prefix_cmd ("pt", class_maintenance, maint_btrace_pt_show_cmd, _("\
-Show Intel(R) Processor Trace specific variables."),
+Show Intel Processor Trace specific variables."),
&maint_btrace_pt_show_cmdlist, "maintenance show btrace pt ",
0, &maint_btrace_show_cmdlist);