21#include "llvm/Support/JSON.h"
26#define LLDB_OPTIONS_diagnostics_dump
27#include "CommandOptions.inc"
29#define LLDB_OPTIONS_diagnostics_report
30#include "CommandOptions.inc"
37 "Dump diagnostics to disk", nullptr) {}
52 switch (short_option) {
57 llvm_unreachable(
"Unimplemented option");
67 return llvm::ArrayRef(g_diagnostics_dump_options);
79 llvm::sys::fs::create_directories(
m_options.directory.GetPath());
81 return llvm::errorCodeToError(ec);
91 result.
AppendError(llvm::toString(directory.takeError()));
96 llvm::Expected<Diagnostics::Report> report =
100 directory->GetPath().c_str());
101 result.
AppendError(llvm::toString(report.takeError()));
119 interpreter,
"diagnostics report",
120 "Assemble a diagnostics bundle and file it as a bug report.",
136 switch (short_option) {
144 plugin = option_arg.str();
147 llvm_unreachable(
"Unimplemented option");
159 return llvm::ArrayRef(g_diagnostics_report_options);
173 llvm::sys::fs::create_directories(
m_options.directory.GetPath());
175 return llvm::errorCodeToError(ec);
184 result.
AppendError(llvm::toString(directory.takeError()));
188 llvm::Expected<Diagnostics::Report> report =
191 result.
AppendError(llvm::toString(report.takeError()));
196 out <<
"Bug report written to " << directory->GetPath() <<
"\n";
197 if (!report->attachments.files.empty()) {
198 out <<
"Attach the following files to the issue:\n";
199 for (
const std::string &file : report->attachments.files)
200 out <<
" [ ] " << file <<
"\n";
202 result.
AppendWarning(
"the report may contain file paths, command history "
203 "and program data. Review it before attaching it to a "
212 std::unique_ptr<BugReporter> reporter =
219 result.
AppendError(
"no bug reporter is available");
222 if (llvm::Error
error = reporter->File(*report)) {
227 out <<
"Opened a pre-filled " << reporter->GetPluginName() <<
" report.\n";
237 "Commands controlling LLDB diagnostics.",
238 "diagnostics <subcommand> [<command-options>]") {
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.
Options * GetOptions() override
llvm::Expected< FileSpec > GetDirectory()
void DoExecute(Args &args, CommandReturnObject &result) override
~CommandObjectDiagnosticsDump() override=default
CommandObjectDiagnosticsDump(CommandInterpreter &interpreter)
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
~CommandOptions() override=default
CommandObjectDiagnosticsReport(CommandInterpreter &interpreter)
void DoExecute(Args &args, CommandReturnObject &result) override
Options * GetOptions() override
~CommandObjectDiagnosticsReport() override=default
llvm::Expected< FileSpec > GetDirectory()
A command line argument class.
CommandObjectDiagnostics(CommandInterpreter &interpreter)
~CommandObjectDiagnostics() override
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
CommandObjectMultiword(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
friend class CommandInterpreter
CommandObjectParsed(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
ExecutionContext m_exe_ctx
void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void AppendWarning(llvm::StringRef in_string)
Stream & GetOutputStream()
static llvm::Expected< FileSpec > CreateUniqueDirectory()
Create a unique diagnostic directory.
llvm::Expected< Report > Collect(Debugger &debugger, const ExecutionContext &exe_ctx, const FileSpec &dir)
Collect a full diagnostics bundle into dir and return its report.
static Diagnostics & Instance()
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A command line option parsing protocol class.
std::vector< Option > m_getopt_table
static std::unique_ptr< BugReporter > CreateBugReporterInstance(llvm::StringRef name={})
A stream class that can stream formatted output to a file.
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
A class that represents a running process on the host machine.
llvm::json::Value toJSON(const Diagnostics::Report &report)
Render a diagnostics report as JSON, for diagnostics dump's terminal output.
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
@ eReturnStatusSuccessFinishResult