LLDB  mainline
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
lldb_private::trace_intel_pt::DecodedThread Class Reference

#include <DecodedThread.h>

Inheritance diagram for lldb_private::trace_intel_pt::DecodedThread:
Inheritance graph
[legend]
Collaboration diagram for lldb_private::trace_intel_pt::DecodedThread:
Collaboration graph
[legend]

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< TscRangeCalculateTscRange (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 LibiptErrorsStatsGetTscErrorsStats () const
 Return an object with statistics of the TSC decoding errors that happened. More...
 
const EventsStatsGetEventsStats () 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_tm_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::stringm_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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ DecodedThread() [1/2]

lldb_private::trace_intel_pt::DecodedThread::DecodedThread ( lldb::ThreadSP  thread_sp)

◆ DecodedThread() [2/2]

lldb_private::trace_intel_pt::DecodedThread::DecodedThread ( lldb::ThreadSP  thread_sp,
llvm::Error &&  err 
)

Utility constructor that initializes the trace with a provided error.

Member Function Documentation

◆ Append()

void DecodedThread::Append ( const DecodedInstruction insn)

◆ AppendError()

void DecodedThread::AppendError ( llvm::Error &&  error)
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().

◆ CalculateApproximateMemoryUsage()

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.

◆ CalculateTscRange()

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.

Parameters
[in]insn_indexThe instruction index in question.
[in]hint_rangeAn 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.

◆ GetCursor()

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.

◆ GetErrorByInstructionIndex()

const char * DecodedThread::GetErrorByInstructionIndex ( size_t  ins_idx)

Get the error associated with a given instruction index.

Returns
The error message of nullptr if the given index points to a valid instruction.

Definition at line 212 of file DecodedThread.cpp.

References m_errors.

◆ GetEvents()

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.

◆ GetEventsStats()

const DecodedThread::EventsStats & DecodedThread::GetEventsStats ( ) const

Return an object with statistics of the trace events that happened.

Returns
The stats object of all the events.

Definition at line 166 of file DecodedThread.cpp.

References m_events_stats.

◆ GetInstructionControlFlowType()

TraceInstructionControlFlowType DecodedThread::GetInstructionControlFlowType ( size_t  insn_index) const

Get the lldb::TraceInstructionControlFlowType categories of the instruction.

Returns
The control flow categories, or 0 if the instruction is an error.

Definition at line 63 of file DecodedThread.cpp.

References IsInstructionAnError(), m_instruction_classes, m_instruction_ips, and m_instruction_sizes.

◆ GetInstructionLoadAddress()

lldb::addr_t DecodedThread::GetInstructionLoadAddress ( size_t  insn_index) const
Returns
The load address of the instruction at the given index, or LLDB_INVALID_ADDRESS if it is an error.

Definition at line 58 of file DecodedThread.cpp.

References m_instruction_ips.

◆ GetInstructionsCount()

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().

◆ GetThread()

ThreadSP DecodedThread::GetThread ( )

Definition at line 98 of file DecodedThread.cpp.

References m_thread_sp.

Referenced by CreateInstructionDecoder().

◆ GetTscErrorsStats()

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.

Returns
An object with the statistics of TSC decoding errors.

Definition at line 162 of file DecodedThread.cpp.

References m_tsc_errors_stats.

◆ IsInstructionAnError()

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().

◆ RecordTscError()

void DecodedThread::RecordTscError ( int  libipt_error_code)

Record an error decoding a TSC timestamp.

See GetTscErrors() for more documentation.

Parameters
[in]libipt_error_codeAn 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().

◆ RecordTscForLastInstruction()

void DecodedThread::RecordTscForLastInstruction ( uint64_t  tsc)
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().

◆ SetAsFailed()

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().

Member Data Documentation

◆ m_errors

llvm::DenseMap<uint64_t, std::string> lldb_private::trace_intel_pt::DecodedThread::m_errors
private

◆ m_events

llvm::DenseMap<uint64_t, lldb::TraceEvents> lldb_private::trace_intel_pt::DecodedThread::m_events
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().

◆ m_events_stats

EventsStats lldb_private::trace_intel_pt::DecodedThread::m_events_stats
private

Statistics of all tracing events.

Definition at line 282 of file DecodedThread.h.

Referenced by Append(), and GetEventsStats().

◆ m_instruction_classes

std::vector<pt_insn_class> lldb_private::trace_intel_pt::DecodedThread::m_instruction_classes
private

The libipt instruction class for each instruction.

Definition at line 263 of file DecodedThread.h.

Referenced by Append(), AppendError(), CalculateApproximateMemoryUsage(), and GetInstructionControlFlowType().

◆ m_instruction_ips

std::vector<lldb::addr_t> lldb_private::trace_intel_pt::DecodedThread::m_instruction_ips
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().

◆ m_instruction_sizes

std::vector<uint8_t> lldb_private::trace_intel_pt::DecodedThread::m_instruction_sizes
private

The size in bytes of each instruction.

Definition at line 261 of file DecodedThread.h.

Referenced by Append(), AppendError(), CalculateApproximateMemoryUsage(), and GetInstructionControlFlowType().

◆ m_instruction_timestamps

std::map<uint64_t, uint64_t> lldb_private::trace_intel_pt::DecodedThread::m_instruction_timestamps
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().

◆ m_last_tsc

llvm::Optional<uint64_t> lldb_private::trace_intel_pt::DecodedThread::m_last_tsc = llvm::None
private

This is the chronologically last TSC that has been added.

Definition at line 273 of file DecodedThread.h.

Referenced by RecordTscForLastInstruction().

◆ m_thread_sp

lldb::ThreadSP lldb_private::trace_intel_pt::DecodedThread::m_thread_sp
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().

◆ m_total_decoding_time

std::chrono::milliseconds lldb_private::trace_intel_pt::DecodedThread::m_total_decoding_time {0}
private

Total amount of time spent decoding.

Definition at line 286 of file DecodedThread.h.

◆ m_tsc_errors_stats

LibiptErrorsStats lldb_private::trace_intel_pt::DecodedThread::m_tsc_errors_stats
private

Statistics of libipt errors when decoding TSCs.

Definition at line 284 of file DecodedThread.h.

Referenced by GetTscErrorsStats(), and RecordTscError().


The documentation for this class was generated from the following files: