LLDB
mainline
|
#include <DecodedThread.h>
Classes | |
struct | EventsStats |
struct | LibiptErrorsStats |
class | TscRange |
Public Member Functions | |
DecodedThread (lldb::ThreadSP thread_sp) | |
DecodedThread (lldb::ThreadSP thread_sp, llvm::Error &&err) | |
Utility constructor that initializes the trace with a provided error. More... | |
void | Append (const DecodedInstruction &insn) |
Append an instruction or a libipt error. More... | |
void | SetAsFailed (llvm::Error &&error) |
Append an error signaling that decoding completely failed. More... | |
lldb::TraceEvents | GetEvents (int insn_index) |
Get a bitmask with the events that happened chronologically right before the instruction pointed by the given instruction index, but after the previous instruction. More... | |
size_t | GetInstructionsCount () const |
Get the total number of instruction pointers from the decoded trace. More... | |
lldb::addr_t | GetInstructionLoadAddress (size_t insn_index) const |
lldb::TraceInstructionControlFlowType | GetInstructionControlFlowType (size_t insn_index) const |
Get the lldb::TraceInstructionControlFlowType categories of the instruction. More... | |
llvm::Optional< TscRange > | CalculateTscRange (size_t insn_index, const llvm::Optional< DecodedThread::TscRange > &hint_range) const |
Construct the TSC range that covers the given instruction index. More... | |
bool | IsInstructionAnError (size_t insn_idx) const |
Check if an instruction given by its index is an error. More... | |
const char * | GetErrorByInstructionIndex (size_t ins_idx) |
Get the error associated with a given instruction index. More... | |
lldb::TraceCursorUP | GetCursor () |
Get a new cursor for the decoded thread. More... | |
const LibiptErrorsStats & | GetTscErrorsStats () const |
Return an object with statistics of the TSC decoding errors that happened. More... | |
const EventsStats & | GetEventsStats () const |
Return an object with statistics of the trace events that happened. More... | |
void | RecordTscError (int libipt_error_code) |
Record an error decoding a TSC timestamp. More... | |
size_t | CalculateApproximateMemoryUsage () const |
The approximate size in bytes used by this instance, including all the already decoded instructions. More... | |
lldb::ThreadSP | GetThread () |
Private Member Functions | |
void | AppendError (llvm::Error &&error) |
Append a decoding error given an llvm::Error. More... | |
void | RecordTscForLastInstruction (uint64_t tsc) |
Notify this class that the last added instruction or error has an associated TSC. More... | |
Private Attributes | |
lldb::ThreadSP | m_thread_sp |
When adding new members to this class, make sure to update CalculateApproximateMemoryUsage() accordingly. More... | |
std::vector< lldb::addr_t > | m_instruction_ips |
The low level storage of all instruction addresses. More... | |
std::vector< uint8_t > | m_instruction_sizes |
The size in bytes of each instruction. More... | |
std::vector< pt_insn_class > | m_instruction_classes |
The libipt instruction class for each instruction. More... | |
std::map< uint64_t, uint64_t > | m_instruction_timestamps |
This map contains the TSCs of the decoded instructions. More... | |
llvm::Optional< uint64_t > | m_last_tsc = llvm::None |
This is the chronologically last TSC that has been added. More... | |
llvm::DenseMap< uint64_t, std::string > | m_errors |
llvm::DenseMap< uint64_t, lldb::TraceEvents > | m_events |
This variable stores the bitmask of events that happened right before the instruction given as a key. More... | |
EventsStats | m_events_stats |
Statistics of all tracing events. More... | |
LibiptErrorsStats | m_tsc_errors_stats |
Statistics of libipt errors when decoding TSCs. More... | |
std::chrono::milliseconds | m_total_decoding_time {0} |
Total amount of time spent decoding. More... | |
Class holding the instructions and function call hierarchy obtained from decoding a trace, as well as a position cursor used when reverse debugging the trace.
Each decoded thread contains a cursor to the current position the user is stopped at. See Trace::GetCursorPosition for more information.
Definition at line 91 of file DecodedThread.h.
lldb_private::trace_intel_pt::DecodedThread::DecodedThread | ( | lldb::ThreadSP | thread_sp | ) |
lldb_private::trace_intel_pt::DecodedThread::DecodedThread | ( | lldb::ThreadSP | thread_sp, |
llvm::Error && | err | ||
) |
Utility constructor that initializes the trace with a provided error.
void DecodedThread::Append | ( | const DecodedInstruction & | insn | ) |
Append an instruction or a libipt error.
Definition at line 112 of file DecodedThread.cpp.
References AppendError(), lldb_private::trace_intel_pt::DecodedInstruction::events, lldb_private::trace_intel_pt::IsEndOfStream(), lldb_private::trace_intel_pt::DecodedInstruction::libipt_error, m_events, m_events_stats, m_instruction_classes, m_instruction_ips, m_instruction_sizes, lldb_private::trace_intel_pt::DecodedInstruction::pt_insn, lldb_private::trace_intel_pt::DecodedThread::EventsStats::RecordEventsForInstruction(), RecordTscForLastInstruction(), and lldb_private::trace_intel_pt::DecodedInstruction::tsc.
|
private |
Append a decoding error given an llvm::Error.
Definition at line 134 of file DecodedThread.cpp.
References error(), LLDB_INVALID_ADDRESS, m_errors, m_instruction_classes, m_instruction_ips, m_instruction_sizes, and lldb_private::toString().
Referenced by Append(), GetCursor(), and SetAsFailed().
size_t DecodedThread::CalculateApproximateMemoryUsage | ( | ) | const |
The approximate size in bytes used by this instance, including all the already decoded instructions.
Definition at line 235 of file DecodedThread.cpp.
References m_errors, m_events, m_instruction_classes, m_instruction_ips, m_instruction_sizes, and m_instruction_timestamps.
Optional< DecodedThread::TscRange > DecodedThread::CalculateTscRange | ( | size_t | insn_index, |
const llvm::Optional< DecodedThread::TscRange > & | hint_range | ||
) | const |
Construct the TSC range that covers the given instruction index.
This operation is O(logn) and should be used sparingly. If the trace was collected with TSC support, all the instructions of the trace will have associated TSCs. This means that this method will only return llvm::None if there are no TSCs whatsoever in the trace.
[in] | insn_index | The instruction index in question. |
[in] | hint_range | An optional range that might include the given index or might be a neighbor of it. It might help speed it traversals of the trace with short jumps. |
Definition at line 182 of file DecodedThread.cpp.
References m_instruction_timestamps.
lldb::TraceCursorUP DecodedThread::GetCursor | ( | ) |
Get a new cursor for the decoded thread.
Definition at line 227 of file DecodedThread.cpp.
References AppendError(), m_instruction_ips, and m_thread_sp.
const char * DecodedThread::GetErrorByInstructionIndex | ( | size_t | ins_idx | ) |
Get the error associated with a given instruction index.
Definition at line 212 of file DecodedThread.cpp.
References m_errors.
lldb::TraceEvents DecodedThread::GetEvents | ( | int | insn_index | ) |
Get a bitmask with the events that happened chronologically right before the instruction pointed by the given instruction index, but after the previous instruction.
Definition at line 145 of file DecodedThread.cpp.
References m_events.
const DecodedThread::EventsStats & DecodedThread::GetEventsStats | ( | ) | const |
Return an object with statistics of the trace events that happened.
Definition at line 166 of file DecodedThread.cpp.
References m_events_stats.
TraceInstructionControlFlowType DecodedThread::GetInstructionControlFlowType | ( | size_t | insn_index | ) | const |
Get the lldb::TraceInstructionControlFlowType categories of the instruction.
Definition at line 63 of file DecodedThread.cpp.
References IsInstructionAnError(), m_instruction_classes, m_instruction_ips, and m_instruction_sizes.
lldb::addr_t DecodedThread::GetInstructionLoadAddress | ( | size_t | insn_index | ) | const |
Definition at line 58 of file DecodedThread.cpp.
References m_instruction_ips.
size_t DecodedThread::GetInstructionsCount | ( | ) | const |
Get the total number of instruction pointers from the decoded trace.
This will include instructions that indicate errors (or gaps) in the trace. For an instruction error, you can access its underlying error message with the GetErrorByInstructionIndex() method.
Definition at line 54 of file DecodedThread.cpp.
References m_instruction_ips.
Referenced by lldb_private::trace_intel_pt::DecodedThread::TscRange::TscRange().
ThreadSP DecodedThread::GetThread | ( | ) |
Definition at line 98 of file DecodedThread.cpp.
References m_thread_sp.
Referenced by CreateInstructionDecoder().
const DecodedThread::LibiptErrorsStats & DecodedThread::GetTscErrorsStats | ( | ) | const |
Return an object with statistics of the TSC decoding errors that happened.
A TSC error is not a fatal error and doesn't create gaps in the trace. Instead we only keep track of them as statistics.
Definition at line 162 of file DecodedThread.cpp.
References m_tsc_errors_stats.
bool DecodedThread::IsInstructionAnError | ( | size_t | insn_idx | ) | const |
Check if an instruction given by its index is an error.
Definition at line 208 of file DecodedThread.cpp.
References LLDB_INVALID_ADDRESS, and m_instruction_ips.
Referenced by GetInstructionControlFlowType().
void DecodedThread::RecordTscError | ( | int | libipt_error_code | ) |
Record an error decoding a TSC timestamp.
See GetTscErrors() for more documentation.
[in] | libipt_error_code | An error returned by the libipt library. |
Definition at line 157 of file DecodedThread.cpp.
References m_tsc_errors_stats, and lldb_private::trace_intel_pt::DecodedThread::LibiptErrorsStats::RecordError().
|
private |
Notify this class that the last added instruction or error has an associated TSC.
Definition at line 100 of file DecodedThread.cpp.
References m_instruction_ips, m_instruction_timestamps, and m_last_tsc.
Referenced by Append().
void DecodedThread::SetAsFailed | ( | llvm::Error && | error | ) |
Append an error signaling that decoding completely failed.
Definition at line 141 of file DecodedThread.cpp.
References AppendError(), and error().
|
private |
Definition at line 276 of file DecodedThread.h.
Referenced by AppendError(), CalculateApproximateMemoryUsage(), and GetErrorByInstructionIndex().
|
private |
This variable stores the bitmask of events that happened right before the instruction given as a key.
It maps instruction index -> events
.
Definition at line 279 of file DecodedThread.h.
Referenced by Append(), CalculateApproximateMemoryUsage(), and GetEvents().
|
private |
Statistics of all tracing events.
Definition at line 282 of file DecodedThread.h.
Referenced by Append(), and GetEventsStats().
|
private |
The libipt instruction class for each instruction.
Definition at line 263 of file DecodedThread.h.
Referenced by Append(), AppendError(), CalculateApproximateMemoryUsage(), and GetInstructionControlFlowType().
|
private |
The low level storage of all instruction addresses.
Each instruction has an index in this vector and it will be used in other parts of the code.
Definition at line 259 of file DecodedThread.h.
Referenced by Append(), AppendError(), CalculateApproximateMemoryUsage(), GetCursor(), GetInstructionControlFlowType(), GetInstructionLoadAddress(), GetInstructionsCount(), IsInstructionAnError(), and RecordTscForLastInstruction().
|
private |
The size in bytes of each instruction.
Definition at line 261 of file DecodedThread.h.
Referenced by Append(), AppendError(), CalculateApproximateMemoryUsage(), and GetInstructionControlFlowType().
|
private |
This map contains the TSCs of the decoded instructions.
It maps instruction index -> TSC
, where instruction index
is the first index at which the mapped TSC appears. We use this representation because TSCs are sporadic and we can think of them as ranges. If TSCs are present in the trace, all instructions will have an associated TSC, including the first one. Otherwise, this map will be empty.
Definition at line 271 of file DecodedThread.h.
Referenced by CalculateApproximateMemoryUsage(), CalculateTscRange(), RecordTscForLastInstruction(), and lldb_private::trace_intel_pt::DecodedThread::TscRange::TscRange().
|
private |
This is the chronologically last TSC that has been added.
Definition at line 273 of file DecodedThread.h.
Referenced by RecordTscForLastInstruction().
|
private |
When adding new members to this class, make sure to update CalculateApproximateMemoryUsage() accordingly.
Definition at line 256 of file DecodedThread.h.
Referenced by GetCursor(), and GetThread().
|
private |
Total amount of time spent decoding.
Definition at line 286 of file DecodedThread.h.
|
private |
Statistics of libipt errors when decoding TSCs.
Definition at line 284 of file DecodedThread.h.
Referenced by GetTscErrorsStats(), and RecordTscError().