15ffd83dbSDimitry Andric //===-- CommandObjectPlugin.cpp -------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "CommandObjectPlugin.h"
100b57cec5SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h"
110b57cec5SDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h"
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric using namespace lldb;
140b57cec5SDimitry Andric using namespace lldb_private;
150b57cec5SDimitry Andric
160b57cec5SDimitry Andric class CommandObjectPluginLoad : public CommandObjectParsed {
170b57cec5SDimitry Andric public:
CommandObjectPluginLoad(CommandInterpreter & interpreter)180b57cec5SDimitry Andric CommandObjectPluginLoad(CommandInterpreter &interpreter)
190b57cec5SDimitry Andric : CommandObjectParsed(interpreter, "plugin load",
200b57cec5SDimitry Andric "Import a dylib that implements an LLDB plugin.",
210b57cec5SDimitry Andric nullptr) {
220b57cec5SDimitry Andric CommandArgumentEntry arg1;
230b57cec5SDimitry Andric CommandArgumentData cmd_arg;
240b57cec5SDimitry Andric
250b57cec5SDimitry Andric // Define the first (and only) variant of this arg.
260b57cec5SDimitry Andric cmd_arg.arg_type = eArgTypeFilename;
270b57cec5SDimitry Andric cmd_arg.arg_repetition = eArgRepeatPlain;
280b57cec5SDimitry Andric
290b57cec5SDimitry Andric // There is only one variant this argument could be; put it into the
300b57cec5SDimitry Andric // argument entry.
310b57cec5SDimitry Andric arg1.push_back(cmd_arg);
320b57cec5SDimitry Andric
330b57cec5SDimitry Andric // Push the data for the first argument into the m_arguments vector.
340b57cec5SDimitry Andric m_arguments.push_back(arg1);
350b57cec5SDimitry Andric }
360b57cec5SDimitry Andric
370b57cec5SDimitry Andric ~CommandObjectPluginLoad() override = default;
380b57cec5SDimitry Andric
399dba64beSDimitry Andric void
HandleArgumentCompletion(CompletionRequest & request,OptionElementVector & opt_element_vector)409dba64beSDimitry Andric HandleArgumentCompletion(CompletionRequest &request,
410b57cec5SDimitry Andric OptionElementVector &opt_element_vector) override {
42fe013be4SDimitry Andric lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
43fe013be4SDimitry Andric GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
440b57cec5SDimitry Andric }
450b57cec5SDimitry Andric
460b57cec5SDimitry Andric protected:
DoExecute(Args & command,CommandReturnObject & result)47*c9157d92SDimitry Andric void DoExecute(Args &command, CommandReturnObject &result) override {
480b57cec5SDimitry Andric size_t argc = command.GetArgumentCount();
490b57cec5SDimitry Andric
500b57cec5SDimitry Andric if (argc != 1) {
510b57cec5SDimitry Andric result.AppendError("'plugin load' requires one argument");
52*c9157d92SDimitry Andric return;
530b57cec5SDimitry Andric }
540b57cec5SDimitry Andric
550b57cec5SDimitry Andric Status error;
560b57cec5SDimitry Andric
579dba64beSDimitry Andric FileSpec dylib_fspec(command[0].ref());
580b57cec5SDimitry Andric FileSystem::Instance().Resolve(dylib_fspec);
590b57cec5SDimitry Andric
600b57cec5SDimitry Andric if (GetDebugger().LoadPlugin(dylib_fspec, error))
610b57cec5SDimitry Andric result.SetStatus(eReturnStatusSuccessFinishResult);
620b57cec5SDimitry Andric else {
630b57cec5SDimitry Andric result.AppendError(error.AsCString());
640b57cec5SDimitry Andric }
650b57cec5SDimitry Andric }
660b57cec5SDimitry Andric };
670b57cec5SDimitry Andric
CommandObjectPlugin(CommandInterpreter & interpreter)680b57cec5SDimitry Andric CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
690b57cec5SDimitry Andric : CommandObjectMultiword(interpreter, "plugin",
700b57cec5SDimitry Andric "Commands for managing LLDB plugins.",
710b57cec5SDimitry Andric "plugin <subcommand> [<subcommand-options>]") {
720b57cec5SDimitry Andric LoadSubCommand("load",
730b57cec5SDimitry Andric CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
740b57cec5SDimitry Andric }
750b57cec5SDimitry Andric
760b57cec5SDimitry Andric CommandObjectPlugin::~CommandObjectPlugin() = default;
77