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 //===----------------------------------------------------------------------===//
10 #include "CommandObjectPlugin.h"
11 #include "lldb/Host/Host.h"
12 #include "lldb/Interpreter/CommandInterpreter.h"
13 #include "lldb/Interpreter/CommandReturnObject.h"
16 using namespace lldb_private;
18 class CommandObjectPluginLoad : public CommandObjectParsed {
20 CommandObjectPluginLoad(CommandInterpreter &interpreter)
21 : CommandObjectParsed(interpreter, "plugin load",
22 "Import a dylib that implements an LLDB plugin.",
24 CommandArgumentEntry arg1;
25 CommandArgumentData cmd_arg;
27 // Define the first (and only) variant of this arg.
28 cmd_arg.arg_type = eArgTypeFilename;
29 cmd_arg.arg_repetition = eArgRepeatPlain;
31 // There is only one variant this argument could be; put it into the
33 arg1.push_back(cmd_arg);
35 // Push the data for the first argument into the m_arguments vector.
36 m_arguments.push_back(arg1);
39 ~CommandObjectPluginLoad() override = default;
41 int HandleArgumentCompletion(
42 CompletionRequest &request,
43 OptionElementVector &opt_element_vector) override {
44 CommandCompletions::InvokeCommonCompletionCallbacks(
45 GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
47 return request.GetNumberOfMatches();
51 bool DoExecute(Args &command, CommandReturnObject &result) override {
52 size_t argc = command.GetArgumentCount();
55 result.AppendError("'plugin load' requires one argument");
56 result.SetStatus(eReturnStatusFailed);
62 FileSpec dylib_fspec(command[0].ref);
63 FileSystem::Instance().Resolve(dylib_fspec);
65 if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error))
66 result.SetStatus(eReturnStatusSuccessFinishResult);
68 result.AppendError(error.AsCString());
69 result.SetStatus(eReturnStatusFailed);
72 return result.Succeeded();
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)));
84 CommandObjectPlugin::~CommandObjectPlugin() = default;