@@ -1710,26 +1710,83 @@ handle_pt_insn_event_flags (struct btrace_thread_info *btinfo,
#endif /* defined (HAVE_STRUCT_PT_INSN_RESYNCED) */
}
+/* Generate a decode error warning. */
+
+static void
+ftrace_warn_pt (btrace_thread_info *btinfo, pt_insn_decoder *decoder,
+ btrace_function *bfun, int status)
+{
+ gdb_assert (bfun != nullptr);
+
+ unsigned int ioffset = bfun->insn_offset - 1;
+ uint64_t offset;
+ pt_insn_get_offset (decoder, &offset);
+
+ btrace_insn_iterator it;
+ int found = btrace_find_insn_by_number (&it, btinfo, ioffset);
+ const btrace_insn *binsn = (found != 0) ? btrace_insn_get (&it) : nullptr;
+
+ warning (_("Decode error (%d) at instruction %u (offset = 0x%" PRIx64
+ ", pc = %s): %s."), status, ioffset, offset,
+ (binsn != nullptr) ? hex_string (binsn->pc) : "?",
+ pt_errstr (pt_errcode (status)));
+}
+
+/* Decode the trace and handle events as long as there is no error.
+ Returns the last decoder status. */
+
+static int
+ftrace_decode_pt (btrace_thread_info *btinfo,
+ pt_insn_decoder *decoder,
+ int *plevel,
+ std::vector<unsigned int> &gaps,
+ int status)
+{
+ gdb_assert (status >= 0);
+ for (;;)
+ {
+#if defined (HAVE_PT_INSN_EVENT)
+ /* Handle events from the previous iteration or synchronization. */
+ while (status & pts_event_pending)
+ {
+ status = handle_pt_insn_event (btinfo, decoder, gaps);
+ if (status < 0)
+ return status;
+ }
+#endif
+ pt_insn insn;
+ status = pt_insn_next (decoder, &insn, sizeof (insn));
+ if (status < 0)
+ return status;
+
+ /* Handle events indicated by flags in INSN. */
+ handle_pt_insn_event_flags (btinfo, decoder, insn, gaps);
+
+ btrace_function *bfun
+ = ftrace_update_function (btinfo,
+ std::make_optional<CORE_ADDR> (insn.ip));
+
+ /* Maintain the function level offset. */
+ *plevel = std::min (*plevel, bfun->level);
+
+ ftrace_update_insns (bfun, pt_btrace_insn (insn));
+ }
+}
+
/* Add function branch trace to BTINFO using DECODER. */
static void
-ftrace_add_pt (struct btrace_thread_info *btinfo,
- struct pt_insn_decoder *decoder,
+ftrace_add_pt (btrace_thread_info *btinfo,
+ pt_insn_decoder *decoder,
int *plevel,
std::vector<unsigned int> &gaps)
{
- struct btrace_function *bfun;
- uint64_t offset;
- int status;
-
/* Register the ptwrite filter. */
apply_ext_lang_ptwrite_filter (btinfo);
for (;;)
{
- struct pt_insn insn;
-
- status = pt_insn_sync_forward (decoder);
+ int status = pt_insn_sync_forward (decoder);
if (status < 0)
{
if (status != -pte_eos)
@@ -1738,44 +1795,13 @@ ftrace_add_pt (struct btrace_thread_info *btinfo,
break;
}
- for (;;)
- {
-#if defined (HAVE_PT_INSN_EVENT)
- /* Handle events from the previous iteration or synchronization. */
- while ((status != 0) && (status & pts_event_pending))
- status = handle_pt_insn_event (btinfo, decoder, gaps);
-#endif
- if (status < 0)
- break;
-
- status = pt_insn_next (decoder, &insn, sizeof(insn));
- if (status < 0)
- break;
-
- /* Handle events indicated by flags in INSN. */
- handle_pt_insn_event_flags (btinfo, decoder, insn, gaps);
-
- bfun
- = ftrace_update_function (btinfo,
- std::make_optional<CORE_ADDR> (insn.ip));
-
- /* Maintain the function level offset. */
- *plevel = std::min (*plevel, bfun->level);
-
- ftrace_update_insns (bfun, pt_btrace_insn (insn));
- }
-
+ status = ftrace_decode_pt (btinfo, decoder, plevel, gaps, status);
if (status == -pte_eos)
break;
/* Indicate the gap in the trace. */
- bfun = ftrace_new_gap (btinfo, status, gaps);
-
- pt_insn_get_offset (decoder, &offset);
-
- warning (_("Decode error (%d) at instruction %u (offset = 0x%" PRIx64
- ", pc = 0x%" PRIx64 "): %s."), status, bfun->insn_offset - 1,
- offset, insn.ip, pt_errstr (pt_errcode (status)));
+ btrace_function *bfun = ftrace_new_gap (btinfo, status, gaps);
+ ftrace_warn_pt (btinfo, decoder, bfun, status);
}
}