14bb0738eSEd Maste //===-- CommandObjectPlugin.cpp ---------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include "CommandObjectPlugin.h"
11ac7ddfbfSEd Maste #include "lldb/Host/Host.h"
12ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandInterpreter.h"
13ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandReturnObject.h"
14ac7ddfbfSEd Maste
15ac7ddfbfSEd Maste using namespace lldb;
16ac7ddfbfSEd Maste using namespace lldb_private;
17ac7ddfbfSEd Maste
18435933ddSDimitry Andric class CommandObjectPluginLoad : public CommandObjectParsed {
19ac7ddfbfSEd Maste public:
CommandObjectPluginLoad(CommandInterpreter & interpreter)20435933ddSDimitry Andric CommandObjectPluginLoad(CommandInterpreter &interpreter)
21435933ddSDimitry Andric : CommandObjectParsed(interpreter, "plugin load",
22ac7ddfbfSEd Maste "Import a dylib that implements an LLDB plugin.",
23435933ddSDimitry Andric nullptr) {
24ac7ddfbfSEd Maste CommandArgumentEntry arg1;
25ac7ddfbfSEd Maste CommandArgumentData cmd_arg;
26ac7ddfbfSEd Maste
27ac7ddfbfSEd Maste // Define the first (and only) variant of this arg.
28ac7ddfbfSEd Maste cmd_arg.arg_type = eArgTypeFilename;
29ac7ddfbfSEd Maste cmd_arg.arg_repetition = eArgRepeatPlain;
30ac7ddfbfSEd Maste
31435933ddSDimitry Andric // There is only one variant this argument could be; put it into the
32435933ddSDimitry Andric // argument entry.
33ac7ddfbfSEd Maste arg1.push_back(cmd_arg);
34ac7ddfbfSEd Maste
35ac7ddfbfSEd Maste // Push the data for the first argument into the m_arguments vector.
36ac7ddfbfSEd Maste m_arguments.push_back(arg1);
37ac7ddfbfSEd Maste }
38ac7ddfbfSEd Maste
394bb0738eSEd Maste ~CommandObjectPluginLoad() override = default;
40ac7ddfbfSEd Maste
HandleArgumentCompletion(CompletionRequest & request,OptionElementVector & opt_element_vector)414ba319b5SDimitry Andric int HandleArgumentCompletion(
424ba319b5SDimitry Andric CompletionRequest &request,
434ba319b5SDimitry Andric OptionElementVector &opt_element_vector) override {
44435933ddSDimitry Andric CommandCompletions::InvokeCommonCompletionCallbacks(
45435933ddSDimitry Andric GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
464ba319b5SDimitry Andric request, nullptr);
474ba319b5SDimitry Andric return request.GetNumberOfMatches();
48ac7ddfbfSEd Maste }
49ac7ddfbfSEd Maste
50ac7ddfbfSEd Maste protected:
DoExecute(Args & command,CommandReturnObject & result)51435933ddSDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override {
52ac7ddfbfSEd Maste size_t argc = command.GetArgumentCount();
53ac7ddfbfSEd Maste
54435933ddSDimitry Andric if (argc != 1) {
55ac7ddfbfSEd Maste result.AppendError("'plugin load' requires one argument");
56ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
57ac7ddfbfSEd Maste return false;
58ac7ddfbfSEd Maste }
59ac7ddfbfSEd Maste
605517e702SDimitry Andric Status error;
61ac7ddfbfSEd Maste
62*b5893f02SDimitry Andric FileSpec dylib_fspec(command[0].ref);
63*b5893f02SDimitry Andric FileSystem::Instance().Resolve(dylib_fspec);
64ac7ddfbfSEd Maste
65ac7ddfbfSEd Maste if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error))
66ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
67435933ddSDimitry Andric else {
68ac7ddfbfSEd Maste result.AppendError(error.AsCString());
69ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
70ac7ddfbfSEd Maste }
71ac7ddfbfSEd Maste
72ac7ddfbfSEd Maste return result.Succeeded();
73ac7ddfbfSEd Maste }
74ac7ddfbfSEd Maste };
75ac7ddfbfSEd Maste
CommandObjectPlugin(CommandInterpreter & interpreter)764bb0738eSEd Maste CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
77435933ddSDimitry Andric : CommandObjectMultiword(interpreter, "plugin",
78435933ddSDimitry Andric "Commands for managing LLDB plugins.",
79435933ddSDimitry Andric "plugin <subcommand> [<subcommand-options>]") {
80435933ddSDimitry Andric LoadSubCommand("load",
81435933ddSDimitry Andric CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
82ac7ddfbfSEd Maste }
83ac7ddfbfSEd Maste
844bb0738eSEd Maste CommandObjectPlugin::~CommandObjectPlugin() = default;
85