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