mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-28 15:26:08 +00:00

[lldb] Part 2 of 2 - Refactor `CommandObject::DoExecute(...)` to return `void` instead of ~~`bool`~~ Justifications: - The code doesn't ultimately apply the `true`/`false` return values. - The methods already pass around a `CommandReturnObject`, typically with a `result` parameter. - Each command return object already contains: - A more precise status - The error code(s) that apply to that status Part 1 refactors the `CommandObject::Execute(...)` method. - See [https://github.com/llvm/llvm-project/pull/69989](https://github.com/llvm/llvm-project/pull/69989) rdar://117378957
77 lines
2.6 KiB
C++
77 lines
2.6 KiB
C++
//===-- CommandObjectPlugin.cpp -------------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#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)
|
|
: CommandObjectParsed(interpreter, "plugin load",
|
|
"Import a dylib that implements an LLDB plugin.",
|
|
nullptr) {
|
|
CommandArgumentEntry arg1;
|
|
CommandArgumentData cmd_arg;
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
cmd_arg.arg_type = eArgTypeFilename;
|
|
cmd_arg.arg_repetition = eArgRepeatPlain;
|
|
|
|
// There is only one variant this argument could be; put it into the
|
|
// argument entry.
|
|
arg1.push_back(cmd_arg);
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
m_arguments.push_back(arg1);
|
|
}
|
|
|
|
~CommandObjectPluginLoad() override = default;
|
|
|
|
void
|
|
HandleArgumentCompletion(CompletionRequest &request,
|
|
OptionElementVector &opt_element_vector) override {
|
|
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
|
|
GetCommandInterpreter(), lldb::eDiskFileCompletion, request, nullptr);
|
|
}
|
|
|
|
protected:
|
|
void DoExecute(Args &command, CommandReturnObject &result) override {
|
|
size_t argc = command.GetArgumentCount();
|
|
|
|
if (argc != 1) {
|
|
result.AppendError("'plugin load' requires one argument");
|
|
return;
|
|
}
|
|
|
|
Status error;
|
|
|
|
FileSpec dylib_fspec(command[0].ref());
|
|
FileSystem::Instance().Resolve(dylib_fspec);
|
|
|
|
if (GetDebugger().LoadPlugin(dylib_fspec, error))
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
else {
|
|
result.AppendError(error.AsCString());
|
|
}
|
|
}
|
|
};
|
|
|
|
CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
|
|
: CommandObjectMultiword(interpreter, "plugin",
|
|
"Commands for managing LLDB plugins.",
|
|
"plugin <subcommand> [<subcommand-options>]") {
|
|
LoadSubCommand("load",
|
|
CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
|
|
}
|
|
|
|
CommandObjectPlugin::~CommandObjectPlugin() = default;
|