1 //===-- CommandObjectPlugin.cpp ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // Other libraries and framework includes
14 #include "CommandObjectPlugin.h"
15 #include "lldb/Host/Host.h"
16 #include "lldb/Interpreter/CommandInterpreter.h"
17 #include "lldb/Interpreter/CommandReturnObject.h"
20 using namespace lldb_private;
22 class CommandObjectPluginLoad : public CommandObjectParsed {
24 CommandObjectPluginLoad(CommandInterpreter &interpreter)
25 : CommandObjectParsed(interpreter, "plugin load",
26 "Import a dylib that implements an LLDB plugin.",
28 CommandArgumentEntry arg1;
29 CommandArgumentData cmd_arg;
31 // Define the first (and only) variant of this arg.
32 cmd_arg.arg_type = eArgTypeFilename;
33 cmd_arg.arg_repetition = eArgRepeatPlain;
35 // There is only one variant this argument could be; put it into the
37 arg1.push_back(cmd_arg);
39 // Push the data for the first argument into the m_arguments vector.
40 m_arguments.push_back(arg1);
43 ~CommandObjectPluginLoad() override = default;
45 int HandleArgumentCompletion(
46 CompletionRequest &request,
47 OptionElementVector &opt_element_vector) override {
48 CommandCompletions::InvokeCommonCompletionCallbacks(
49 GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
51 return request.GetNumberOfMatches();
55 bool DoExecute(Args &command, CommandReturnObject &result) override {
56 size_t argc = command.GetArgumentCount();
59 result.AppendError("'plugin load' requires one argument");
60 result.SetStatus(eReturnStatusFailed);
66 FileSpec dylib_fspec(command[0].ref, true);
68 if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error))
69 result.SetStatus(eReturnStatusSuccessFinishResult);
71 result.AppendError(error.AsCString());
72 result.SetStatus(eReturnStatusFailed);
75 return result.Succeeded();
79 CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
80 : CommandObjectMultiword(interpreter, "plugin",
81 "Commands for managing LLDB plugins.",
82 "plugin <subcommand> [<subcommand-options>]") {
83 LoadSubCommand("load",
84 CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
87 CommandObjectPlugin::~CommandObjectPlugin() = default;