LLDB mainline
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

  • negative: actual errors
  • positive or zero: not an error, but a list of bits signaling the status of the decoder, e.g. whether there are events that need to be decoded or not.

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.

References m_anomaly_detector, m_decoded_thread, m_decoder_up, m_next_block_ip, m_psb_block, and m_tsc_upper_bound.

Referenced by Create().

Member Function Documentation

◆ AppendInstructionAndDetectAnomalies()

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

Append an instruction and return false if and only if a serious anomaly has been detected.

Definition at line 405 of file LibiptDecoder.cpp.

References m_anomaly_detector, m_decoded_thread, and lldb_private::toString().

Referenced by DecodeInstructionsAndEvents().

◆ Create()

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(), and PSBBlockDecoder().

◆ 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 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::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 createStringError(), IsLibiptError(), m_decoded_thread, m_decoder_up, m_psb_block, and m_tsc_upper_bound.

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(), and PSBBlockDecoder().

◆ m_decoded_thread

◆ 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(), and PSBBlockDecoder().

◆ m_psb_block

PSBBlock PSBBlockDecoder::m_psb_block
private

Definition at line 554 of file LibiptDecoder.cpp.

Referenced by DecodePSBBlock(), ProcessPTEventTSC(), and PSBBlockDecoder().

◆ 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(), and PSBBlockDecoder().


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