LLDB mainline
|
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. More...
#include <DecodedThread.h>
Classes | |
struct | ErrorStats |
struct | EventsStats |
struct | NanosecondsRange |
A structure that represents a maximal range of trace items associated to the same non-interpolated timestamps in nanoseconds. More... | |
union | TraceItemStorage |
We use a union to optimize the memory usage for the different kinds of trace items. More... | |
struct | TSCRange |
A structure that represents a maximal range of trace items associated to the same TSC value. More... | |
Public Types | |
using | TSC = uint64_t |
Public Member Functions | |
DecodedThread (lldb::ThreadSP thread_sp, const std::optional< LinuxPerfZeroTscConversion > &tsc_conversion) | |
uint64_t | GetItemsCount () const |
Get the total number of instruction, errors and events from the decoded trace. | |
const char * | GetErrorByIndex (uint64_t item_index) const |
lldb::TraceItemKind | GetItemKindByIndex (uint64_t item_index) const |
lldb::TraceEvent | GetEventByIndex (int item_index) const |
lldb::cpu_id_t | GetCPUByIndex (uint64_t item_index) const |
Get the most recent CPU id before or at the given trace item index. | |
lldb::addr_t | GetSyncPointOffsetByIndex (uint64_t item_index) const |
std::optional< DecodedThread::TSCRange > | GetTSCRangeByIndex (uint64_t item_index) const |
Get a maximal range of trace items that include the given item_index that have the same TSC value. | |
std::optional< DecodedThread::NanosecondsRange > | GetNanosecondsRangeByIndex (uint64_t item_index) |
Get a maximal range of trace items that include the given item_index that have the same nanoseconds timestamp without interpolation. | |
lldb::addr_t | GetInstructionLoadAddress (uint64_t item_index) const |
uint64_t | GetTotalInstructionCount () const |
const EventsStats & | GetEventsStats () const |
Return an object with statistics of the trace events that happened. | |
const ErrorStats & | GetErrorStats () const |
Return an object with statistics of the trace errors that happened. | |
size_t | CalculateApproximateMemoryUsage () const |
The approximate size in bytes used by this instance, including all the already decoded instructions. | |
lldb::ThreadSP | GetThread () |
void | NotifyTsc (TSC tsc) |
Notify this object that a new tsc has been seen. | |
void | NotifyCPU (lldb::cpu_id_t cpu_id) |
Notify this object that a CPU has been seen. | |
void | NotifySyncPoint (lldb::addr_t psb_offset) |
Notify this object that a new PSB has been seen. | |
void | AppendError (const IntelPTError &error) |
Append a decoding error. | |
void | AppendCustomError (llvm::StringRef error, bool fatal=false) |
Append a custom decoding. | |
void | AppendEvent (lldb::TraceEvent) |
Append an event. | |
void | AppendInstruction (const pt_insn &insn) |
Append an instruction. | |
Private Member Functions | |
DecodedThread::TraceItemStorage & | CreateNewTraceItem (lldb::TraceItemKind kind) |
Create a new trace item. | |
Private Attributes | |
lldb::ThreadSP | m_thread_sp |
When adding new members to this class, make sure to update CalculateApproximateMemoryUsage() accordingly. | |
std::vector< TraceItemStorage > | m_item_data |
Most of the trace data is stored here. | |
std::vector< uint8_t > | m_item_kinds |
The TraceItemKind for each trace item encoded as uint8_t. | |
std::map< uint64_t, TSCRange > | m_tscs |
This map contains the TSCs of the decoded trace items. | |
std::optional< std::map< uint64_t, TSCRange >::iterator > | m_last_tsc |
This is the chronologically last TSC that has been added. | |
std::map< uint64_t, NanosecondsRange > | m_nanoseconds |
This map contains the non-interpolated nanoseconds timestamps of the decoded trace items. | |
std::optional< std::map< uint64_t, NanosecondsRange >::iterator > | m_last_nanoseconds = std::nullopt |
std::map< uint64_t, lldb::cpu_id_t > | m_cpus |
std::optional< uint64_t > | m_last_cpu |
This is the chronologically last CPU ID. | |
llvm::DenseMap< uint64_t, lldb::addr_t > | m_psb_offsets |
std::optional< LinuxPerfZeroTscConversion > | m_tsc_conversion |
TSC -> nanos conversion utility. | |
ErrorStats | m_error_stats |
Statistics of all tracing errors. | |
EventsStats | m_events_stats |
Statistics of all tracing events. | |
std::chrono::milliseconds | m_total_decoding_time {0} |
Total amount of time spent decoding. | |
uint64_t | m_insn_count = 0 |
Total number of instructions in the trace. | |
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 61 of file DecodedThread.h.
using lldb_private::trace_intel_pt::DecodedThread::TSC = uint64_t |
Definition at line 63 of file DecodedThread.h.
DecodedThread::DecodedThread | ( | lldb::ThreadSP | thread_sp, |
const std::optional< LinuxPerfZeroTscConversion > & | tsc_conversion | ||
) |
Definition at line 245 of file DecodedThread.cpp.
void DecodedThread::AppendCustomError | ( | llvm::StringRef | error, |
bool | fatal = false |
||
) |
Append a custom decoding.
[in] | error | The error message. |
[in] | fatal | If true, then the whole decoded thread should be discarded because a fatal anomaly has been found. |
Definition at line 194 of file DecodedThread.cpp.
References lldb_private::ConstString::AsCString(), CreateNewTraceItem(), lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage::error, lldb::eTraceItemKindError, m_error_stats, and lldb_private::trace_intel_pt::DecodedThread::ErrorStats::RecordError().
Referenced by PSBBlockDecoder::AppendInstructionAndDetectAnomalies(), and PSBBlockDecoder::ProcessPTEventTSC().
void DecodedThread::AppendError | ( | const IntelPTError & | error | ) |
Append a decoding error.
Definition at line 188 of file DecodedThread.cpp.
References lldb_private::ConstString::AsCString(), CreateNewTraceItem(), error(), lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage::error, lldb::eTraceItemKindError, m_error_stats, and lldb_private::trace_intel_pt::DecodedThread::ErrorStats::RecordError().
Referenced by PSBBlockDecoder::DecodeInstructionsAndEvents(), and PSBBlockDecoder::ProcessPTEvents().
void DecodedThread::AppendEvent | ( | lldb::TraceEvent | event | ) |
Append an event.
Definition at line 178 of file DecodedThread.cpp.
References CreateNewTraceItem(), lldb::eTraceItemKindEvent, lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage::event, m_events_stats, and lldb_private::trace_intel_pt::DecodedThread::EventsStats::RecordEvent().
Referenced by NotifyCPU(), NotifySyncPoint(), NotifyTsc(), and PSBBlockDecoder::ProcessPTEvents().
void DecodedThread::AppendInstruction | ( | const pt_insn & | insn | ) |
Append an instruction.
Definition at line 183 of file DecodedThread.cpp.
References CreateNewTraceItem(), lldb::eTraceItemKindInstruction, lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage::load_address, and m_insn_count.
Referenced by PSBBlockDecoder::AppendInstructionAndDetectAnomalies().
size_t DecodedThread::CalculateApproximateMemoryUsage | ( | ) | const |
The approximate size in bytes used by this instance, including all the already decoded instructions.
Definition at line 250 of file DecodedThread.cpp.
References m_cpus, m_item_data, m_item_kinds, m_nanoseconds, and m_tscs.
|
private |
Create a new trace item.
Definition at line 103 of file DecodedThread.cpp.
References m_item_data, m_item_kinds, m_last_nanoseconds, and m_last_tsc.
Referenced by AppendCustomError(), AppendError(), AppendEvent(), and AppendInstruction().
lldb::cpu_id_t DecodedThread::GetCPUByIndex | ( | uint64_t | item_index | ) | const |
Get the most recent CPU id before or at the given trace item index.
[in] | item_index | The trace item index to compare with. |
Definition at line 153 of file DecodedThread.cpp.
References LLDB_INVALID_CPU_ID, and m_cpus.
const char * DecodedThread::GetErrorByIndex | ( | uint64_t | item_index | ) | const |
Definition at line 241 of file DecodedThread.cpp.
References m_item_data.
const DecodedThread::ErrorStats & DecodedThread::GetErrorStats | ( | ) | const |
Return an object with statistics of the trace errors that happened.
Definition at line 232 of file DecodedThread.cpp.
References m_error_stats.
lldb::TraceEvent DecodedThread::GetEventByIndex | ( | int | item_index | ) | const |
Definition at line 200 of file DecodedThread.cpp.
References m_item_data.
const DecodedThread::EventsStats & DecodedThread::GetEventsStats | ( | ) | const |
Return an object with statistics of the trace events that happened.
Definition at line 204 of file DecodedThread.cpp.
References m_events_stats.
lldb::addr_t DecodedThread::GetInstructionLoadAddress | ( | uint64_t | item_index | ) | const |
Definition at line 91 of file DecodedThread.cpp.
References m_item_data.
Referenced by PSBBlockAnomalyDetector::TryIdentifyInfiniteLoop().
lldb::TraceItemKind DecodedThread::GetItemKindByIndex | ( | uint64_t | item_index | ) | const |
Definition at line 237 of file DecodedThread.cpp.
References m_item_kinds.
Referenced by PSBBlockAnomalyDetector::TryIdentifyInfiniteLoop().
uint64_t DecodedThread::GetItemsCount | ( | ) | const |
Get the total number of instruction, errors and events from the decoded trace.
Definition at line 88 of file DecodedThread.cpp.
References m_item_kinds.
Referenced by NotifyCPU(), NotifySyncPoint(), NotifyTsc(), and PSBBlockAnomalyDetector::TryIdentifyInfiniteLoop().
std::optional< DecodedThread::NanosecondsRange > DecodedThread::GetNanosecondsRangeByIndex | ( | uint64_t | item_index | ) |
Get a maximal range of trace items that include the given item_index
that have the same nanoseconds timestamp without interpolation.
[in] | item_index | The trace item index to compare with. |
Definition at line 167 of file DecodedThread.cpp.
References m_nanoseconds.
lldb::addr_t DecodedThread::GetSyncPointOffsetByIndex | ( | uint64_t | item_index | ) | const |
Definition at line 96 of file DecodedThread.cpp.
References m_psb_offsets.
ThreadSP DecodedThread::GetThread | ( | ) |
Definition at line 100 of file DecodedThread.cpp.
References m_thread_sp.
uint64_t DecodedThread::GetTotalInstructionCount | ( | ) | const |
Definition at line 174 of file DecodedThread.cpp.
References m_insn_count.
Referenced by PSBBlockAnomalyDetector::DetectAnomaly(), and PSBBlockAnomalyDetector::RefreshPacketOffset().
std::optional< DecodedThread::TSCRange > DecodedThread::GetTSCRangeByIndex | ( | uint64_t | item_index | ) | const |
Get a maximal range of trace items that include the given item_index
that have the same TSC value.
[in] | item_index | The trace item index to compare with. |
Definition at line 159 of file DecodedThread.cpp.
References m_tscs.
void DecodedThread::NotifyCPU | ( | lldb::cpu_id_t | cpu_id | ) |
Notify this object that a CPU has been seen.
If this a new CPU, an event will be created.
Definition at line 145 of file DecodedThread.cpp.
References AppendEvent(), lldb::eTraceEventCPUChanged, GetItemsCount(), m_cpus, and m_last_cpu.
void DecodedThread::NotifySyncPoint | ( | lldb::addr_t | psb_offset | ) |
Notify this object that a new PSB has been seen.
Definition at line 113 of file DecodedThread.cpp.
References AppendEvent(), lldb::eTraceEventSyncPoint, GetItemsCount(), and m_psb_offsets.
Referenced by PSBBlockDecoder::DecodePSBBlock().
void DecodedThread::NotifyTsc | ( | TSC | tsc | ) |
Notify this object that a new tsc has been seen.
If this a new TSC, an event will be created.
Definition at line 118 of file DecodedThread.cpp.
References AppendEvent(), lldb::eTraceEventHWClockTick, GetItemsCount(), m_last_nanoseconds, m_last_tsc, m_nanoseconds, m_tsc_conversion, and m_tscs.
Referenced by PSBBlockDecoder::DecodePSBBlock(), and PSBBlockDecoder::ProcessPTEventTSC().
|
private |
Definition at line 313 of file DecodedThread.h.
Referenced by CalculateApproximateMemoryUsage(), GetCPUByIndex(), and NotifyCPU().
|
private |
Statistics of all tracing errors.
Definition at line 324 of file DecodedThread.h.
Referenced by AppendCustomError(), AppendError(), and GetErrorStats().
|
private |
Statistics of all tracing events.
Definition at line 327 of file DecodedThread.h.
Referenced by AppendEvent(), and GetEventsStats().
|
private |
Total number of instructions in the trace.
Definition at line 332 of file DecodedThread.h.
Referenced by AppendInstruction(), and GetTotalInstructionCount().
|
private |
Most of the trace data is stored here.
Definition at line 288 of file DecodedThread.h.
Referenced by CalculateApproximateMemoryUsage(), CreateNewTraceItem(), GetErrorByIndex(), GetEventByIndex(), and GetInstructionLoadAddress().
|
private |
The TraceItemKind for each trace item encoded as uint8_t.
We don't include it in TraceItemStorage to avoid padding.
Definition at line 291 of file DecodedThread.h.
Referenced by CalculateApproximateMemoryUsage(), CreateNewTraceItem(), GetItemKindByIndex(), and GetItemsCount().
|
private |
This is the chronologically last CPU ID.
Definition at line 315 of file DecodedThread.h.
Referenced by NotifyCPU().
|
private |
Definition at line 308 of file DecodedThread.h.
Referenced by CreateNewTraceItem(), and NotifyTsc().
|
private |
This is the chronologically last TSC that has been added.
Definition at line 299 of file DecodedThread.h.
Referenced by CreateNewTraceItem(), and NotifyTsc().
|
private |
This map contains the non-interpolated nanoseconds timestamps of the decoded trace items.
It maps item index -> nanoseconds
, where item index
is the first index at which the mapped nanoseconds first appears. We use this representation because timestamps are sporadic and we think of them as ranges.
Definition at line 306 of file DecodedThread.h.
Referenced by CalculateApproximateMemoryUsage(), GetNanosecondsRangeByIndex(), and NotifyTsc().
|
private |
Definition at line 318 of file DecodedThread.h.
Referenced by GetSyncPointOffsetByIndex(), and NotifySyncPoint().
|
private |
When adding new members to this class, make sure to update CalculateApproximateMemoryUsage() accordingly.
Definition at line 266 of file DecodedThread.h.
Referenced by GetThread().
|
private |
Total amount of time spent decoding.
Definition at line 329 of file DecodedThread.h.
|
private |
TSC -> nanos conversion utility.
Definition at line 321 of file DecodedThread.h.
Referenced by NotifyTsc().
|
private |
This map contains the TSCs of the decoded trace items.
It maps item index -> TSC
, where item index
is the first index at which the mapped TSC first appears. We use this representation because TSCs are sporadic and we can think of them as ranges.
Definition at line 297 of file DecodedThread.h.
Referenced by CalculateApproximateMemoryUsage(), GetTSCRangeByIndex(), and NotifyTsc().