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) {
106 if (command.
size() != 1) {
107 result.
AppendError(
"a single path to a directory where the trace bundle "
108 "will be created is required");
112 FileSpec bundle_dir(command[0].ref());
117 TraceSP trace_sp = process_sp->GetTarget().GetTrace();
119 if (llvm::Expected<FileSpec> desc_file =
122 "Trace bundle description file written to: {0}", *desc_file);
133#define LLDB_OPTIONS_trace_load
134#include "CommandOptions.inc"
136#pragma mark CommandObjectTraceLoad
151 switch (short_option) {
157 llvm_unreachable(
"Unimplemented option");
167 return ArrayRef(g_trace_load_options);
175 interpreter,
"trace load",
176 "Load a post-mortem processor trace session from a trace bundle.",
177 "trace load <trace_description_file>") {
194 if (command.
size() != 1) {
195 result.
AppendError(
"a single path to a JSON file containing a the "
196 "description of the trace bundle is required");
200 const FileSpec trace_description_file(command[0].ref());
202 llvm::Expected<lldb::TraceSP> trace_or_err =
204 trace_description_file);
208 "%s\n", llvm::toString(trace_or_err.takeError()).c_str());
214 trace_or_err.get()->GetPluginName());
224#define LLDB_OPTIONS_trace_dump
225#include "CommandOptions.inc"
227#pragma mark CommandObjectTraceDump
242 switch (short_option) {
248 llvm_unreachable(
"Unimplemented option");
258 return llvm::ArrayRef(g_trace_dump_options);
266 "Dump the loaded processor trace data.",
277 if (
error.Success()) {
288#define LLDB_OPTIONS_trace_schema
289#include "CommandOptions.inc"
291#pragma mark CommandObjectTraceSchema
306 switch (short_option) {
312 llvm_unreachable(
"Unimplemented option");
322 return llvm::ArrayRef(g_trace_schema_options);
330 "Show the schema of the given trace plugin.",
331 "trace schema <plug-in>. Use the plug-in name "
332 "\"all\" to see all schemas.\n") {
343 if (command.
empty()) {
345 "trace schema cannot be invoked without a plug-in as argument");
349 StringRef plugin_name(command[0].c_str());
350 if (plugin_name ==
"all") {
360 if (Expected<StringRef> schemaOrErr =
367 if (
error.Success()) {
381 "Commands for loading and using processor "
382 "trace information.",
383 "trace [<sub-command-options>]") {
400 return createStringError(inconvertibleErrorCode(),
401 "Process not available.");
403 return createStringError(inconvertibleErrorCode(),
404 "Process must be alive.");
406 if (Expected<TraceSP> trace_sp = process_sp->GetTarget().GetTraceOrCreate())
409 return createStringError(inconvertibleErrorCode(),
410 "Tracing is not supported. %s",
411 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 default version handles argument definitions that have only one argument type,...
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 default version handles argument definitions that have only one argument type,...
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)
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
ExecutionContext m_exe_ctx
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 Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
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