11#include "llvm/Support/JSON.h"
12#include "llvm/Support/MemoryBuffer.h"
35#define LLDB_OPTIONS_trace_save
36#include "CommandOptions.inc"
38#pragma mark CommandObjectTraceSave
51 switch (short_option) {
57 llvm_unreachable(
"Unimplemented option");
67 return llvm::ArrayRef(g_trace_save_options);
77 interpreter,
"trace save",
78 "Save the trace of the current target in the specified directory, "
79 "which will be created if needed. "
80 "This directory will contain a trace bundle, with all the "
81 "necessary files the reconstruct the trace session even on a "
82 "different computer. "
83 "Part of this bundle is the bundle description file with the name "
84 "trace.json. This file can be used by the \"trace load\" command "
85 "to load this trace in LLDB."
86 "Note: if the current target contains information of multiple "
87 "processes or targets, they all will be included in the bundle.",
88 "trace save [<cmd-options>] <bundle_directory>",
89 eCommandRequiresProcess | eCommandTryTargetAPILock |
90 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused |
91 eCommandProcessMustBeTraced) {
108 if (command.
size() != 1) {
109 result.
AppendError(
"a single path to a directory where the trace bundle "
110 "will be created is required");
114 FileSpec bundle_dir(command[0].ref());
119 TraceSP trace_sp = process_sp->GetTarget().GetTrace();
121 if (llvm::Expected<FileSpec> desc_file =
124 "Trace bundle description file written to: {0}", *desc_file);
137#define LLDB_OPTIONS_trace_load
138#include "CommandOptions.inc"
140#pragma mark CommandObjectTraceLoad
155 switch (short_option) {
161 llvm_unreachable(
"Unimplemented option");
171 return ArrayRef(g_trace_load_options);
179 interpreter,
"trace load",
180 "Load a post-mortem processor trace session from a trace bundle.",
181 "trace load <trace_description_file>") {
200 if (command.
size() != 1) {
201 result.
AppendError(
"a single path to a JSON file containing a the "
202 "description of the trace bundle is required");
206 const FileSpec trace_description_file(command[0].ref());
208 llvm::Expected<lldb::TraceSP> trace_or_err =
210 trace_description_file);
214 "%s\n", llvm::toString(trace_or_err.takeError()).c_str());
220 trace_or_err.get()->GetPluginName());
231#define LLDB_OPTIONS_trace_dump
232#include "CommandOptions.inc"
234#pragma mark CommandObjectTraceDump
249 switch (short_option) {
255 llvm_unreachable(
"Unimplemented option");
265 return llvm::ArrayRef(g_trace_dump_options);
273 "Dump the loaded processor trace data.",
284 if (
error.Success()) {
296#define LLDB_OPTIONS_trace_schema
297#include "CommandOptions.inc"
299#pragma mark CommandObjectTraceSchema
314 switch (short_option) {
320 llvm_unreachable(
"Unimplemented option");
330 return llvm::ArrayRef(g_trace_schema_options);
338 "Show the schema of the given trace plugin.",
339 "trace schema <plug-in>. Use the plug-in name "
340 "\"all\" to see all schemas.\n") {
352 if (command.
empty()) {
354 "trace schema cannot be invoked without a plug-in as argument");
358 StringRef plugin_name(command[0].c_str());
359 if (plugin_name ==
"all") {
369 if (Expected<StringRef> schemaOrErr =
373 error = schemaOrErr.takeError();
376 if (
error.Success()) {
391 "Commands for loading and using processor "
392 "trace information.",
393 "trace [<sub-command-options>]") {
410 return createStringError(inconvertibleErrorCode(),
411 "Process not available.");
413 return createStringError(inconvertibleErrorCode(),
414 "Process must be alive.");
416 if (Expected<TraceSP> trace_sp = process_sp->GetTarget().GetTraceOrCreate())
419 return createStringError(inconvertibleErrorCode(),
420 "Tracing is not supported. %s",
421 toString(trace_sp.takeError()).c_str());
static llvm::raw_ostream & error(Stream &strm)
~CommandOptions() override=default
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
CommandObjectTraceDump(CommandInterpreter &interpreter)
Options * GetOptions() override
~CommandObjectTraceDump() override=default
bool DoExecute(Args &command, CommandReturnObject &result) override
Status SetOptionValue(uint32_t option_idx, StringRef option_arg, ExecutionContext *execution_context) override
ArrayRef< OptionDefinition > GetDefinitions() override
~CommandOptions() override=default
void OptionParsingStarting(ExecutionContext *execution_context) override
bool DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectTraceLoad() override=default
CommandObjectTraceLoad(CommandInterpreter &interpreter)
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
Options * GetOptions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void OptionParsingStarting(ExecutionContext *execution_context) override
~CommandObjectTraceSave() override=default
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
Options * GetOptions() override
CommandObjectTraceSave(CommandInterpreter &interpreter)
bool DoExecute(Args &command, CommandReturnObject &result) override
~CommandOptions() override=default
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
Options * GetOptions() override
bool DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectTraceSchema() override=default
CommandObjectTraceSchema(CommandInterpreter &interpreter)
A command line argument class.
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
ExecutionContext GetExecutionContext() const
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
bool m_live_debug_session_only
lldb::CommandObjectSP m_delegate_sp
std::string m_delegate_error
llvm::Expected< lldb::CommandObjectSP > DoGetProxyCommandObject()
CommandObject * GetProxyCommandObject() override
virtual lldb::CommandObjectSP GetDelegateCommand(Trace &trace)=0
~CommandObjectTrace() override
CommandObjectTrace(CommandInterpreter &interpreter)
ExecutionContext m_exe_ctx
std::vector< CommandArgumentEntry > m_arguments
CommandInterpreter & GetCommandInterpreter()
CommandInterpreter & m_interpreter
void AppendMessage(llvm::StringRef in_string)
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void void AppendMessageWithFormatv(const char *format, Args &&... args)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
"lldb/Utility/ArgCompletionRequest.h"
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
static FileSystem & Instance()
A command line option parsing protocol class.
std::vector< Option > m_getopt_table
static llvm::StringRef GetTraceSchema(llvm::StringRef plugin_name)
Get the JSON schema for a trace bundle description file corresponding to the given plugin.
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::Expected< llvm::StringRef > FindPluginSchema(llvm::StringRef plugin_name)
Get the schema of a Trace plug-in given its name.
A class that represents a running process on the host machine.
std::vector< OptionArgElement > OptionElementVector
const char * toString(AppleArm64ExceptionClass EC)
@ eReturnStatusSuccessFinishResult
Used to build individual command argument lists.