[mlir][int-range] Limit xor int range inference to i1 (#116968)
[llvm-project.git] / lldb / source / Commands / CommandObjectDiagnostics.cpp
blobac87f869f01272e1cba2199c869cd0f1897e5db4
1 //===-- CommandObjectDiagnostics.cpp --------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "CommandObjectDiagnostics.h"
10 #include "lldb/Host/OptionParser.h"
11 #include "lldb/Interpreter/CommandOptionArgumentTable.h"
12 #include "lldb/Interpreter/CommandReturnObject.h"
13 #include "lldb/Interpreter/OptionArgParser.h"
14 #include "lldb/Interpreter/OptionValueEnumeration.h"
15 #include "lldb/Interpreter/OptionValueUInt64.h"
16 #include "lldb/Interpreter/Options.h"
17 #include "lldb/Utility/Diagnostics.h"
19 using namespace lldb;
20 using namespace lldb_private;
22 #define LLDB_OPTIONS_diagnostics_dump
23 #include "CommandOptions.inc"
25 class CommandObjectDiagnosticsDump : public CommandObjectParsed {
26 public:
27 // Constructors and Destructors
28 CommandObjectDiagnosticsDump(CommandInterpreter &interpreter)
29 : CommandObjectParsed(interpreter, "diagnostics dump",
30 "Dump diagnostics to disk", nullptr) {}
32 ~CommandObjectDiagnosticsDump() override = default;
34 class CommandOptions : public Options {
35 public:
36 CommandOptions() = default;
38 ~CommandOptions() override = default;
40 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
41 ExecutionContext *execution_context) override {
42 Status error;
43 const int short_option = m_getopt_table[option_idx].val;
45 switch (short_option) {
46 case 'd':
47 directory.SetDirectory(option_arg);
48 break;
49 default:
50 llvm_unreachable("Unimplemented option");
52 return error;
55 void OptionParsingStarting(ExecutionContext *execution_context) override {
56 directory.Clear();
59 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
60 return llvm::ArrayRef(g_diagnostics_dump_options);
63 FileSpec directory;
66 Options *GetOptions() override { return &m_options; }
68 protected:
69 llvm::Expected<FileSpec> GetDirectory() {
70 if (m_options.directory) {
71 auto ec =
72 llvm::sys::fs::create_directories(m_options.directory.GetPath());
73 if (ec)
74 return llvm::errorCodeToError(ec);
75 return m_options.directory;
77 return Diagnostics::CreateUniqueDirectory();
80 void DoExecute(Args &args, CommandReturnObject &result) override {
81 llvm::Expected<FileSpec> directory = GetDirectory();
83 if (!directory) {
84 result.AppendError(llvm::toString(directory.takeError()));
85 return;
88 llvm::Error error = Diagnostics::Instance().Create(*directory);
89 if (error) {
90 result.AppendErrorWithFormat("failed to write diagnostics to %s",
91 directory->GetPath().c_str());
92 result.AppendError(llvm::toString(std::move(error)));
93 return;
96 result.GetOutputStream() << "diagnostics written to " << *directory << '\n';
98 result.SetStatus(eReturnStatusSuccessFinishResult);
99 return;
102 CommandOptions m_options;
105 CommandObjectDiagnostics::CommandObjectDiagnostics(
106 CommandInterpreter &interpreter)
107 : CommandObjectMultiword(interpreter, "diagnostics",
108 "Commands controlling LLDB diagnostics.",
109 "diagnostics <subcommand> [<command-options>]") {
110 LoadSubCommand(
111 "dump", CommandObjectSP(new CommandObjectDiagnosticsDump(interpreter)));
114 CommandObjectDiagnostics::~CommandObjectDiagnostics() = default;