From a7d6c3effe93954ecad634eebbcc59fc6856c3d9 Mon Sep 17 00:00:00 2001 From: Walter Erquinigo Date: Fri, 24 Jun 2022 14:02:47 -0700 Subject: [trace] Make events first class items in the trace cursor and rework errors We want to include events with metadata, like context switches, and this requires the API to handle events with payloads (e.g. information about such context switches). Besides this, we want to support multiple similar events between two consecutive instructions, like multiple context switches. However, the current implementation is not good for this because we are defining events as bitmask enums associated with specific instructions. Thus, we need to decouple instructions from events and make events actual items in the trace, just like instructions and errors. - Add accessors in the TraceCursor to know if an item is an event or not - Modify from the TraceDumper all the way to DecodedThread to support - Renamed the paused event to disabled. - Improved the tsc handling logic. I was using an API for getting the tsc from libipt, but that was an overkill that should be used when not processing events manually, but as we are already processing events, we can more easily get the tscs. event items. Fortunately this simplified many things - As part of this refactor, I also fixed and long stating issue, which is that some non decoding errors were being inserted in the decoded thread. I changed this so that TraceIntelPT::Decode returns an error if the decoder couldn't be set up proplerly. Then, errors within a trace are actual anomalies found in between instrutions. All test pass Differential Revision: https://reviews.llvm.org/D128576 --- lldb/source/Commands/CommandObjectThread.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lldb/source/Commands/CommandObjectThread.cpp') diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp index 7dd89e601af8..993523e06736 100644 --- a/lldb/source/Commands/CommandObjectThread.cpp +++ b/lldb/source/Commands/CommandObjectThread.cpp @@ -33,7 +33,7 @@ #include "lldb/Target/ThreadPlan.h" #include "lldb/Target/ThreadPlanStepInRange.h" #include "lldb/Target/Trace.h" -#include "lldb/Target/TraceInstructionDumper.h" +#include "lldb/Target/TraceDumper.h" #include "lldb/Utility/State.h" using namespace lldb; @@ -2208,7 +2208,7 @@ public: size_t m_count; size_t m_continue; llvm::Optional m_output_file; - TraceInstructionDumperOptions m_dumper_options; + TraceDumperOptions m_dumper_options; }; CommandObjectTraceDumpInstructions(CommandInterpreter &interpreter) @@ -2272,8 +2272,14 @@ protected: m_options.m_dumper_options.id = m_last_id; } - TraceCursorUP cursor_up = - m_exe_ctx.GetTargetSP()->GetTrace()->GetCursor(*thread_sp); + llvm::Expected cursor_or_error = + m_exe_ctx.GetTargetSP()->GetTrace()->CreateNewCursor(*thread_sp); + + if (!cursor_or_error) { + result.AppendError(llvm::toString(cursor_or_error.takeError())); + return false; + } + TraceCursorUP &cursor_up = *cursor_or_error; if (m_options.m_dumper_options.id && !cursor_up->HasId(*m_options.m_dumper_options.id)) { @@ -2295,9 +2301,9 @@ protected: cursor_up->Seek(1, TraceCursor::SeekType::End); } - TraceInstructionDumper dumper( - std::move(cursor_up), out_file ? *out_file : result.GetOutputStream(), - m_options.m_dumper_options); + TraceDumper dumper(std::move(cursor_up), + out_file ? *out_file : result.GetOutputStream(), + m_options.m_dumper_options); m_last_id = dumper.DumpInstructions(m_options.m_count); return true; -- cgit v1.2.3