blob: 13ef6b227c5b92cbacef27bf210c14e074e29b2a [file] [log] [blame]
Eugene Zelenko26cac3a2016-02-20 00:58:29 +00001//===-- CommandObjectPlugin.cpp ---------------------------------*- C++ -*-===//
Enrico Granata21dfcd92012-09-28 23:57:51 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eugene Zelenko26cac3a2016-02-20 00:58:29 +000010// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
Enrico Granata21dfcd92012-09-28 23:57:51 +000014#include "CommandObjectPlugin.h"
Enrico Granata21dfcd92012-09-28 23:57:51 +000015#include "lldb/Host/Host.h"
Enrico Granata21dfcd92012-09-28 23:57:51 +000016#include "lldb/Interpreter/CommandInterpreter.h"
17#include "lldb/Interpreter/CommandReturnObject.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
Kate Stoneb9c1b512016-09-06 20:57:50 +000022class CommandObjectPluginLoad : public CommandObjectParsed {
Enrico Granata21dfcd92012-09-28 23:57:51 +000023public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000024 CommandObjectPluginLoad(CommandInterpreter &interpreter)
25 : CommandObjectParsed(interpreter, "plugin load",
Eugene Zelenko26cac3a2016-02-20 00:58:29 +000026 "Import a dylib that implements an LLDB plugin.",
Kate Stoneb9c1b512016-09-06 20:57:50 +000027 nullptr) {
28 CommandArgumentEntry arg1;
29 CommandArgumentData cmd_arg;
Eugene Zelenko26cac3a2016-02-20 00:58:29 +000030
Kate Stoneb9c1b512016-09-06 20:57:50 +000031 // Define the first (and only) variant of this arg.
32 cmd_arg.arg_type = eArgTypeFilename;
33 cmd_arg.arg_repetition = eArgRepeatPlain;
Eugene Zelenko26cac3a2016-02-20 00:58:29 +000034
Kate Stoneb9c1b512016-09-06 20:57:50 +000035 // There is only one variant this argument could be; put it into the
36 // argument entry.
37 arg1.push_back(cmd_arg);
Todd Fialae1cfbc72016-08-11 23:51:28 +000038
Kate Stoneb9c1b512016-09-06 20:57:50 +000039 // Push the data for the first argument into the m_arguments vector.
40 m_arguments.push_back(arg1);
41 }
42
43 ~CommandObjectPluginLoad() override = default;
44
Raphael Isemann2443bbd2018-07-02 21:29:56 +000045 int HandleArgumentCompletion(
46 CompletionRequest &request,
47 OptionElementVector &opt_element_vector) override {
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 CommandCompletions::InvokeCommonCompletionCallbacks(
49 GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
Raphael Isemanna2e76c02018-07-13 18:28:14 +000050 request, nullptr);
Raphael Isemann1a6d7ab2018-07-27 18:42:46 +000051 return request.GetNumberOfMatches();
Kate Stoneb9c1b512016-09-06 20:57:50 +000052 }
Enrico Granata21dfcd92012-09-28 23:57:51 +000053
54protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +000055 bool DoExecute(Args &command, CommandReturnObject &result) override {
56 size_t argc = command.GetArgumentCount();
57
58 if (argc != 1) {
59 result.AppendError("'plugin load' requires one argument");
60 result.SetStatus(eReturnStatusFailed);
61 return false;
Enrico Granata21dfcd92012-09-28 23:57:51 +000062 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000063
Zachary Turner97206d52017-05-12 04:51:55 +000064 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +000065
Zachary Turner2c84f902016-12-09 05:46:41 +000066 FileSpec dylib_fspec(command[0].ref, true);
Kate Stoneb9c1b512016-09-06 20:57:50 +000067
68 if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error))
69 result.SetStatus(eReturnStatusSuccessFinishResult);
70 else {
71 result.AppendError(error.AsCString());
72 result.SetStatus(eReturnStatusFailed);
73 }
74
75 return result.Succeeded();
76 }
Enrico Granata21dfcd92012-09-28 23:57:51 +000077};
78
Kate Stone7428a182016-07-14 22:03:10 +000079CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
Kate Stoneb9c1b512016-09-06 20:57:50 +000080 : CommandObjectMultiword(interpreter, "plugin",
81 "Commands for managing LLDB plugins.",
82 "plugin <subcommand> [<subcommand-options>]") {
83 LoadSubCommand("load",
84 CommandObjectSP(new CommandObjectPluginLoad(interpreter)));
Enrico Granata21dfcd92012-09-28 23:57:51 +000085}
Kate Stoneb9c1b512016-09-06 20:57:50 +000086
Eugene Zelenko26cac3a2016-02-20 00:58:29 +000087CommandObjectPlugin::~CommandObjectPlugin() = default;