Go to the documentation of this file.
9 #ifndef LLDB_TARGET_TRACE_H
10 #define LLDB_TARGET_TRACE_H
12 #include <unordered_map>
14 #include "llvm/Support/JSON.h"
47 public std::enable_shared_from_this<Trace> {
113 static llvm::Expected<lldb::TraceSP>
115 const llvm::json::Value &bundle_description,
116 llvm::StringRef session_file_dir);
130 static llvm::Expected<lldb::TraceSP>
137 static llvm::Expected<llvm::StringRef>
153 static llvm::Expected<lldb::TraceSP>
155 const FileSpec &trace_description_file);
158 virtual lldb::CommandObjectSP
162 virtual lldb::CommandObjectSP
174 virtual llvm::Expected<lldb::TraceCursorUP>
231 llvm::ArrayRef<lldb::tid_t> tids,
349 llvm::Expected<std::vector<uint8_t>>
351 uint64_t expected_size);
368 llvm::StringRef kind,
384 llvm::StringRef kind);
399 llvm::StringRef kind);
438 llvm::Expected<std::vector<uint8_t>>
452 llvm::Expected<std::vector<uint8_t>>
463 llvm::Expected<std::vector<uint8_t>>
468 llvm::StringRef kind);
472 llvm::StringRef kind);
478 Trace(llvm::ArrayRef<lldb::ProcessSP> postmortem_processes,
479 llvm::Optional<std::vector<lldb::cpu_id_t>> postmortem_cpus);
519 llvm::StringRef json_response) = 0;
557 llvm::DenseMap<lldb::tid_t, llvm::DenseMap<ConstString, uint64_t>>
561 llvm::DenseMap<lldb::cpu_id_t, llvm::DenseMap<ConstString, uint64_t>>
565 llvm::DenseMap<ConstString, std::vector<uint8_t>>>
574 llvm::Optional<std::vector<lldb::cpu_id_t>>
cpus;
581 llvm::DenseMap<lldb::tid_t, llvm::DenseMap<ConstString, FileSpec>>
585 llvm::DenseMap<lldb::cpu_id_t, llvm::DenseMap<ConstString, FileSpec>>
599 #endif // LLDB_TARGET_TRACE_H
llvm::Optional< std::vector< lldb::cpu_id_t > > cpus
The list of cpus being traced.
struct lldb_private::Trace::Storage m_storage
jLLDBTraceGetBinaryData gdb-remote packet
std::function< llvm::Error(llvm::ArrayRef< uint8_t > data)> OnBinaryDataReadCallback
llvm::ArrayRef< Process * > GetPostMortemProcesses()
Get the currently traced postmortem processes.
std::vector< Process * > GetAllProcesses()
llvm::Optional< uint64_t > GetLiveThreadBinaryDataSize(lldb::tid_t tid, llvm::StringRef kind)
Get the size of the data returned by GetLiveThreadBinaryData.
llvm::Optional< std::string > live_refresh_error
virtual lldb::CommandObjectSP GetProcessTraceStartCommand(CommandInterpreter &interpreter)=0
Get the command handle for the "process trace start" command.
static llvm::Expected< lldb::TraceSP > FindPluginForLiveProcess(llvm::StringRef plugin_name, Process &process)
Find a trace plug-in to trace a live process.
Process * GetLiveProcess()
Get the currently traced live process.
static llvm::Expected< lldb::TraceSP > LoadPostMortemTraceFromFile(Debugger &debugger, const FileSpec &trace_description_file)
Load a trace from a trace description file and create Targets, Processes and Threads based on the con...
static llvm::Error OnDataFileRead(FileSpec file, OnBinaryDataReadCallback callback)
Helper method for reading a data file and passing its data to the given callback.
void SetPostMortemThreadDataFile(lldb::tid_t tid, llvm::StringRef kind, FileSpec file_spec)
Associate a given thread with a data file using a data identifier.
llvm::Expected< std::vector< uint8_t > > GetLiveCpuBinaryData(lldb::cpu_id_t cpu_id, llvm::StringRef kind)
Get binary data of a live cpu given a data identifier.
virtual const char * GetStartConfigurationHelp()=0
llvm::Error OnPostMortemThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnThreadBinaryDataRead() for post mortem threads.
We package all the data that can change upon process stops to make sure this contract is very visible...
std::function< llvm::Error(const llvm::DenseMap< lldb::cpu_id_t, llvm::ArrayRef< uint8_t > > &cpu_to_data)> OnCpusBinaryDataReadCallback
llvm::Expected< std::vector< uint8_t > > GetLiveProcessBinaryData(llvm::StringRef kind)
Get binary data of the current process given a data identifier.
const char * RefreshLiveProcessState()
Method to be invoked by the plug-in to refresh the live process state.
std::shared_ptr< Object > ObjectSP
static llvm::Expected< lldb::TraceSP > FindPluginForPostMortemProcess(Debugger &debugger, const llvm::json::Value &bundle_description, llvm::StringRef session_file_dir)
Find a trace plug-in using JSON data.
llvm::Error OnPostMortemCpuBinaryDataRead(lldb::cpu_id_t cpu_id, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnCpuBinaryDataRead() for post mortem cpus.
llvm::Error OnLiveThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnThreadBinaryDataRead() for live threads.
virtual lldb::CommandObjectSP GetThreadTraceStartCommand(CommandInterpreter &interpreter)=0
Get the command handle for the "thread trace start" command.
virtual llvm::Expected< lldb::TraceCursorUP > CreateNewCursor(Thread &thread)=0
Get a TraceCursor for the given thread's trace.
virtual bool IsTraced(lldb::tid_t tid)=0
Check if a thread is currently traced by this object.
llvm::Error OnAllCpusBinaryDataRead(llvm::StringRef kind, OnCpusBinaryDataReadCallback callback)
Similar to OnCpuBinaryDataRead but this is able to fetch the same data from all cpus at once.
llvm::DenseMap< lldb::cpu_id_t, llvm::DenseMap< ConstString, std::vector< uint8_t > > > live_cpu_data
cpu id -> data kind -> bytes
virtual llvm::Error Start(StructuredData::ObjectSP configuration=StructuredData::ObjectSP())=0
Start tracing a live process.
llvm::Expected< FileSpec > GetPostMortemThreadDataFile(lldb::tid_t tid, llvm::StringRef kind)
Get the file path containing data of a postmortem thread given a data identifier.
std::vector< Process * > GetTracedProcesses()
Return the list of processes traced by this instance.
llvm::DenseMap< lldb::tid_t, llvm::DenseMap< ConstString, FileSpec > > postmortem_thread_data
Postmortem traces can specific additional data files, which are represented in this variable using a ...
#define LLDB_INVALID_STOP_ID
Invalid value definitions.
llvm::Expected< FileSpec > GetPostMortemCpuDataFile(lldb::cpu_id_t cpu_id, llvm::StringRef kind)
Get the file path containing data of a postmortem cpu given a data identifier.
Process * m_live_process
Process traced by this object if doing live tracing. Otherwise it's null.
llvm::DenseMap< lldb::cpu_id_t, llvm::DenseMap< ConstString, FileSpec > > postmortem_cpu_data
cpu id -> data kind -> file
Storage & GetUpdatedStorage()
Get the storage after refreshing the data in the case of a live process.
virtual void Dump(Stream *s) const =0
Dump the trace data that this plug-in has access to.
llvm::DenseMap< ConstString, uint64_t > live_process_data
data kind -> size
llvm::DenseMap< lldb::tid_t, llvm::DenseMap< ConstString, uint64_t > > live_thread_data
These data kinds are returned by lldb-server when fetching the state of the tracing session.
llvm::DenseMap< lldb::cpu_id_t, llvm::DenseMap< ConstString, uint64_t > > live_cpu_data_sizes
cpu id -> data kind -> size
llvm::Error Stop()
Stop tracing all current and future threads of a live process.
llvm::Optional< uint64_t > GetLiveProcessBinaryDataSize(llvm::StringRef kind)
Get the size of the data returned by GetLiveProcessBinaryData.
llvm::ArrayRef< lldb::cpu_id_t > GetTracedCpus()
A class that represents a running process on the host machine.
llvm::Error OnCpuBinaryDataRead(lldb::cpu_id_t cpu_id, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Fetch binary data associated with a cpu, either live or postmortem, and pass it to the given callback...
llvm::Error OnThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Fetch binary data associated with a thread, either live or postmortem, and pass it to the given callb...
llvm::Expected< std::vector< uint8_t > > GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind)
Get binary data of a live thread given a data identifier.
virtual llvm::StringRef GetSchema()=0
llvm::Error OnLiveCpuBinaryDataRead(lldb::cpu_id_t cpu, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnLiveBinaryDataRead() for live cpus.
llvm::Expected< std::vector< uint8_t > > GetLiveTraceBinaryData(const TraceGetBinaryDataRequest &request, uint64_t expected_size)
Dispatcher for live trace data requests with some additional error checking.
std::vector< Process * > postmortem_processes
Portmortem processes traced by this object if doing non-live tracing.
Trace(Process &live_process)
Constructor for a live process.
static llvm::Expected< llvm::StringRef > FindPluginSchema(llvm::StringRef plugin_name)
Get the schema of a Trace plug-in given its name.
virtual llvm::Error DoRefreshLiveProcessState(TraceGetStateResponse state, llvm::StringRef json_response)=0
Method to be overriden by the plug-in to refresh its own state.
void SetPostMortemCpuDataFile(lldb::cpu_id_t cpu_id, llvm::StringRef kind, FileSpec file_spec)
Associate a given cpu with a data file using a data identifier.
Trace(llvm::ArrayRef< lldb::ProcessSP > postmortem_processes, llvm::Optional< std::vector< lldb::cpu_id_t >> postmortem_cpus)
Constructor for post mortem processes.
llvm::Expected< std::string > GetLiveProcessState()
Get the current tracing state of a live process and its threads.
llvm::Optional< uint64_t > GetLiveCpuBinaryDataSize(lldb::cpu_id_t cpu_id, llvm::StringRef kind)
Get the size of the data returned by GetLiveCpuBinaryData.
virtual void DumpTraceInfo(Thread &thread, Stream &s, bool verbose, bool json)=0
Dump general info about a given thread's trace.
virtual llvm::Expected< FileSpec > SaveToDisk(FileSpec directory, bool compact)=0
Save the trace to the specified directory, which will be created if needed.