LLDB  mainline
CommandObjectPlugin.cpp
Go to the documentation of this file.
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"
12 
13 using namespace lldb;
14 using namespace lldb_private;
15 
17 public:
19  : CommandObjectParsed(interpreter, "plugin load",
20  "Import a dylib that implements an LLDB plugin.",
21  nullptr) {
23  CommandArgumentData cmd_arg;
24 
25  // Define the first (and only) variant of this arg.
26  cmd_arg.arg_type = eArgTypeFilename;
28 
29  // There is only one variant this argument could be; put it into the
30  // argument entry.
31  arg1.push_back(cmd_arg);
32 
33  // Push the data for the first argument into the m_arguments vector.
34  m_arguments.push_back(arg1);
35  }
36 
37  ~CommandObjectPluginLoad() override = default;
38 
39  void
41  OptionElementVector &opt_element_vector) override {
42  CommandCompletions::InvokeCommonCompletionCallbacks(
43  GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
44  request, nullptr);
45  }
46 
47 protected:
48  bool DoExecute(Args &command, CommandReturnObject &result) override {
49  size_t argc = command.GetArgumentCount();
50 
51  if (argc != 1) {
52  result.AppendError("'plugin load' requires one argument");
53  return false;
54  }
55 
56  Status error;
57 
58  FileSpec dylib_fspec(command[0].ref());
59  FileSystem::Instance().Resolve(dylib_fspec);
60 
61  if (GetDebugger().LoadPlugin(dylib_fspec, error))
63  else {
64  result.AppendError(error.AsCString());
65  }
66 
67  return result.Succeeded();
68  }
69 };
70 
71 CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
72  : CommandObjectMultiword(interpreter, "plugin",
73  "Commands for managing LLDB plugins.",
74  "plugin <subcommand> [<subcommand-options>]") {
75  LoadSubCommand("load",
76  CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
77 }
78 
lldb_private::CommandObjectParsed
Definition: CommandObject.h:394
lldb_private::eArgRepeatPlain
@ eArgRepeatPlain
Definition: lldb-private-enumerations.h:95
lldb_private::CommandObject::CommandArgumentData
Definition: CommandObject.h:89
CommandObjectPluginLoad::CommandObjectPluginLoad
CommandObjectPluginLoad(CommandInterpreter &interpreter)
Definition: CommandObjectPlugin.cpp:18
lldb::eArgTypeFilename
@ eArgTypeFilename
Definition: lldb-enumerations.h:537
lldb_private::CommandObject::CommandArgumentData::arg_repetition
ArgumentRepetitionType arg_repetition
Definition: CommandObject.h:92
lldb_private::Args
Definition: Args.h:33
CommandObjectPluginLoad
Definition: CommandObjectPlugin.cpp:16
CommandReturnObject.h
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::CommandObjectMultiword
Definition: CommandObjectMultiword.h:19
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
CommandObjectPluginLoad::HandleArgumentCompletion
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
Definition: CommandObjectPlugin.cpp:40
CommandObjectPlugin.h
lldb_private::CommandObjectMultiword::LoadSubCommand
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
Definition: CommandObjectMultiword.cpp:80
lldb_private::CommandReturnObject::SetStatus
void SetStatus(lldb::ReturnStatus status)
Definition: CommandReturnObject.cpp:121
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:214
lldb_private::CommandObjectPlugin::~CommandObjectPlugin
~CommandObjectPlugin() override
lldb_private::CommandObject::CommandArgumentData::arg_type
lldb::CommandArgumentType arg_type
Definition: CommandObject.h:91
lldb_private::OptionElementVector
std::vector< OptionArgElement > OptionElementVector
Definition: Options.h:42
LoadPlugin
static llvm::sys::DynamicLibrary LoadPlugin(const lldb::DebuggerSP &debugger_sp, const FileSpec &spec, Status &error)
Definition: SBDebugger.cpp:64
lldb_private::Status
Definition: Status.h:44
lldb_private::CommandReturnObject
Definition: CommandReturnObject.h:25
lldb::eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishResult
Definition: lldb-enumerations.h:261
CommandObjectPluginLoad::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: CommandObjectPlugin.cpp:48
lldb_private::CommandReturnObject::Succeeded
bool Succeeded()
Definition: CommandReturnObject.cpp:125
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
CommandInterpreter.h
lldb_private::CommandObject::CommandArgumentEntry
std::vector< CommandArgumentData > CommandArgumentEntry
Definition: CommandObject.h:105
lldb_private::CommandReturnObject::AppendError
void void AppendError(llvm::StringRef in_string)
Definition: CommandReturnObject.cpp:100
lldb_private::Args::GetArgumentCount
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition: Args.h:118
lldb
Definition: SBAddress.h:15
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100