]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Commands/CommandObjectPlugin.cpp
Vendor import of lldb trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / source / Commands / CommandObjectPlugin.cpp
1 //===-- CommandObjectPlugin.cpp ---------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "CommandObjectPlugin.h"
11 #include "lldb/Host/Host.h"
12 #include "lldb/Interpreter/CommandInterpreter.h"
13 #include "lldb/Interpreter/CommandReturnObject.h"
14
15 using namespace lldb;
16 using namespace lldb_private;
17
18 class CommandObjectPluginLoad : public CommandObjectParsed {
19 public:
20   CommandObjectPluginLoad(CommandInterpreter &interpreter)
21       : CommandObjectParsed(interpreter, "plugin load",
22                             "Import a dylib that implements an LLDB plugin.",
23                             nullptr) {
24     CommandArgumentEntry arg1;
25     CommandArgumentData cmd_arg;
26
27     // Define the first (and only) variant of this arg.
28     cmd_arg.arg_type = eArgTypeFilename;
29     cmd_arg.arg_repetition = eArgRepeatPlain;
30
31     // There is only one variant this argument could be; put it into the
32     // argument entry.
33     arg1.push_back(cmd_arg);
34
35     // Push the data for the first argument into the m_arguments vector.
36     m_arguments.push_back(arg1);
37   }
38
39   ~CommandObjectPluginLoad() override = default;
40
41   int HandleArgumentCompletion(
42       CompletionRequest &request,
43       OptionElementVector &opt_element_vector) override {
44     CommandCompletions::InvokeCommonCompletionCallbacks(
45         GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
46         request, nullptr);
47     return request.GetNumberOfMatches();
48   }
49
50 protected:
51   bool DoExecute(Args &command, CommandReturnObject &result) override {
52     size_t argc = command.GetArgumentCount();
53
54     if (argc != 1) {
55       result.AppendError("'plugin load' requires one argument");
56       result.SetStatus(eReturnStatusFailed);
57       return false;
58     }
59
60     Status error;
61
62     FileSpec dylib_fspec(command[0].ref);
63     FileSystem::Instance().Resolve(dylib_fspec);
64
65     if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error))
66       result.SetStatus(eReturnStatusSuccessFinishResult);
67     else {
68       result.AppendError(error.AsCString());
69       result.SetStatus(eReturnStatusFailed);
70     }
71
72     return result.Succeeded();
73   }
74 };
75
76 CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
77     : CommandObjectMultiword(interpreter, "plugin",
78                              "Commands for managing LLDB plugins.",
79                              "plugin <subcommand> [<subcommand-options>]") {
80   LoadSubCommand("load",
81                  CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
82 }
83
84 CommandObjectPlugin::~CommandObjectPlugin() = default;