xref: /freebsd/contrib/llvm-project/lldb/source/Commands/CommandObjectPlugin.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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 
13 using namespace lldb;
14 using namespace lldb_private;
15 
16 class CommandObjectPluginLoad : public CommandObjectParsed {
17 public:
CommandObjectPluginLoad(CommandInterpreter & interpreter)18   CommandObjectPluginLoad(CommandInterpreter &interpreter)
19       : CommandObjectParsed(interpreter, "plugin load",
20                             "Import a dylib that implements an LLDB plugin.",
21                             nullptr) {
22     AddSimpleArgumentList(eArgTypeFilename);
23   }
24 
25   ~CommandObjectPluginLoad() override = default;
26 
27 protected:
DoExecute(Args & command,CommandReturnObject & result)28   void DoExecute(Args &command, CommandReturnObject &result) override {
29     size_t argc = command.GetArgumentCount();
30 
31     if (argc != 1) {
32       result.AppendError("'plugin load' requires one argument");
33       return;
34     }
35 
36     Status error;
37 
38     FileSpec dylib_fspec(command[0].ref());
39     FileSystem::Instance().Resolve(dylib_fspec);
40 
41     if (GetDebugger().LoadPlugin(dylib_fspec, error))
42       result.SetStatus(eReturnStatusSuccessFinishResult);
43     else {
44       result.AppendError(error.AsCString());
45     }
46   }
47 };
48 
CommandObjectPlugin(CommandInterpreter & interpreter)49 CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
50     : CommandObjectMultiword(interpreter, "plugin",
51                              "Commands for managing LLDB plugins.",
52                              "plugin <subcommand> [<subcommand-options>]") {
53   LoadSubCommand("load",
54                  CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
55 }
56 
57 CommandObjectPlugin::~CommandObjectPlugin() = default;
58