@@ -1285,379 +1285,384 @@ decode_interrupt_vector (const uint8_t vector)
}
#endif /* (LIBIPT_VERSION >= 0x201) */
-/* Handle instruction decode events (libipt-v2). */
+#if defined (HAVE_PT_INSN_EVENT)
+/* Handle an instruction decode event (libipt-v2). */
static int
-handle_pt_insn_events (struct btrace_thread_info *btinfo,
- struct pt_insn_decoder *decoder,
- std::vector<unsigned int> &gaps, int status)
+handle_pt_insn_event (btrace_thread_info *btinfo, pt_insn_decoder *decoder,
+ std::vector<unsigned int> &gaps)
{
-#if defined (HAVE_PT_INSN_EVENT)
- while (status & pts_event_pending)
+ pt_event event;
+ int status = pt_insn_event (decoder, &event, sizeof (event));
+ if (status < 0)
+ return status;
+
+ switch (event.type)
{
- struct pt_event event;
- uint64_t offset;
- std::optional<CORE_ADDR> pc;
+ default:
+ break;
- status = pt_insn_event (decoder, &event, sizeof (event));
- if (status < 0)
+ case ptev_enabled:
+ if (event.status_update != 0)
break;
- switch (event.type)
+ /* Only create a new gap if there are non-aux instructions in the
+ trace since the last gap. We could be at the beginning of the
+ recording and could already have handled one or more events, like
+ ptev_iret, that created aux insns. In that case we don't want to
+ create a gap or print a warning. */
+ if (event.variant.enabled.resumed == 0
+ && ftrace_contains_non_aux_since_last_gap (btinfo))
{
- default:
- break;
-
- case ptev_enabled:
- {
- if (event.status_update != 0)
- break;
-
- /* Only create a new gap if there are non-aux instructions in
- the trace since the last gap. We could be at the beginning
- of the recording and could already have handled one or more
- events, like ptev_iret, that created aux insns. In that
- case we don't want to create a gap or print a warning. */
- if (event.variant.enabled.resumed == 0
- && ftrace_contains_non_aux_since_last_gap (btinfo))
- {
- struct btrace_function *bfun
- = ftrace_new_gap (btinfo, BDE_PT_NON_CONTIGUOUS, gaps);
+ btrace_function *bfun
+ = ftrace_new_gap (btinfo, BDE_PT_NON_CONTIGUOUS, gaps);
- pt_insn_get_offset (decoder, &offset);
+ uint64_t offset;
+ pt_insn_get_offset (decoder, &offset);
- warning
- (_("Non-contiguous trace at instruction %u (offset = 0x%"
- PRIx64 ")."), bfun->insn_offset - 1, offset);
- }
+ warning
+ (_("Non-contiguous trace at instruction %u (offset = 0x%"
+ PRIx64 ")."), bfun->insn_offset - 1, offset);
+ }
- break;
- }
+ break;
- case ptev_overflow:
- {
- struct btrace_function *bfun
- = ftrace_new_gap (btinfo, BDE_PT_OVERFLOW, gaps);
+ case ptev_overflow:
+ {
+ btrace_function *bfun
+ = ftrace_new_gap (btinfo, BDE_PT_OVERFLOW, gaps);
- pt_insn_get_offset (decoder, &offset);
+ uint64_t offset;
+ pt_insn_get_offset (decoder, &offset);
- warning (_("Overflow at instruction %u (offset = 0x%" PRIx64 ")."),
- bfun->insn_offset - 1, offset);
+ warning (_("Overflow at instruction %u (offset = 0x%" PRIx64 ")."),
+ bfun->insn_offset - 1, offset);
- break;
- }
+ break;
+ }
#if defined (HAVE_STRUCT_PT_EVENT_VARIANT_PTWRITE)
- case ptev_ptwrite:
+ case ptev_ptwrite:
+ {
+ std::optional<std::string> ptw_string;
+ std::optional<CORE_ADDR> pc;
+
+ /* Lookup the PC if available. The event often doesn't provide
+ one, so we look into the last function segment as well.
+ Looking further back makes limited sense for ptwrite. */
+ if (event.ip_suppressed == 0)
+ pc = event.variant.ptwrite.ip;
+ else if (!btinfo->functions.empty ())
{
- std::optional<std::string> ptw_string;
-
- /* Lookup the PC if available. The event often doesn't provide
- one, so we look into the last function segment as well.
- Looking further back makes limited sense for ptwrite. */
- if (event.ip_suppressed == 0)
- pc = event.variant.ptwrite.ip;
- else if (!btinfo->functions.empty ())
+ std::vector<btrace_insn> &insns = btinfo->functions.back ().insn;
+ for (auto insn = insns.rbegin (); insn != insns.rend (); ++insn)
{
- std::vector<btrace_insn> &insns
- = btinfo->functions.back ().insn;
- for (auto insn = insns.rbegin (); insn != insns.rend ();
- ++insn)
+ switch (insn->iclass)
{
- switch (insn->iclass)
- {
- case BTRACE_INSN_AUX:
- continue;
-
- case BTRACE_INSN_OTHER:
- case BTRACE_INSN_CALL:
- case BTRACE_INSN_RETURN:
- case BTRACE_INSN_JUMP:
- pc = insn->pc;
- break;
- /* No default to rely on compiler warnings. */
- }
+ case BTRACE_INSN_AUX:
+ continue;
+
+ case BTRACE_INSN_OTHER:
+ case BTRACE_INSN_CALL:
+ case BTRACE_INSN_RETURN:
+ case BTRACE_INSN_JUMP:
+ pc = insn->pc;
break;
+ /* No default to rely on compiler warnings. */
}
+ break;
}
+ }
- if (!pc.has_value ())
- warning (_("Failed to determine the PC for ptwrite."));
-
+ if (!pc.has_value ())
+ warning (_("Failed to determine the PC for ptwrite."));
- if (btinfo->ptw_callback_fun != nullptr)
- ptw_string
- = btinfo->ptw_callback_fun (event.variant.ptwrite.payload,
- pc, btinfo->ptw_context);
+ if (btinfo->ptw_callback_fun != nullptr)
+ ptw_string
+ = btinfo->ptw_callback_fun (event.variant.ptwrite.payload,
+ pc, btinfo->ptw_context);
- if (ptw_string.has_value () && (*ptw_string).empty ())
- continue;
+ if (ptw_string.has_value () && (*ptw_string).empty ())
+ break;
- if (!ptw_string.has_value ())
- ptw_string = hex_string (event.variant.ptwrite.payload);
+ if (!ptw_string.has_value ())
+ ptw_string = hex_string (event.variant.ptwrite.payload);
- handle_pt_aux_insn (btinfo, *ptw_string, pc);
+ handle_pt_aux_insn (btinfo, *ptw_string, pc);
- break;
- }
+ break;
+ }
#endif /* defined (HAVE_STRUCT_PT_EVENT_VARIANT_PTWRITE) */
#if (LIBIPT_VERSION >= 0x201)
- case ptev_interrupt:
- {
- std::string aux_string = std::string (_("interrupt: vector = "))
- + hex_string (event.variant.interrupt.vector);
-
- const char *decoded
- = decode_interrupt_vector (event.variant.interrupt.vector);
- if (decoded != nullptr)
- aux_string += std::string (" (") + decoded + ")";
+ case ptev_interrupt:
+ {
+ std::string aux_string = std::string (_("interrupt: vector = "))
+ + hex_string (event.variant.interrupt.vector);
+ std::optional<CORE_ADDR> pc;
- if (event.variant.interrupt.has_cr2 != 0)
- {
- aux_string += std::string (", cr2 = ")
- + hex_string (event.variant.interrupt.cr2);
- }
+ const char *decoded
+ = decode_interrupt_vector (event.variant.interrupt.vector);
+ if (decoded != nullptr)
+ aux_string += std::string (" (") + decoded + ")";
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.interrupt.ip;
- aux_string += std::string (", ip = ") + hex_string (*pc);
- }
-
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
+ if (event.variant.interrupt.has_cr2 != 0)
+ {
+ aux_string += std::string (", cr2 = ")
+ + hex_string (event.variant.interrupt.cr2);
}
- case ptev_iret:
+ if (event.ip_suppressed == 0)
{
- std::string aux_string = std::string (_("iret"));
+ pc = event.variant.interrupt.ip;
+ aux_string += std::string (", ip = ") + hex_string (*pc);
+ }
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.iret.ip;
- aux_string += std::string (": ip = ") + hex_string (*pc);
- }
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
- }
+ case ptev_iret:
+ {
+ std::string aux_string = std::string (_("iret"));
+ std::optional<CORE_ADDR> pc;
- case ptev_smi:
+ if (event.ip_suppressed == 0)
{
- std::string aux_string = std::string (_("smi"));
+ pc = event.variant.iret.ip;
+ aux_string += std::string (": ip = ") + hex_string (*pc);
+ }
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.smi.ip;
- aux_string += std::string (": ip = ") + hex_string (*pc);
- }
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
- }
+ case ptev_smi:
+ {
+ std::string aux_string = std::string (_("smi"));
+ std::optional<CORE_ADDR> pc;
- case ptev_rsm:
+ if (event.ip_suppressed == 0)
{
- std::string aux_string = std::string (_("rsm"));
+ pc = event.variant.smi.ip;
+ aux_string += std::string (": ip = ") + hex_string (*pc);
+ }
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.rsm.ip;
- aux_string += std::string (": ip = ") + hex_string (*pc);
- }
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
- }
+ case ptev_rsm:
+ {
+ std::string aux_string = std::string (_("rsm"));
+ std::optional<CORE_ADDR> pc;
- case ptev_sipi:
+ if (event.ip_suppressed == 0)
{
- std::string aux_string = std::string (_("sipi: vector = "))
- + hex_string (event.variant.sipi.vector);
-
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
+ pc = event.variant.rsm.ip;
+ aux_string += std::string (": ip = ") + hex_string (*pc);
}
- case ptev_init:
- {
- std::string aux_string = std::string (_("init"));
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.init.ip;
- aux_string += std::string (": ip = ") + hex_string (*pc);
- }
+ case ptev_sipi:
+ {
+ std::string aux_string = std::string (_("sipi: vector = "))
+ + hex_string (event.variant.sipi.vector);
+ std::optional<CORE_ADDR> pc;
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
- }
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
- case ptev_vmentry:
+ case ptev_init:
+ {
+ std::string aux_string = std::string (_("init"));
+ std::optional<CORE_ADDR> pc;
+
+ if (event.ip_suppressed == 0)
{
- std::string aux_string = std::string (_("vmentry"));
+ pc = event.variant.init.ip;
+ aux_string += std::string (": ip = ") + hex_string (*pc);
+ }
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.vmentry.ip;
- aux_string += std::string (": ip = ") + hex_string (*pc);
- }
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
- }
+ case ptev_vmentry:
+ {
+ std::string aux_string = std::string (_("vmentry"));
+ std::optional<CORE_ADDR> pc;
- case ptev_vmexit:
+ if (event.ip_suppressed == 0)
{
- std::string aux_string = std::string (_("vmexit"));
+ pc = event.variant.vmentry.ip;
+ aux_string += std::string (": ip = ") + hex_string (*pc);
+ }
- if (event.variant.vmexit.has_vector != 0
- || event.variant.vmexit.has_vmxr != 0
- || event.variant.vmexit.has_vmxq != 0
- || event.ip_suppressed != 0)
- aux_string += std::string (":");
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
- if (event.variant.vmexit.has_vector != 0)
- {
- aux_string += std::string (_(" vector = "))
- + hex_string (event.variant.vmexit.vector);
+ case ptev_vmexit:
+ {
+ std::string aux_string = std::string (_("vmexit"));
+ std::optional<CORE_ADDR> pc;
- const char* decoded = decode_interrupt_vector
- (event.variant.vmexit.vector);
- if (decoded != nullptr)
- aux_string += std::string (" (") + decoded + ")";
- }
+ if (event.variant.vmexit.has_vector != 0
+ || event.variant.vmexit.has_vmxr != 0
+ || event.variant.vmexit.has_vmxq != 0
+ || event.ip_suppressed != 0)
+ aux_string += std::string (":");
- if (event.variant.vmexit.has_vmxr != 0)
- {
- std::string separator = aux_string.back () == ':' ? "" : ",";
- aux_string += separator + std::string (" vmxr = ")
- + hex_string (event.variant.vmexit.vmxr);
- }
+ if (event.variant.vmexit.has_vector != 0)
+ {
+ aux_string += std::string (_(" vector = "))
+ + hex_string (event.variant.vmexit.vector);
- if (event.variant.vmexit.has_vmxq != 0)
- {
- std::string separator = aux_string.back () == ':' ? "" : ",";
- aux_string += separator + std::string (" vmxq = ")
- + hex_string (event.variant.vmexit.vmxq);
- }
+ const char* decoded = decode_interrupt_vector
+ (event.variant.vmexit.vector);
+ if (decoded != nullptr)
+ aux_string += std::string (" (") + decoded + ")";
+ }
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.vmexit.ip;
- std::string separator = aux_string.back () == ':' ? "" : ",";
- aux_string += separator + std::string (" ip = ")
- + hex_string (*pc);
- }
+ if (event.variant.vmexit.has_vmxr != 0)
+ {
+ std::string separator = aux_string.back () == ':' ? "" : ",";
+ aux_string += separator + std::string (" vmxr = ")
+ + hex_string (event.variant.vmexit.vmxr);
+ }
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
+ if (event.variant.vmexit.has_vmxq != 0)
+ {
+ std::string separator = aux_string.back () == ':' ? "" : ",";
+ aux_string += separator + std::string (" vmxq = ")
+ + hex_string (event.variant.vmexit.vmxq);
}
- case ptev_shutdown:
+ if (event.ip_suppressed == 0)
{
- std::string aux_string = std::string (_("shutdown"));
+ pc = event.variant.vmexit.ip;
+ std::string separator = aux_string.back () == ':' ? "" : ",";
+ aux_string += separator + std::string (" ip = ")
+ + hex_string (*pc);
+ }
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.shutdown.ip;
- aux_string += std::string (": ip = ") + hex_string (*pc);
- }
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
- }
+ case ptev_shutdown:
+ {
+ std::string aux_string = std::string (_("shutdown"));
+ std::optional<CORE_ADDR> pc;
- case ptev_uintr:
+ if (event.ip_suppressed == 0)
{
- std::string aux_string = std::string (_("uintr: vector = "))
- + hex_string (event.variant.uintr.vector);
+ pc = event.variant.shutdown.ip;
+ aux_string += std::string (": ip = ") + hex_string (*pc);
+ }
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.uintr.ip;
- aux_string += std::string (", ip = ") + hex_string (*pc);
- }
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
- }
+ case ptev_uintr:
+ {
+ std::string aux_string = std::string (_("uintr: vector = "))
+ + hex_string (event.variant.uintr.vector);
+ std::optional<CORE_ADDR> pc;
- case ptev_uiret:
+ if (event.ip_suppressed == 0)
{
- std::string aux_string = std::string (_("uiret"));
+ pc = event.variant.uintr.ip;
+ aux_string += std::string (", ip = ") + hex_string (*pc);
+ }
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.uiret.ip;
- aux_string += std::string (": ip = ") + hex_string (*pc);
- }
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
- }
-#endif /* (LIBIPT_VERSION >= 0x201) */
+ case ptev_uiret:
+ {
+ std::string aux_string = std::string (_("uiret"));
+ std::optional<CORE_ADDR> pc;
-#if (LIBIPT_VERSION >= 0x202)
- case ptev_trig:
+ if (event.ip_suppressed == 0)
{
- std::string aux_string
- = (std::string (_("trig: trbv = "))
- + hex_string (event.variant.trig.trbv));
+ pc = event.variant.uiret.ip;
+ aux_string += std::string (": ip = ") + hex_string (*pc);
+ }
- if (event.variant.trig.mult != 0)
- aux_string += std::string (", mult");
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
+#endif /* (LIBIPT_VERSION >= 0x201) */
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.trig.ip;
- aux_string += (std::string (", ip = ") + hex_string (*pc));
- }
+#if (LIBIPT_VERSION >= 0x202)
+ case ptev_trig:
+ {
+ std::string aux_string
+ = (std::string (_("trig: trbv = "))
+ + hex_string (event.variant.trig.trbv));
+ std::optional<CORE_ADDR> pc;
- if (event.variant.trig.icnt != 0)
- aux_string += (std::string (", icnt = ")
- + hex_string (event.variant.trig.icnt));
+ if (event.variant.trig.mult != 0)
+ aux_string += std::string (", mult");
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
+ if (event.ip_suppressed == 0)
+ {
+ pc = event.variant.trig.ip;
+ aux_string += (std::string (", ip = ") + hex_string (*pc));
}
- case ptev_swintr:
- {
- std::string aux_string
- = (std::string (_("swintr: vector = "))
- + hex_string (event.variant.swintr.vector));
+ if (event.variant.trig.icnt != 0)
+ aux_string += (std::string (", icnt = ")
+ + hex_string (event.variant.trig.icnt));
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.swintr.ip;
- aux_string += (std::string (", ip = ") + hex_string (*pc));
- }
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
- }
+ case ptev_swintr:
+ {
+ std::string aux_string
+ = (std::string (_("swintr: vector = "))
+ + hex_string (event.variant.swintr.vector));
+ std::optional<CORE_ADDR> pc;
- case ptev_syscall:
+ if (event.ip_suppressed == 0)
{
- std::string aux_string = std::string (_("syscall"));
+ pc = event.variant.swintr.ip;
+ aux_string += (std::string (", ip = ") + hex_string (*pc));
+ }
- if (event.ip_suppressed == 0)
- {
- pc = event.variant.syscall.ip;
- aux_string += (std::string (": ip = ") + hex_string (*pc));
- }
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
- handle_pt_aux_insn (btinfo, aux_string, pc);
- break;
+ case ptev_syscall:
+ {
+ std::string aux_string = std::string (_("syscall"));
+ std::optional<CORE_ADDR> pc;
+
+ if (event.ip_suppressed == 0)
+ {
+ pc = event.variant.syscall.ip;
+ aux_string += (std::string (": ip = ") + hex_string (*pc));
}
+
+ handle_pt_aux_insn (btinfo, aux_string, pc);
+ break;
+ }
#endif /* (LIBIPT_VERSION >= 0x202) */
- }
}
-#endif /* defined (HAVE_PT_INSN_EVENT) */
return status;
}
+#endif /* defined (HAVE_PT_INSN_EVENT) */
/* Handle events indicated by flags in INSN (libipt-v1). */
@@ -1735,8 +1740,11 @@ ftrace_add_pt (struct btrace_thread_info *btinfo,
for (;;)
{
+#if defined (HAVE_PT_INSN_EVENT)
/* Handle events from the previous iteration or synchronization. */
- status = handle_pt_insn_events (btinfo, decoder, gaps, status);
+ while ((status != 0) && (status & pts_event_pending))
+ status = handle_pt_insn_event (btinfo, decoder, gaps);
+#endif
if (status < 0)
break;