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) {
107 if (command.
size() != 1) {
108 result.
AppendError(
"a single path to a directory where the trace bundle "
109 "will be created is required");
113 FileSpec bundle_dir(command[0].ref());
118 TraceSP trace_sp = process_sp->GetTarget().GetTrace();
120 if (llvm::Expected<FileSpec> desc_file =
123 "Trace bundle description file written to: {0}", *desc_file);
134#define LLDB_OPTIONS_trace_load
135#include "CommandOptions.inc"
137#pragma mark CommandObjectTraceLoad
152 switch (short_option) {
158 llvm_unreachable(
"Unimplemented option");
168 return ArrayRef(g_trace_load_options);
176 interpreter,
"trace load",
177 "Load a post-mortem processor trace session from a trace bundle.",
178 "trace load <trace_description_file>") {
196 if (command.
size() != 1) {
197 result.
AppendError(
"a single path to a JSON file containing a the "
198 "description of the trace bundle is required");
202 const FileSpec trace_description_file(command[0].ref());
204 llvm::Expected<lldb::TraceSP> trace_or_err =
206 trace_description_file);
210 "%s\n", llvm::toString(trace_or_err.takeError()).c_str());
216 trace_or_err.get()->GetPluginName());
226#define LLDB_OPTIONS_trace_dump
227#include "CommandOptions.inc"
229#pragma mark CommandObjectTraceDump
244 switch (short_option) {
250 llvm_unreachable(
"Unimplemented option");
260 return llvm::ArrayRef(g_trace_dump_options);
268 "Dump the loaded processor trace data.",
279 if (
error.Success()) {
290#define LLDB_OPTIONS_trace_schema
291#include "CommandOptions.inc"
293#pragma mark CommandObjectTraceSchema
308 switch (short_option) {
314 llvm_unreachable(
"Unimplemented option");
324 return llvm::ArrayRef(g_trace_schema_options);
332 "Show the schema of the given trace plugin.",
333 "trace schema <plug-in>. Use the plug-in name "
334 "\"all\" to see all schemas.\n") {
346 if (command.
empty()) {
348 "trace schema cannot be invoked without a plug-in as argument");
352 StringRef plugin_name(command[0].c_str());
353 if (plugin_name ==
"all") {
363 if (Expected<StringRef> schemaOrErr =
367 error = schemaOrErr.takeError();
370 if (
error.Success()) {
384 "Commands for loading and using processor "
385 "trace information.",
386 "trace [<sub-command-options>]") {
403 return createStringError(inconvertibleErrorCode(),
404 "Process not available.");
406 return createStringError(inconvertibleErrorCode(),
407 "Process must be alive.");
409 if (Expected<TraceSP> trace_sp = process_sp->GetTarget().GetTraceOrCreate())
412 return createStringError(inconvertibleErrorCode(),
413 "Tracing is not supported. %s",
414 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
void 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
~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
void DoExecute(Args &command, CommandReturnObject &result) 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 DoExecute(Args &command, CommandReturnObject &result) override
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)
~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
void 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)
std::shared_ptr< lldb_private::Trace > TraceSP
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
std::shared_ptr< lldb_private::Process > ProcessSP
@ eReturnStatusSuccessFinishResult
Used to build individual command argument lists.