11 #include "llvm/Support/JSON.h"
12 #include "llvm/Support/MemoryBuffer.h"
34 #define LLDB_OPTIONS_trace_load
35 #include "CommandOptions.inc"
37 #pragma mark CommandObjectTraceLoad
50 const int short_option = m_getopt_table[option_idx].val;
52 switch (short_option) {
58 llvm_unreachable(
"Unimplemented option");
68 return makeArrayRef(g_trace_load_options);
76 "Load a processor trace session from a JSON file.",
85 if (command.
size() != 1) {
87 "a single path to a JSON file containing a trace session"
92 auto end_with_failure = [&result](
llvm::Error err) ->
bool {
98 FileSpec json_file(command[0].ref());
100 auto buffer_or_error = llvm::MemoryBuffer::getFile(json_file.
GetPath());
101 if (!buffer_or_error) {
102 return end_with_failure(llvm::createStringError(
103 std::errc::invalid_argument,
"could not open input file: %s - %s.",
105 buffer_or_error.getError().message().c_str()));
108 llvm::Expected<json::Value> session_file =
109 json::parse(buffer_or_error.get()->getBuffer().str());
111 return end_with_failure(session_file.takeError());
113 if (Expected<lldb::TraceSP> traceOrErr =
114 Trace::FindPluginForPostMortemProcess(
115 GetDebugger(), *session_file,
117 lldb::TraceSP trace_sp = traceOrErr.get();
118 if (m_options.m_verbose && trace_sp)
120 trace_sp->GetPluginName());
122 return end_with_failure(traceOrErr.takeError());
132 #define LLDB_OPTIONS_trace_dump
133 #include "CommandOptions.inc"
135 #pragma mark CommandObjectTraceDump
148 const int short_option = m_getopt_table[option_idx].val;
150 switch (short_option) {
156 llvm_unreachable(
"Unimplemented option");
166 return llvm::makeArrayRef(g_trace_dump_options);
174 "Dump the loaded processor trace data.",
185 if (
error.Success()) {
197 #define LLDB_OPTIONS_trace_schema
198 #include "CommandOptions.inc"
200 #pragma mark CommandObjectTraceSchema
213 const int short_option = m_getopt_table[option_idx].val;
215 switch (short_option) {
221 llvm_unreachable(
"Unimplemented option");
231 return llvm::makeArrayRef(g_trace_schema_options);
239 "Show the schema of the given trace plugin.",
240 "trace schema <plug-in>. Use the plug-in name "
241 "\"all\" to see all schemas.\n") {}
250 if (command.
empty()) {
252 "trace schema cannot be invoked without a plug-in as argument");
256 StringRef plugin_name(command[0].c_str());
257 if (plugin_name ==
"all") {
260 StringRef schema = PluginManager::GetTraceSchema(index++);
267 if (Expected<StringRef> schemaOrErr =
268 Trace::FindPluginSchema(plugin_name))
271 error = schemaOrErr.takeError();
274 if (
error.Success()) {
289 "Commands for loading and using processor "
290 "trace information.",
291 "trace [<sub-command-options>]") {
306 return createStringError(inconvertibleErrorCode(),
307 "Process not available.");
309 return createStringError(inconvertibleErrorCode(),
310 "Process must be alive.");
312 if (Expected<TraceSP> trace_sp = process_sp->GetTarget().GetTraceOrCreate())
315 return createStringError(inconvertibleErrorCode(),
316 "Tracing is not supported. %s",
317 toString(trace_sp.takeError()).c_str());