]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Commands/CommandObjectPlugin.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Commands / CommandObjectPlugin.cpp
1 //===-- CommandObjectPlugin.cpp ---------------------------------*- C++ -*-===//
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/Host/Host.h"
11 #include "lldb/Interpreter/CommandInterpreter.h"
12 #include "lldb/Interpreter/CommandReturnObject.h"
13
14 using namespace lldb;
15 using namespace lldb_private;
16
17 class CommandObjectPluginLoad : public CommandObjectParsed {
18 public:
19   CommandObjectPluginLoad(CommandInterpreter &interpreter)
20       : CommandObjectParsed(interpreter, "plugin load",
21                             "Import a dylib that implements an LLDB plugin.",
22                             nullptr) {
23     CommandArgumentEntry arg1;
24     CommandArgumentData cmd_arg;
25
26     // Define the first (and only) variant of this arg.
27     cmd_arg.arg_type = eArgTypeFilename;
28     cmd_arg.arg_repetition = eArgRepeatPlain;
29
30     // There is only one variant this argument could be; put it into the
31     // argument entry.
32     arg1.push_back(cmd_arg);
33
34     // Push the data for the first argument into the m_arguments vector.
35     m_arguments.push_back(arg1);
36   }
37
38   ~CommandObjectPluginLoad() override = default;
39
40   int HandleArgumentCompletion(
41       CompletionRequest &request,
42       OptionElementVector &opt_element_vector) override {
43     CommandCompletions::InvokeCommonCompletionCallbacks(
44         GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
45         request, nullptr);
46     return request.GetNumberOfMatches();
47   }
48
49 protected:
50   bool DoExecute(Args &command, CommandReturnObject &result) override {
51     size_t argc = command.GetArgumentCount();
52
53     if (argc != 1) {
54       result.AppendError("'plugin load' requires one argument");
55       result.SetStatus(eReturnStatusFailed);
56       return false;
57     }
58
59     Status error;
60
61     FileSpec dylib_fspec(command[0].ref);
62     FileSystem::Instance().Resolve(dylib_fspec);
63
64     if (GetDebugger().LoadPlugin(dylib_fspec, error))
65       result.SetStatus(eReturnStatusSuccessFinishResult);
66     else {
67       result.AppendError(error.AsCString());
68       result.SetStatus(eReturnStatusFailed);
69     }
70
71     return result.Succeeded();
72   }
73 };
74
75 CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
76     : CommandObjectMultiword(interpreter, "plugin",
77                              "Commands for managing LLDB plugins.",
78                              "plugin <subcommand> [<subcommand-options>]") {
79   LoadSubCommand("load",
80                  CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
81 }
82
83 CommandObjectPlugin::~CommandObjectPlugin() = default;