1//===-- CommandObjectPlugin.cpp -------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#include "CommandObjectPlugin.h"
10#include "lldb/Interpreter/CommandInterpreter.h"
11#include "lldb/Interpreter/CommandReturnObject.h"
12
13using namespace lldb;
14using namespace lldb_private;
15
16class CommandObjectPluginLoad : public CommandObjectParsed {
17public:
18 CommandObjectPluginLoad(CommandInterpreter &interpreter)
19 : CommandObjectParsed(interpreter, "plugin load",
20 "Import a dylib that implements an LLDB plugin.",
21 nullptr) {
22 CommandArgumentEntry arg1;
23 CommandArgumentData cmd_arg;
24
25 // Define the first (and only) variant of this arg.
26 cmd_arg.arg_type = eArgTypeFilename;
27 cmd_arg.arg_repetition = eArgRepeatPlain;
28
29 // There is only one variant this argument could be; put it into the
30 // argument entry.
31 arg1.push_back(x: cmd_arg);
32
33 // Push the data for the first argument into the m_arguments vector.
34 m_arguments.push_back(x: arg1);
35 }
36
37 ~CommandObjectPluginLoad() override = default;
38
39 void
40 HandleArgumentCompletion(CompletionRequest &request,
41 OptionElementVector &opt_element_vector) override {
42 lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
43 interpreter&: GetCommandInterpreter(), completion_mask: lldb::eDiskFileCompletion, request, searcher: nullptr);
44 }
45
46protected:
47 void DoExecute(Args &command, CommandReturnObject &result) override {
48 size_t argc = command.GetArgumentCount();
49
50 if (argc != 1) {
51 result.AppendError(in_string: "'plugin load' requires one argument");
52 return;
53 }
54
55 Status error;
56
57 FileSpec dylib_fspec(command[0].ref());
58 FileSystem::Instance().Resolve(file_spec&: dylib_fspec);
59
60 if (GetDebugger().LoadPlugin(spec: dylib_fspec, error))
61 result.SetStatus(eReturnStatusSuccessFinishResult);
62 else {
63 result.AppendError(in_string: error.AsCString());
64 }
65 }
66};
67
68CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
69 : CommandObjectMultiword(interpreter, "plugin",
70 "Commands for managing LLDB plugins.",
71 "plugin <subcommand> [<subcommand-options>]") {
72 LoadSubCommand(cmd_name: "load",
73 command_obj: CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
74}
75
76CommandObjectPlugin::~CommandObjectPlugin() = default;
77

source code of lldb/source/Commands/CommandObjectPlugin.cpp