2020-01-24 08:23:27 +01:00
|
|
|
//===-- CommandObjectPlugin.cpp -------------------------------------------===//
|
2012-09-28 23:57:51 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-09-28 23:57:51 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "CommandObjectPlugin.h"
|
|
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
|
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
class CommandObjectPluginLoad : public CommandObjectParsed {
|
|
|
|
|
public:
|
|
|
|
|
CommandObjectPluginLoad(CommandInterpreter &interpreter)
|
2016-02-20 00:58:29 +00:00
|
|
|
: CommandObjectParsed(interpreter, "plugin load",
|
|
|
|
|
"Import a dylib that implements an LLDB plugin.",
|
|
|
|
|
nullptr) {
|
2012-09-28 23:57:51 +00:00
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
|
CommandArgumentData cmd_arg;
|
2016-02-20 00:58:29 +00:00
|
|
|
|
|
|
|
|
// Define the first (and only) variant of this arg.
|
2012-09-28 23:57:51 +00:00
|
|
|
cmd_arg.arg_type = eArgTypeFilename;
|
2016-02-20 00:58:29 +00:00
|
|
|
cmd_arg.arg_repetition = eArgRepeatPlain;
|
|
|
|
|
|
2012-09-28 23:57:51 +00:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
|
// argument entry.
|
|
|
|
|
arg1.push_back(cmd_arg);
|
2016-08-11 23:51:28 +00:00
|
|
|
|
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
2012-09-28 23:57:51 +00:00
|
|
|
m_arguments.push_back(arg1);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-11 23:51:28 +00:00
|
|
|
~CommandObjectPluginLoad() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-08-22 07:41:23 +00:00
|
|
|
void
|
|
|
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
|
|
|
OptionElementVector &opt_element_vector) override {
|
2016-08-11 23:51:28 +00:00
|
|
|
CommandCompletions::InvokeCommonCompletionCallbacks(
|
2016-02-20 00:58:29 +00:00
|
|
|
GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
|
2018-07-13 18:28:14 +00:00
|
|
|
request, nullptr);
|
2012-09-28 23:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2015-10-07 16:56:17 +00:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2012-09-28 23:57:51 +00:00
|
|
|
size_t argc = command.GetArgumentCount();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-09-28 23:57:51 +00:00
|
|
|
if (argc != 1) {
|
|
|
|
|
result.AppendError("'plugin load' requires one argument");
|
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-09-13 11:26:48 +00:00
|
|
|
FileSpec dylib_fspec(command[0].ref());
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSystem::Instance().Resolve(dylib_fspec);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-04-27 06:19:42 +00:00
|
|
|
if (GetDebugger().LoadPlugin(dylib_fspec, error))
|
2012-09-28 23:57:51 +00:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
2016-09-06 20:57:50 +00:00
|
|
|
else {
|
2013-04-24 21:29:08 +00:00
|
|
|
result.AppendError(error.AsCString());
|
2012-09-28 23:57:51 +00:00
|
|
|
result.SetStatus(eReturnStatusFailed);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-28 23:57:51 +00:00
|
|
|
return result.Succeeded();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-09-28 23:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
2016-07-14 22:03:10 +00:00
|
|
|
CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectMultiword(interpreter, "plugin",
|
|
|
|
|
"Commands for managing LLDB plugins.",
|
|
|
|
|
"plugin <subcommand> [<subcommand-options>]") {
|
2012-09-28 23:57:51 +00:00
|
|
|
LoadSubCommand("load",
|
|
|
|
|
CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-02-20 00:58:29 +00:00
|
|
|
CommandObjectPlugin::~CommandObjectPlugin() = default;
|