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) {
22*0fca6ea1SDimitry Andric AddSimpleArgumentList(eArgTypeFilename);
230b57cec5SDimitry Andric }
240b57cec5SDimitry Andric
250b57cec5SDimitry Andric ~CommandObjectPluginLoad() override = default;
260b57cec5SDimitry Andric
270b57cec5SDimitry Andric protected:
DoExecute(Args & command,CommandReturnObject & result)285f757f3fSDimitry Andric void DoExecute(Args &command, CommandReturnObject &result) override {
290b57cec5SDimitry Andric size_t argc = command.GetArgumentCount();
300b57cec5SDimitry Andric
310b57cec5SDimitry Andric if (argc != 1) {
320b57cec5SDimitry Andric result.AppendError("'plugin load' requires one argument");
335f757f3fSDimitry Andric return;
340b57cec5SDimitry Andric }
350b57cec5SDimitry Andric
360b57cec5SDimitry Andric Status error;
370b57cec5SDimitry Andric
389dba64beSDimitry Andric FileSpec dylib_fspec(command[0].ref());
390b57cec5SDimitry Andric FileSystem::Instance().Resolve(dylib_fspec);
400b57cec5SDimitry Andric
410b57cec5SDimitry Andric if (GetDebugger().LoadPlugin(dylib_fspec, error))
420b57cec5SDimitry Andric result.SetStatus(eReturnStatusSuccessFinishResult);
430b57cec5SDimitry Andric else {
440b57cec5SDimitry Andric result.AppendError(error.AsCString());
450b57cec5SDimitry Andric }
460b57cec5SDimitry Andric }
470b57cec5SDimitry Andric };
480b57cec5SDimitry Andric
CommandObjectPlugin(CommandInterpreter & interpreter)490b57cec5SDimitry Andric CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
500b57cec5SDimitry Andric : CommandObjectMultiword(interpreter, "plugin",
510b57cec5SDimitry Andric "Commands for managing LLDB plugins.",
520b57cec5SDimitry Andric "plugin <subcommand> [<subcommand-options>]") {
530b57cec5SDimitry Andric LoadSubCommand("load",
540b57cec5SDimitry Andric CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
550b57cec5SDimitry Andric }
560b57cec5SDimitry Andric
570b57cec5SDimitry Andric CommandObjectPlugin::~CommandObjectPlugin() = default;
58