1cfca06d7SDimitry Andric //===-- CommandObjectPlugin.cpp -------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste
9f034231aSEd Maste #include "CommandObjectPlugin.h"
10f034231aSEd Maste #include "lldb/Interpreter/CommandInterpreter.h"
11f034231aSEd Maste #include "lldb/Interpreter/CommandReturnObject.h"
12f034231aSEd Maste
13f034231aSEd Maste using namespace lldb;
14f034231aSEd Maste using namespace lldb_private;
15f034231aSEd Maste
1614f1b3e8SDimitry Andric class CommandObjectPluginLoad : public CommandObjectParsed {
17f034231aSEd Maste public:
CommandObjectPluginLoad(CommandInterpreter & interpreter)1814f1b3e8SDimitry Andric CommandObjectPluginLoad(CommandInterpreter &interpreter)
1914f1b3e8SDimitry Andric : CommandObjectParsed(interpreter, "plugin load",
20f034231aSEd Maste "Import a dylib that implements an LLDB plugin.",
2114f1b3e8SDimitry Andric nullptr) {
22ac9a064cSDimitry Andric AddSimpleArgumentList(eArgTypeFilename);
23f034231aSEd Maste }
24f034231aSEd Maste
25f3fbd1c0SDimitry Andric ~CommandObjectPluginLoad() override = default;
26f034231aSEd Maste
27f034231aSEd Maste protected:
DoExecute(Args & command,CommandReturnObject & result)28b1c73532SDimitry Andric void DoExecute(Args &command, CommandReturnObject &result) override {
29f034231aSEd Maste size_t argc = command.GetArgumentCount();
30f034231aSEd Maste
3114f1b3e8SDimitry Andric if (argc != 1) {
32f034231aSEd Maste result.AppendError("'plugin load' requires one argument");
33b1c73532SDimitry Andric return;
34f034231aSEd Maste }
35f034231aSEd Maste
36b76161e4SDimitry Andric Status error;
37f034231aSEd Maste
38ead24645SDimitry Andric FileSpec dylib_fspec(command[0].ref());
3994994d37SDimitry Andric FileSystem::Instance().Resolve(dylib_fspec);
40f034231aSEd Maste
415f29bb8aSDimitry Andric if (GetDebugger().LoadPlugin(dylib_fspec, error))
42f034231aSEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
4314f1b3e8SDimitry Andric else {
44f034231aSEd Maste result.AppendError(error.AsCString());
45f034231aSEd Maste }
46f034231aSEd Maste }
47f034231aSEd Maste };
48f034231aSEd Maste
CommandObjectPlugin(CommandInterpreter & interpreter)49f3fbd1c0SDimitry Andric CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
5014f1b3e8SDimitry Andric : CommandObjectMultiword(interpreter, "plugin",
5114f1b3e8SDimitry Andric "Commands for managing LLDB plugins.",
5214f1b3e8SDimitry Andric "plugin <subcommand> [<subcommand-options>]") {
5314f1b3e8SDimitry Andric LoadSubCommand("load",
5414f1b3e8SDimitry Andric CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
55f034231aSEd Maste }
56f034231aSEd Maste
57f3fbd1c0SDimitry Andric CommandObjectPlugin::~CommandObjectPlugin() = default;
58