diff options
Diffstat (limited to 'contrib/llvm-project/lldb/source/Commands/CommandObjectTrace.cpp')
-rw-r--r-- | contrib/llvm-project/lldb/source/Commands/CommandObjectTrace.cpp | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/contrib/llvm-project/lldb/source/Commands/CommandObjectTrace.cpp b/contrib/llvm-project/lldb/source/Commands/CommandObjectTrace.cpp index 53f1b0a32e60..17aded9ed2a0 100644 --- a/contrib/llvm-project/lldb/source/Commands/CommandObjectTrace.cpp +++ b/contrib/llvm-project/lldb/source/Commands/CommandObjectTrace.cpp @@ -72,9 +72,13 @@ public: }; CommandObjectTraceLoad(CommandInterpreter &interpreter) - : CommandObjectParsed(interpreter, "trace load", - "Load a processor trace session from a JSON file.", - "trace load") {} + : CommandObjectParsed( + interpreter, "trace load", + "Load a post-mortem processor trace session from a trace bundle.", + "trace load") { + CommandArgumentData session_file_arg{eArgTypePath, eArgRepeatPlain}; + m_arguments.push_back({session_file_arg}); + } ~CommandObjectTraceLoad() override = default; @@ -83,43 +87,27 @@ public: protected: bool DoExecute(Args &command, CommandReturnObject &result) override { if (command.size() != 1) { - result.AppendError( - "a single path to a JSON file containing a trace session" - "is required"); + result.AppendError("a single path to a JSON file containing a the " + "description of the trace bundle is required"); return false; } - auto end_with_failure = [&result](llvm::Error err) -> bool { - result.AppendErrorWithFormat("%s\n", - llvm::toString(std::move(err)).c_str()); - return false; - }; + const FileSpec trace_description_file(command[0].ref()); - FileSpec json_file(command[0].ref()); + llvm::Expected<lldb::TraceSP> trace_or_err = + Trace::LoadPostMortemTraceFromFile(GetDebugger(), + trace_description_file); - auto buffer_or_error = llvm::MemoryBuffer::getFile(json_file.GetPath()); - if (!buffer_or_error) { - return end_with_failure(llvm::createStringError( - std::errc::invalid_argument, "could not open input file: %s - %s.", - json_file.GetPath().c_str(), - buffer_or_error.getError().message().c_str())); + if (!trace_or_err) { + result.AppendErrorWithFormat( + "%s\n", llvm::toString(trace_or_err.takeError()).c_str()); + return false; } - llvm::Expected<json::Value> session_file = - json::parse(buffer_or_error.get()->getBuffer().str()); - if (!session_file) - return end_with_failure(session_file.takeError()); - - if (Expected<lldb::TraceSP> traceOrErr = - Trace::FindPluginForPostMortemProcess( - GetDebugger(), *session_file, - json_file.GetDirectory().AsCString())) { - lldb::TraceSP trace_sp = traceOrErr.get(); - if (m_options.m_verbose && trace_sp) - result.AppendMessageWithFormatv("loading trace with plugin {0}\n", - trace_sp->GetPluginName()); - } else - return end_with_failure(traceOrErr.takeError()); + if (m_options.m_verbose) { + result.AppendMessageWithFormatv("loading trace with plugin {0}\n", + trace_or_err.get()->GetPluginName()); + } result.SetStatus(eReturnStatusSuccessFinishResult); return true; @@ -238,7 +226,10 @@ public: : CommandObjectParsed(interpreter, "trace schema", "Show the schema of the given trace plugin.", "trace schema <plug-in>. Use the plug-in name " - "\"all\" to see all schemas.\n") {} + "\"all\" to see all schemas.\n") { + CommandArgumentData plugin_arg{eArgTypeNone, eArgRepeatPlain}; + m_arguments.push_back({plugin_arg}); + } ~CommandObjectTraceSchema() override = default; |