9#ifndef LLDB_TARGET_TRACE_H
10#define LLDB_TARGET_TRACE_H
13#include <unordered_map>
15#include "llvm/Support/JSON.h"
48 public std::enable_shared_from_this<Trace> {
114 static llvm::Expected<lldb::TraceSP>
116 const llvm::json::Value &bundle_description,
117 llvm::StringRef session_file_dir);
131 static llvm::Expected<lldb::TraceSP>
138 static llvm::Expected<llvm::StringRef>
154 static llvm::Expected<lldb::TraceSP>
156 const FileSpec &trace_description_file);
175 virtual llvm::Expected<lldb::TraceCursorSP>
232 llvm::ArrayRef<lldb::tid_t> tids,
243 llvm::Error
Stop(llvm::ArrayRef<lldb::tid_t> tids);
261 std::function<llvm::Error(llvm::ArrayRef<uint8_t> data)>;
350 llvm::Expected<std::vector<uint8_t>>
352 uint64_t expected_size);
369 llvm::StringRef kind,
385 llvm::StringRef kind);
400 llvm::StringRef kind);
439 llvm::Expected<std::vector<uint8_t>>
453 llvm::Expected<std::vector<uint8_t>>
464 llvm::Expected<std::vector<uint8_t>>
469 llvm::StringRef kind);
473 llvm::StringRef kind);
479 Trace(llvm::ArrayRef<lldb::ProcessSP> postmortem_processes,
480 std::optional<std::vector<lldb::cpu_id_t>> postmortem_cpus);
495 llvm::Error
Start(
const llvm::json::Value &request);
520 llvm::StringRef json_response) = 0;
558 llvm::DenseMap<lldb::tid_t, llvm::DenseMap<ConstString, uint64_t>>
562 llvm::DenseMap<lldb::cpu_id_t, llvm::DenseMap<ConstString, uint64_t>>
566 llvm::DenseMap<ConstString, std::vector<uint8_t>>>
575 std::optional<std::vector<lldb::cpu_id_t>>
cpus;
582 llvm::DenseMap<lldb::tid_t, llvm::DenseMap<ConstString, FileSpec>>
586 llvm::DenseMap<lldb::cpu_id_t, llvm::DenseMap<ConstString, FileSpec>>
A class to manage flag bits.
A plug-in interface definition class for debugging a process.
A stream class that can stream formatted output to a file.
std::shared_ptr< Object > ObjectSP
A plug-in interface definition class for trace information.
std::vector< Process * > GetTracedProcesses()
Return the list of processes traced by this instance.
static llvm::Error OnDataFileRead(FileSpec file, OnBinaryDataReadCallback callback)
Helper method for reading a data file and passing its data to the given callback.
llvm::Error OnPostMortemCpuBinaryDataRead(lldb::cpu_id_t cpu_id, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnCpuBinaryDataRead() for post mortem cpus.
virtual llvm::Error Start(StructuredData::ObjectSP configuration=StructuredData::ObjectSP())=0
Start tracing a live process.
std::function< llvm::Error(llvm::ArrayRef< uint8_t > data)> OnBinaryDataReadCallback
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 > > GetLiveCpuBinaryData(lldb::cpu_id_t cpu_id, llvm::StringRef kind)
Get binary data of a live cpu given a data identifier.
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.
llvm::Expected< std::vector< uint8_t > > GetLiveProcessBinaryData(llvm::StringRef kind)
Get binary data of the current process given a data identifier.
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.
Storage & GetUpdatedStorage()
Get the storage after refreshing the data in the case of a live process.
llvm::Error OnLiveCpuBinaryDataRead(lldb::cpu_id_t cpu, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnLiveBinaryDataRead() for live cpus.
llvm::Expected< std::string > GetLiveProcessState()
Get the current tracing state of a live process and its threads.
virtual const char * GetStartConfigurationHelp()=0
static llvm::Expected< lldb::TraceSP > FindPluginForLiveProcess(llvm::StringRef plugin_name, Process &process)
Find a trace plug-in to trace a live process.
std::optional< uint64_t > GetLiveCpuBinaryDataSize(lldb::cpu_id_t cpu_id, llvm::StringRef kind)
Get the size of the data returned by GetLiveCpuBinaryData.
Process * m_live_process
Process traced by this object if doing live tracing. Otherwise it's null.
llvm::Error Stop()
Stop tracing all current and future threads of a live process.
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.
virtual llvm::StringRef GetSchema()=0
Trace(Process &live_process)
Constructor for a live process.
virtual lldb::CommandObjectSP GetThreadTraceStartCommand(CommandInterpreter &interpreter)=0
Get the command handle for the "thread trace start" command.
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...
virtual void Dump(Stream *s) const =0
Dump the trace data that this plug-in has access to.
virtual void DumpTraceInfo(Thread &thread, Stream &s, bool verbose, bool json)=0
Dump general info about a given thread's trace.
virtual llvm::Expected< lldb::TraceCursorSP > CreateNewCursor(Thread &thread)=0
Get a TraceCursor for the given thread's trace.
Trace(llvm::ArrayRef< lldb::ProcessSP > postmortem_processes, std::optional< std::vector< lldb::cpu_id_t > > postmortem_cpus)
Constructor for post mortem processes.
struct lldb_private::Trace::Storage m_storage
llvm::Error OnPostMortemThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnThreadBinaryDataRead() for post mortem threads.
static llvm::Expected< llvm::StringRef > FindPluginSchema(llvm::StringRef plugin_name)
Get the schema of a Trace plug-in given its name.
llvm::ArrayRef< lldb::cpu_id_t > GetTracedCpus()
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::Error Start(llvm::ArrayRef< lldb::tid_t > tids, StructuredData::ObjectSP configuration=StructuredData::ObjectSP())=0
Start tracing live threads.
void SetPostMortemThreadDataFile(lldb::tid_t tid, llvm::StringRef kind, FileSpec file_spec)
Associate a given thread with a data file using a data identifier.
const char * RefreshLiveProcessState()
Method to be invoked by the plug-in to refresh the live process state.
std::vector< Process * > GetAllProcesses()
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::Expected< std::vector< uint8_t > > GetLiveTraceBinaryData(const TraceGetBinaryDataRequest &request, uint64_t expected_size)
Dispatcher for live trace data requests with some additional error checking.
virtual llvm::Expected< FileSpec > SaveToDisk(FileSpec directory, bool compact)=0
Save the trace to the specified directory, which will be created if needed.
virtual lldb::CommandObjectSP GetProcessTraceStartCommand(CommandInterpreter &interpreter)=0
Get the command handle for the "process trace start" command.
Process * GetLiveProcess()
Get the currently traced live process.
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.
std::optional< uint64_t > GetLiveProcessBinaryDataSize(llvm::StringRef kind)
Get the size of the data returned by GetLiveProcessBinaryData.
llvm::ArrayRef< Process * > GetPostMortemProcesses()
Get the currently traced postmortem processes.
llvm::Error OnLiveThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnThreadBinaryDataRead() for live threads.
virtual llvm::Error DoRefreshLiveProcessState(TraceGetStateResponse state, llvm::StringRef json_response)=0
Method to be overriden by the plug-in to refresh its own state.
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...
virtual bool IsTraced(lldb::tid_t tid)=0
Check if a thread is currently traced by this object.
std::optional< uint64_t > GetLiveThreadBinaryDataSize(lldb::tid_t tid, llvm::StringRef kind)
Get the size of the data returned by GetLiveThreadBinaryData.
std::function< llvm::Error(const llvm::DenseMap< lldb::cpu_id_t, llvm::ArrayRef< uint8_t > > &cpu_to_data)> OnCpusBinaryDataReadCallback
#define LLDB_INVALID_STOP_ID
Invalid value definitions.
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
jLLDBTraceGetBinaryData gdb-remote packet
We package all the data that can change upon process stops to make sure this contract is very visible...
llvm::DenseMap< lldb::cpu_id_t, llvm::DenseMap< ConstString, uint64_t > > live_cpu_data_sizes
cpu id -> data kind -> size
llvm::DenseMap< lldb::cpu_id_t, llvm::DenseMap< ConstString, std::vector< uint8_t > > > live_cpu_data
cpu id -> data kind -> bytes
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::tid_t, llvm::DenseMap< ConstString, FileSpec > > postmortem_thread_data
Postmortem traces can specific additional data files, which are represented in this variable using a ...
llvm::DenseMap< ConstString, uint64_t > live_process_data
data kind -> size
std::optional< std::vector< lldb::cpu_id_t > > cpus
The list of cpus being traced.
llvm::DenseMap< lldb::cpu_id_t, llvm::DenseMap< ConstString, FileSpec > > postmortem_cpu_data
cpu id -> data kind -> file
std::optional< std::string > live_refresh_error
std::vector< Process * > postmortem_processes
Portmortem processes traced by this object if doing non-live tracing.