LLDB mainline
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
PSBBlockDecoder Class Reference

Class that decodes a raw buffer for a single PSB block using the low level libipt library. More...

Public Member Functions

 PSBBlockDecoder (PtInsnDecoderUP &&decoder_up, const PSBBlock &psb_block, std::optional< lldb::addr_t > next_block_ip, DecodedThread &decoded_thread, TraceIntelPT &trace_intel_pt, std::optional< DecodedThread::TSC > tsc_upper_bound)
 
void DecodePSBBlock ()
 

Static Public Member Functions

static Expected< PSBBlockDecoderCreate (TraceIntelPT &trace_intel_pt, const PSBBlock &psb_block, ArrayRef< uint8_t > buffer, Process &process, std::optional< lldb::addr_t > next_block_ip, DecodedThread &decoded_thread, std::optional< DecodedThread::TSC > tsc_upper_bound)
 

Private Member Functions

bool AppendInstructionAndDetectAnomalies (const pt_insn &insn)
 Append an instruction and return false if and only if a serious anomaly has been detected.
 
void DecodeInstructionsAndEvents (int status)
 Decode all the instructions and events of the given PSB block.
 
Error ProcessPTEventTSC (DecodedThread::TSC tsc)
 Process the TSC of a decoded PT event.
 
int ProcessPTEvents (int status)
 Before querying instructions, we need to query the events associated with that instruction, e.g.
 

Private Attributes

PtInsnDecoderUP m_decoder_up
 
PSBBlock m_psb_block
 
std::optional< lldb::addr_tm_next_block_ip
 
DecodedThreadm_decoded_thread
 
PSBBlockAnomalyDetector m_anomaly_detector
 
std::optional< DecodedThread::TSCm_tsc_upper_bound
 

Detailed Description

Class that decodes a raw buffer for a single PSB block using the low level libipt library.

It assumes that kernel and user mode instructions are not mixed in the same PSB block.

Throughout this code, the status of the decoder will be used to identify events needed to be processed or errors in the decoder. The values can be

Definition at line 319 of file LibiptDecoder.cpp.

Constructor & Destructor Documentation

◆ PSBBlockDecoder()

PSBBlockDecoder::PSBBlockDecoder ( PtInsnDecoderUP &&  decoder_up,
const PSBBlock psb_block,
std::optional< lldb::addr_t next_block_ip,
DecodedThread decoded_thread,
TraceIntelPT trace_intel_pt,
std::optional< DecodedThread::TSC tsc_upper_bound 
)
inline
Parameters
[in]decoderA decoder configured to start and end within the boundaries of the given psb_block.
[in]psb_blockThe PSB block to decode.
[in]next_block_ipThe starting ip at the next PSB block of the same thread if available.
[in]decoded_threadA DecodedThread object where the decoded instructions will be appended to. It might have already some instructions.
[in]tsc_upper_boundMaximum allowed value of TSCs decoded from this PSB block. Any of this PSB's data occurring after this TSC will be excluded.

Definition at line 338 of file LibiptDecoder.cpp.

Member Function Documentation

◆ AppendInstructionAndDetectAnomalies()

bool PSBBlockDecoder::AppendInstructionAndDetectAnomalies ( const pt_insn &  insn)
inlineprivate

◆ Create()

static Expected< PSBBlockDecoder > PSBBlockDecoder::Create ( TraceIntelPT trace_intel_pt,
const PSBBlock psb_block,
ArrayRef< uint8_t >  buffer,
Process process,
std::optional< lldb::addr_t next_block_ip,
DecodedThread decoded_thread,
std::optional< DecodedThread::TSC tsc_upper_bound 
)
inlinestatic
Parameters
[in]trace_intel_ptThe main Trace object that own the PSB block.
[in]decoderA decoder configured to start and end within the boundaries of the given psb_block.
[in]psb_blockThe PSB block to decode.
[in]bufferThe raw intel pt trace for this block.
[in]processThe process to decode. It provides the memory image to use for decoding.
[in]next_block_ipThe starting ip at the next PSB block of the same thread if available.
[in]decoded_threadA DecodedThread object where the decoded instructions will be appended to. It might have already some instructions.

Definition at line 371 of file LibiptDecoder.cpp.

References CreateInstructionDecoder().

◆ DecodeInstructionsAndEvents()

void PSBBlockDecoder::DecodeInstructionsAndEvents ( int  status)
inlineprivate

Decode all the instructions and events of the given PSB block.

The decoding loop might stop abruptly if an infinite decoding loop is detected.

Definition at line 418 of file LibiptDecoder.cpp.

References lldb_private::trace_intel_pt::DecodedThread::AppendError(), AppendInstructionAndDetectAnomalies(), IsEndOfStream(), IsLibiptError(), m_decoded_thread, m_decoder_up, m_next_block_ip, and ProcessPTEvents().

Referenced by DecodePSBBlock().

◆ DecodePSBBlock()

void PSBBlockDecoder::DecodePSBBlock ( )
inline

◆ ProcessPTEvents()

int PSBBlockDecoder::ProcessPTEvents ( int  status)
inlineprivate

Before querying instructions, we need to query the events associated with that instruction, e.g.

timing and trace disablement events.

Parameters
[in]statusThe status gotten from the previous instruction decoding or PSB synchronization.
Returns
The pte_status after decoding events.

Definition at line 508 of file LibiptDecoder.cpp.

References lldb_private::trace_intel_pt::DecodedThread::AppendError(), lldb_private::trace_intel_pt::DecodedThread::AppendEvent(), lldb::eTraceEventDisabledHW, lldb::eTraceEventDisabledSW, HasEvents(), IsLibiptError(), m_decoded_thread, m_decoder_up, and ProcessPTEventTSC().

Referenced by DecodeInstructionsAndEvents().

◆ ProcessPTEventTSC()

Error PSBBlockDecoder::ProcessPTEventTSC ( DecodedThread::TSC  tsc)
inlineprivate

Process the TSC of a decoded PT event.

Specifically, check if this TSC is below the TSC upper bound for this PSB. If the TSC exceeds the upper bound, return an error to abort decoding. Otherwise add the it to the underlying DecodedThread and decoding should continue as expected.

Parameters
[in]tscThe TSC of the a decoded event.

Definition at line 471 of file LibiptDecoder.cpp.

References lldb_private::trace_intel_pt::DecodedThread::AppendCustomError(), IsLibiptError(), m_decoded_thread, m_decoder_up, m_psb_block, m_tsc_upper_bound, lldb_private::trace_intel_pt::DecodedThread::NotifyTsc(), and lldb_private::trace_intel_pt::PSBBlock::size.

Referenced by ProcessPTEvents().

Member Data Documentation

◆ m_anomaly_detector

PSBBlockAnomalyDetector PSBBlockDecoder::m_anomaly_detector
private

Definition at line 557 of file LibiptDecoder.cpp.

Referenced by AppendInstructionAndDetectAnomalies().

◆ m_decoded_thread

DecodedThread& PSBBlockDecoder::m_decoded_thread
private

◆ m_decoder_up

PtInsnDecoderUP PSBBlockDecoder::m_decoder_up
private

◆ m_next_block_ip

std::optional<lldb::addr_t> PSBBlockDecoder::m_next_block_ip
private

Definition at line 555 of file LibiptDecoder.cpp.

Referenced by DecodeInstructionsAndEvents().

◆ m_psb_block

PSBBlock PSBBlockDecoder::m_psb_block
private

Definition at line 554 of file LibiptDecoder.cpp.

Referenced by DecodePSBBlock(), and ProcessPTEventTSC().

◆ m_tsc_upper_bound

std::optional<DecodedThread::TSC> PSBBlockDecoder::m_tsc_upper_bound
private

Definition at line 558 of file LibiptDecoder.cpp.

Referenced by ProcessPTEventTSC().


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