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/Host/Host.h"
11 #include "lldb/Interpreter/CommandInterpreter.h"
12 #include "lldb/Interpreter/CommandReturnObject.h"
15 using namespace lldb_private;
17 class CommandObjectPluginLoad : public CommandObjectParsed {
19 CommandObjectPluginLoad(CommandInterpreter &interpreter)
20 : CommandObjectParsed(interpreter, "plugin load",
21 "Import a dylib that implements an LLDB plugin.",
23 CommandArgumentEntry arg1;
24 CommandArgumentData cmd_arg;
26 // Define the first (and only) variant of this arg.
27 cmd_arg.arg_type = eArgTypeFilename;
28 cmd_arg.arg_repetition = eArgRepeatPlain;
30 // There is only one variant this argument could be; put it into the
32 arg1.push_back(cmd_arg);
34 // Push the data for the first argument into the m_arguments vector.
35 m_arguments.push_back(arg1);
38 ~CommandObjectPluginLoad() override = default;
40 int HandleArgumentCompletion(
41 CompletionRequest &request,
42 OptionElementVector &opt_element_vector) override {
43 CommandCompletions::InvokeCommonCompletionCallbacks(
44 GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
46 return request.GetNumberOfMatches();
50 bool DoExecute(Args &command, CommandReturnObject &result) override {
51 size_t argc = command.GetArgumentCount();
54 result.AppendError("'plugin load' requires one argument");
55 result.SetStatus(eReturnStatusFailed);
61 FileSpec dylib_fspec(command[0].ref);
62 FileSystem::Instance().Resolve(dylib_fspec);
64 if (GetDebugger().LoadPlugin(dylib_fspec, error))
65 result.SetStatus(eReturnStatusSuccessFinishResult);
67 result.AppendError(error.AsCString());
68 result.SetStatus(eReturnStatusFailed);
71 return result.Succeeded();
75 CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
76 : CommandObjectMultiword(interpreter, "plugin",
77 "Commands for managing LLDB plugins.",
78 "plugin <subcommand> [<subcommand-options>]") {
79 LoadSubCommand("load",
80 CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
83 CommandObjectPlugin::~CommandObjectPlugin() = default;