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
49 const int short_option = m_getopt_table[option_idx].val;
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) {
93 m_arguments.push_back({bundle_dir});
99 CommandCompletions::InvokeCommonCompletionCallbacks(
100 GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
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());
115 FileSystem::Instance().Resolve(bundle_dir);
117 ProcessSP process_sp = m_exe_ctx.GetProcessSP();
119 TraceSP trace_sp = process_sp->GetTarget().GetTrace();
121 if (llvm::Expected<FileSpec> desc_file =
122 trace_sp->SaveToDisk(bundle_dir, m_options.m_compact)) {
124 "Trace bundle description file written to: {0}", *desc_file);
137 #define LLDB_OPTIONS_trace_load
138 #include "CommandOptions.inc"
140 #pragma mark CommandObjectTraceLoad
153 const int short_option = m_getopt_table[option_idx].val;
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>") {
183 m_arguments.push_back({session_file_arg});
189 CommandCompletions::InvokeCommonCompletionCallbacks(
190 GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
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 =
209 Trace::LoadPostMortemTraceFromFile(GetDebugger(),
210 trace_description_file);
218 if (m_options.m_verbose) {
220 trace_or_err.get()->GetPluginName());
231 #define LLDB_OPTIONS_trace_dump
232 #include "CommandOptions.inc"
234 #pragma mark CommandObjectTraceDump
247 const int short_option = m_getopt_table[option_idx].val;
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
312 const int short_option = m_getopt_table[option_idx].val;
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") {
342 m_arguments.push_back({plugin_arg});
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") {
362 StringRef schema = PluginManager::GetTraceSchema(index++);
369 if (Expected<StringRef> schemaOrErr =
370 Trace::FindPluginSchema(plugin_name))
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());