1 //===-- CommandObjectPlugin.cpp ---------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "CommandObjectPlugin.h"
10 #include "lldb/Interpreter/CommandInterpreter.h"
11 #include "lldb/Interpreter/CommandReturnObject.h"
14 using namespace lldb_private
;
16 class CommandObjectPluginLoad
: public CommandObjectParsed
{
18 CommandObjectPluginLoad(CommandInterpreter
&interpreter
)
19 : CommandObjectParsed(interpreter
, "plugin load",
20 "Import a dylib that implements an LLDB plugin.",
22 CommandArgumentEntry arg1
;
23 CommandArgumentData cmd_arg
;
25 // Define the first (and only) variant of this arg.
26 cmd_arg
.arg_type
= eArgTypeFilename
;
27 cmd_arg
.arg_repetition
= eArgRepeatPlain
;
29 // There is only one variant this argument could be; put it into the
31 arg1
.push_back(cmd_arg
);
33 // Push the data for the first argument into the m_arguments vector.
34 m_arguments
.push_back(arg1
);
37 ~CommandObjectPluginLoad() override
= default;
40 HandleArgumentCompletion(CompletionRequest
&request
,
41 OptionElementVector
&opt_element_vector
) override
{
42 CommandCompletions::InvokeCommonCompletionCallbacks(
43 GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion
,
48 bool DoExecute(Args
&command
, CommandReturnObject
&result
) override
{
49 size_t argc
= command
.GetArgumentCount();
52 result
.AppendError("'plugin load' requires one argument");
53 result
.SetStatus(eReturnStatusFailed
);
59 FileSpec
dylib_fspec(command
[0].ref());
60 FileSystem::Instance().Resolve(dylib_fspec
);
62 if (GetDebugger().LoadPlugin(dylib_fspec
, error
))
63 result
.SetStatus(eReturnStatusSuccessFinishResult
);
65 result
.AppendError(error
.AsCString());
66 result
.SetStatus(eReturnStatusFailed
);
69 return result
.Succeeded();
73 CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter
&interpreter
)
74 : CommandObjectMultiword(interpreter
, "plugin",
75 "Commands for managing LLDB plugins.",
76 "plugin <subcommand> [<subcommand-options>]") {
77 LoadSubCommand("load",
78 CommandObjectSP(new CommandObjectPluginLoad(interpreter
)));
81 CommandObjectPlugin::~CommandObjectPlugin() = default;