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

#include <TraceIntelPT.h>

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

Public Member Functions

void Dump (Stream *s) const override
 Dump the trace data that this plug-in has access to. More...
 
llvm::Error SaveLiveTraceToDisk (FileSpec directory) override
 Save the trace of a live process to the specified directory, which will be created if needed. More...
 
 ~TraceIntelPT () override=default
 
lldb::CommandObjectSP GetProcessTraceStartCommand (CommandInterpreter &interpreter) override
 Get the command handle for the "process trace start" command. More...
 
lldb::CommandObjectSP GetThreadTraceStartCommand (CommandInterpreter &interpreter) override
 Get the command handle for the "thread trace start" command. More...
 
llvm::StringRef GetSchema () override
 
lldb::TraceCursorUP GetCursor (Thread &thread) override
 Get a TraceCursor for the given thread's trace. More...
 
void DumpTraceInfo (Thread &thread, Stream &s, bool verbose) override
 Dump general info about a given thread's trace. More...
 
llvm::Optional< size_t > GetRawTraceSize (Thread &thread)
 
void DoRefreshLiveProcessState (llvm::Expected< TraceGetStateResponse > state) override
 Method to be overriden by the plug-in to refresh its own state. More...
 
bool IsTraced (lldb::tid_t tid) override
 Check if a thread is currently traced by this object. More...
 
const char * GetStartConfigurationHelp () override
 
llvm::Error Start (size_t thread_buffer_size, size_t total_buffer_size_limit, bool enable_tsc, llvm::Optional< size_t > psb_period)
 Start tracing a live process. More...
 
llvm::Error Start (StructuredData::ObjectSP configuration=StructuredData::ObjectSP()) override
 Start tracing a live process. More...
 
llvm::Error Start (llvm::ArrayRef< lldb::tid_t > tids, size_t thread_buffer_size, bool enable_tsc, llvm::Optional< size_t > psb_period)
 Start tracing live threads. More...
 
llvm::Error Start (llvm::ArrayRef< lldb::tid_t > tids, StructuredData::ObjectSP configuration=StructuredData::ObjectSP()) override
 Start tracing a live process. More...
 
llvm::Expected< std::vector< uint8_t > > GetLiveThreadBuffer (lldb::tid_t tid)
 Get the thread buffer content for a live thread. More...
 
llvm::Expected< pt_cpu > GetCPUInfo ()
 
ProcessGetLiveProcess ()
 Get the current traced live process. More...
 
- Public Member Functions inherited from lldb_private::Trace
llvm::Error Stop (llvm::ArrayRef< lldb::tid_t > tids)
 Stop tracing live threads. More...
 
llvm::Error Stop ()
 Stop tracing all current and future threads of a live process. More...
 
llvm::Expected< const FileSpec & > GetPostMortemTraceFile (lldb::tid_t tid)
 Get the trace file of the given post mortem thread. More...
 
uint32_t GetStopID ()
 
- Public Member Functions inherited from lldb_private::PluginInterface
 PluginInterface ()=default
 
virtual ~PluginInterface ()=default
 
 PluginInterface (const PluginInterface &)=delete
 
PluginInterfaceoperator= (const PluginInterface &)=delete
 

Private Member Functions

llvm::Expected< pt_cpu > GetCPUInfoForLiveProcess ()
 
 TraceIntelPT (const pt_cpu &cpu_info, const std::vector< lldb::ThreadPostMortemTraceSP > &traced_threads)
 
 TraceIntelPT (Process &live_process)
 Constructor for live processes. More...
 
DecodedThreadSP Decode (Thread &thread)
 Decode the trace of the given thread that, i.e. More...
 

Private Attributes

llvm::Optional< pt_cpu > m_cpu_info
 It is provided by either a session file or a live process' "cpuInfo" binary data. More...
 
std::map< lldb::tid_t, std::unique_ptr< ThreadDecoder > > m_thread_decoders
 
llvm::Optional< std::stringm_live_refresh_error
 Error gotten after a failed live process update, if any. More...
 

Friends

class TraceIntelPTSessionFileParser
 
llvm::StringRef GetPluginName () override
 PluginInterface protocol. More...
 
static void Initialize ()
 
static void Terminate ()
 
static llvm::Expected< lldb::TraceSP > CreateInstanceForSessionFile (const llvm::json::Value &trace_session_file, llvm::StringRef session_file_dir, Debugger &debugger)
 Create an instance of this class. More...
 
static llvm::Expected< lldb::TraceSP > CreateInstanceForLiveProcess (Process &process)
 
static ConstString GetPluginNameStatic ()
 

Additional Inherited Members

- Static Public Member Functions inherited from lldb_private::Trace
static llvm::Expected< lldb::TraceSP > FindPluginForPostMortemProcess (Debugger &debugger, const llvm::json::Value &trace_session_file, llvm::StringRef session_file_dir)
 Find a trace plug-in using JSON data. More...
 
static llvm::Expected< lldb::TraceSP > FindPluginForLiveProcess (llvm::StringRef plugin_name, Process &process)
 Find a trace plug-in to trace a live process. More...
 
static llvm::Expected< llvm::StringRef > FindPluginSchema (llvm::StringRef plugin_name)
 Get the schema of a Trace plug-in given its name. More...
 
- Protected Member Functions inherited from lldb_private::Trace
llvm::Expected< llvm::ArrayRef< uint8_t > > GetLiveThreadBinaryData (lldb::tid_t tid, llvm::StringRef kind)
 Get binary data of a live thread given a data identifier. More...
 
llvm::Expected< llvm::ArrayRef< uint8_t > > GetLiveProcessBinaryData (llvm::StringRef kind)
 Get binary data of the current process given a data identifier. More...
 
llvm::Optional< size_t > GetLiveThreadBinaryDataSize (lldb::tid_t tid, llvm::StringRef kind)
 Get the size of the data returned by GetLiveThreadBinaryData. More...
 
llvm::Optional< size_t > GetLiveProcessBinaryDataSize (llvm::StringRef kind)
 Get the size of the data returned by GetLiveProcessBinaryData. More...
 
 Trace ()=default
 Constructor for post mortem processes. More...
 
 Trace (Process &live_process)
 Constructor for a live process. More...
 
llvm::Error Start (const llvm::json::Value &request)
 Start tracing a live process or its threads. More...
 
llvm::Expected< std::stringGetLiveProcessState ()
 Get the current tracing state of a live process and its threads. More...
 
void RefreshLiveProcessState ()
 Method to be invoked by the plug-in to refresh the live process state. More...
 
- Protected Attributes inherited from lldb_private::Trace
uint32_t m_stop_id = LLDB_INVALID_STOP_ID
 
Processm_live_process = nullptr
 Process traced by this object if doing live tracing. Otherwise it's null. More...
 
std::map< lldb::tid_t, std::unordered_map< std::string, size_t > > m_live_thread_data
 tid -> data kind -> size More...
 
std::unordered_map< std::string, size_t > m_live_process_data
 data kind -> size More...
 

Detailed Description

Definition at line 21 of file TraceIntelPT.h.

Constructor & Destructor Documentation

◆ ~TraceIntelPT()

lldb_private::trace_intel_pt::TraceIntelPT::~TraceIntelPT ( )
overridedefault

◆ TraceIntelPT() [1/2]

lldb_private::trace_intel_pt::TraceIntelPT::TraceIntelPT ( const pt_cpu &  cpu_info,
const std::vector< lldb::ThreadPostMortemTraceSP > &  traced_threads 
)
private
Parameters
[in]trace_threadsThreadTrace instances, which are not live-processes and whose trace files are fixed.

◆ TraceIntelPT() [2/2]

lldb_private::trace_intel_pt::TraceIntelPT::TraceIntelPT ( Process live_process)
inlineprivate

Constructor for live processes.

Definition at line 167 of file TraceIntelPT.h.

Member Function Documentation

◆ CreateInstanceForLiveProcess()

Expected< TraceSP > TraceIntelPT::CreateInstanceForLiveProcess ( Process process)
static

◆ CreateInstanceForSessionFile()

Expected< TraceSP > TraceIntelPT::CreateInstanceForSessionFile ( const llvm::json::Value &  trace_session_file,
llvm::StringRef  session_file_dir,
Debugger debugger 
)
static

Create an instance of this class.

Parameters
[in]trace_session_fileThe contents of the trace session file. See Trace::FindPlugin.
[in]session_file_dirThe path to the directory that contains the session file. It's used to resolved relative paths in the session file.
[in]debuggerThe debugger instance where new Targets will be created as part of the JSON data parsing.
Returns
A trace instance or an error in case of failures.

Definition at line 68 of file TraceIntelPT.cpp.

References lldb_private::trace_intel_pt::TraceIntelPTSessionFileParser::Parse().

◆ Decode()

DecodedThreadSP TraceIntelPT::Decode ( Thread thread)
private

Decode the trace of the given thread that, i.e.

recontruct the traced instructions.

Parameters
[in]threadIf thread is a ThreadTrace, then its internal trace file will be decoded. Live threads are not currently supported.
Returns
A DecodedThread shared pointer with the decoded instructions. Any errors are embedded in the instruction list.

Definition at line 92 of file TraceIntelPT.cpp.

References lldb_private::UserID::GetID(), m_live_refresh_error, m_thread_decoders, and lldb_private::Trace::RefreshLiveProcessState().

Referenced by GetCursor(), and GetRawTraceSize().

◆ DoRefreshLiveProcessState()

void TraceIntelPT::DoRefreshLiveProcessState ( llvm::Expected< TraceGetStateResponse state)
overridevirtual

Method to be overriden by the plug-in to refresh its own state.

This is invoked by RefreshLiveProcessState when a new state is found.

Parameters
[in]stateThe jLLDBTraceGetState response.

Implements lldb_private::Trace.

Definition at line 193 of file TraceIntelPT.cpp.

References lldb_private::ThreadList::FindThreadByID(), lldb_private::Process::GetThreadList(), lldb_private::Trace::m_live_process, m_live_refresh_error, m_thread_decoders, lldb_private::TraceThreadState::tid, and lldb_private::toString().

◆ Dump()

void TraceIntelPT::Dump ( Stream s) const
overridevirtual

Dump the trace data that this plug-in has access to.

This function will dump all of the trace data for all threads in a user readable format. Options for dumping can be added as this API is iterated on.

Parameters
[in]sA stream object to dump the information to.

Implements lldb_private::Trace.

Definition at line 61 of file TraceIntelPT.cpp.

◆ DumpTraceInfo()

void TraceIntelPT::DumpTraceInfo ( Thread thread,
Stream s,
bool  verbose 
)
overridevirtual

Dump general info about a given thread's trace.

Each Trace plug-in decides which data to show.

Parameters
[in]threadThe thread that owns the trace in question.
[in]sThe stream object where the info will be printed printed.
[in]verboseIf true, print detailed info If false, print compact info

Implements lldb_private::Trace.

Definition at line 111 of file TraceIntelPT.cpp.

References lldb_private::UserID::GetID(), lldb_private::Thread::GetIndexID(), GetRawTraceSize(), and lldb_private::Stream::Printf().

◆ GetCPUInfo()

Expected< pt_cpu > TraceIntelPT::GetCPUInfo ( )

◆ GetCPUInfoForLiveProcess()

Expected< pt_cpu > TraceIntelPT::GetCPUInfoForLiveProcess ( )
private

Definition at line 129 of file TraceIntelPT.cpp.

References lldb_private::Trace::GetLiveProcessBinaryData(), and string().

Referenced by GetCPUInfo().

◆ GetCursor()

lldb::TraceCursorUP TraceIntelPT::GetCursor ( Thread thread)
overridevirtual

Get a TraceCursor for the given thread's trace.

Returns
A TraceCursorUP. If the thread is not traced or its trace information failed to load, the corresponding error is embedded in the trace.

Implements lldb_private::Trace.

Definition at line 107 of file TraceIntelPT.cpp.

References Decode().

◆ GetLiveProcess()

Process * TraceIntelPT::GetLiveProcess ( )

Get the current traced live process.

Returns
The current traced live process. If it's not a live process, return nullptr.

Definition at line 191 of file TraceIntelPT.cpp.

References lldb_private::Trace::m_live_process.

Referenced by lldb_private::trace_intel_pt::TraceIntelPTSessionSaver::SaveToDisk().

◆ GetLiveThreadBuffer()

Expected< std::vector< uint8_t > > TraceIntelPT::GetLiveThreadBuffer ( lldb::tid_t  tid)

Get the thread buffer content for a live thread.

Definition at line 343 of file TraceIntelPT.cpp.

References lldb_private::Trace::GetLiveThreadBinaryData().

Referenced by DecodeLiveThread(), and lldb_private::trace_intel_pt::TraceIntelPTSessionSaver::SaveToDisk().

◆ GetPluginName()

llvm::StringRef lldb_private::trace_intel_pt::TraceIntelPT::GetPluginName ( )
inlineoverridevirtual

◆ GetPluginNameStatic()

ConstString TraceIntelPT::GetPluginNameStatic ( )
static

Definition at line 52 of file TraceIntelPT.cpp.

Referenced by GetPluginName().

◆ GetProcessTraceStartCommand()

lldb::CommandObjectSP TraceIntelPT::GetProcessTraceStartCommand ( CommandInterpreter interpreter)
overridevirtual

Get the command handle for the "process trace start" command.

Implements lldb_private::Trace.

Definition at line 30 of file TraceIntelPT.cpp.

◆ GetRawTraceSize()

Optional< size_t > TraceIntelPT::GetRawTraceSize ( Thread thread)

Definition at line 122 of file TraceIntelPT.cpp.

References Decode(), lldb_private::UserID::GetID(), and IsTraced().

Referenced by DumpTraceInfo().

◆ GetSchema()

StringRef TraceIntelPT::GetSchema ( )
overridevirtual
Returns
The JSON schema of this Trace plug-in.

Implements lldb_private::Trace.

Definition at line 57 of file TraceIntelPT.cpp.

◆ GetStartConfigurationHelp()

const char * TraceIntelPT::GetStartConfigurationHelp ( )
overridevirtual
Returns
A description of the parameters to use for the Trace::Start method.

Implements lldb_private::Trace.

Definition at line 219 of file TraceIntelPT.cpp.

◆ GetThreadTraceStartCommand()

lldb::CommandObjectSP TraceIntelPT::GetThreadTraceStartCommand ( CommandInterpreter interpreter)
overridevirtual

Get the command handle for the "thread trace start" command.

Implements lldb_private::Trace.

Definition at line 36 of file TraceIntelPT.cpp.

◆ Initialize()

void TraceIntelPT::Initialize ( )
static

Definition at line 41 of file TraceIntelPT.cpp.

◆ IsTraced()

bool TraceIntelPT::IsTraced ( lldb::tid_t  tid)
overridevirtual

Check if a thread is currently traced by this object.

Parameters
[in]tidThe id of the thread in question.
Returns
true if the thread is traced by this instance, false otherwise.

Implements lldb_private::Trace.

Definition at line 210 of file TraceIntelPT.cpp.

References m_thread_decoders, and lldb_private::Trace::RefreshLiveProcessState().

Referenced by GetRawTraceSize(), and lldb_private::trace_intel_pt::TraceIntelPTSessionSaver::SaveToDisk().

◆ SaveLiveTraceToDisk()

llvm::Error TraceIntelPT::SaveLiveTraceToDisk ( FileSpec  directory)
overridevirtual

Save the trace of a live process to the specified directory, which will be created if needed.

This will also create a a file <directory>/trace.json with the main properties of the trace session, along with others files which contain the actual trace data. The trace.json file can be used later as input for the "trace load" command to load the trace in LLDB. The process being trace is not a live process, return an error.

Parameters
[in]directoryThe directory where the trace files will be saved.
Returns
llvm::success if the operation was successful, or an llvm::Error otherwise.

Implements lldb_private::Trace.

Definition at line 63 of file TraceIntelPT.cpp.

References lldb_private::trace_intel_pt::TraceIntelPTSessionSaver::SaveToDisk().

◆ Start() [1/4]

llvm::Error lldb_private::trace_intel_pt::TraceIntelPT::Start ( llvm::ArrayRef< lldb::tid_t tids,
size_t  thread_buffer_size,
bool  enable_tsc,
llvm::Optional< size_t >  psb_period 
)

Start tracing live threads.

Parameters
[in]tidsThreads to trace.
[in]thread_buffer_sizeTrace size per thread in bytes.
[in]enable_tscWhether to use enable TSC timestamps or not. More information in TraceIntelPT::GetStartConfigurationHelp().
[in]psb_period
This value defines the period in which PSB packets will be generated.
More information in TraceIntelPT::GetStartConfigurationHelp().
Returns
llvm::Error::success if the operation was successful, or llvm::Error otherwise.

◆ Start() [2/4]

llvm::Error lldb_private::trace_intel_pt::TraceIntelPT::Start ( llvm::ArrayRef< lldb::tid_t tids,
StructuredData::ObjectSP  configuration = StructuredData::ObjectSP() 
)
overridevirtual

Start tracing a live process.

Parameters
[in]configurationSee SBTrace::Start(const lldb::SBStructuredData &) for more information.
Returns
llvm::Error::success if the operation was successful, or llvm::Error otherwise.

Implements lldb_private::Trace.

◆ Start() [3/4]

llvm::Error lldb_private::trace_intel_pt::TraceIntelPT::Start ( size_t  thread_buffer_size,
size_t  total_buffer_size_limit,
bool  enable_tsc,
llvm::Optional< size_t >  psb_period 
)

Start tracing a live process.

Parameters
[in]thread_buffer_sizeTrace size per thread in bytes.
[in]total_buffer_size_limitMaximum total trace size per process in bytes. More information in TraceIntelPT::GetStartConfigurationHelp().
[in]enable_tscWhether to use enable TSC timestamps or not. More information in TraceIntelPT::GetStartConfigurationHelp().
[in]psb_period
This value defines the period in which PSB packets will be generated.
More information in TraceIntelPT::GetStartConfigurationHelp();
Returns
llvm::Error::success if the operation was successful, or llvm::Error otherwise.

Referenced by Start().

◆ Start() [4/4]

Error TraceIntelPT::Start ( StructuredData::ObjectSP  configuration = StructuredData::ObjectSP())
overridevirtual

Start tracing a live process.

Parameters
[in]configurationSee SBTrace::Start(const lldb::SBStructuredData &) for more information.
Returns
llvm::Error::success if the operation was successful, or llvm::Error otherwise.

Implements lldb_private::Trace.

Definition at line 285 of file TraceIntelPT.cpp.

References lldb_private::StructuredData::Object::GetAsDictionary(), lldb_private::trace_intel_pt::kDefaultEnableTscValue, lldb_private::trace_intel_pt::kDefaultProcessBufferSizeLimit, lldb_private::trace_intel_pt::kDefaultPsbPeriod, lldb_private::trace_intel_pt::kDefaultThreadBufferSize, and Start().

◆ Terminate()

void TraceIntelPT::Terminate ( )
static

Definition at line 48 of file TraceIntelPT.cpp.

Friends And Related Function Documentation

◆ TraceIntelPTSessionFileParser

friend class TraceIntelPTSessionFileParser
friend

Definition at line 155 of file TraceIntelPT.h.

Member Data Documentation

◆ m_cpu_info

llvm::Optional<pt_cpu> lldb_private::trace_intel_pt::TraceIntelPT::m_cpu_info
private

It is provided by either a session file or a live process' "cpuInfo" binary data.

Definition at line 184 of file TraceIntelPT.h.

Referenced by GetCPUInfo().

◆ m_live_refresh_error

llvm::Optional<std::string> lldb_private::trace_intel_pt::TraceIntelPT::m_live_refresh_error
private

Error gotten after a failed live process update, if any.

Definition at line 187 of file TraceIntelPT.h.

Referenced by Decode(), and DoRefreshLiveProcessState().

◆ m_thread_decoders

std::map<lldb::tid_t, std::unique_ptr<ThreadDecoder> > lldb_private::trace_intel_pt::TraceIntelPT::m_thread_decoders
private

Definition at line 185 of file TraceIntelPT.h.

Referenced by Decode(), DoRefreshLiveProcessState(), and IsTraced().


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