LLDB  mainline
CommandObjectPlugin.cpp
Go to the documentation of this file.
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"
13 
14 using namespace lldb;
15 using namespace lldb_private;
16 
18 public:
20  : CommandObjectParsed(interpreter, "plugin load",
21  "Import a dylib that implements an LLDB plugin.",
22  nullptr) {
24  CommandArgumentData cmd_arg;
25 
26  // Define the first (and only) variant of this arg.
27  cmd_arg.arg_type = eArgTypeFilename;
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 
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");
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))
66  else {
67  result.AppendError(error.AsCString());
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 
std::vector< CommandArgumentData > CommandArgumentEntry
A command line argument class.
Definition: Args.h:32
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
static llvm::sys::DynamicLibrary LoadPlugin(const lldb::DebuggerSP &debugger_sp, const FileSpec &spec, Status &error)
Definition: SBDebugger.cpp:99
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition: Args.cpp:254
A file utility class.
Definition: FileSpec.h:55
std::size_t GetNumberOfMatches() const
"lldb/Utility/ArgCompletionRequest.h"
std::vector< OptionArgElement > OptionElementVector
Definition: Options.h:41
CommandObjectPluginLoad(CommandInterpreter &interpreter)
void void AppendError(llvm::StringRef in_string)
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: SBAddress.h:15
int HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:130
void SetStatus(lldb::ReturnStatus status)
An error handling class.
Definition: Status.h:44