blob: 221c9a67d8488ecc6172c24ecd6ab25c3223a6ff [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
22class CommandObjectPluginLoad : public CommandObjectParsed
23{
Enrico Granata21dfcd92012-09-28 23:57:51 +000024public:
25 CommandObjectPluginLoad (CommandInterpreter &interpreter) :
Eugene Zelenko26cac3a2016-02-20 00:58:29 +000026 CommandObjectParsed(interpreter,
27 "plugin load",
28 "Import a dylib that implements an LLDB plugin.",
29 nullptr)
Enrico Granata21dfcd92012-09-28 23:57:51 +000030 {
31 CommandArgumentEntry arg1;
32 CommandArgumentData cmd_arg;
33
34 // Define the first (and only) variant of this arg.
35 cmd_arg.arg_type = eArgTypeFilename;
36 cmd_arg.arg_repetition = eArgRepeatPlain;
37
38 // There is only one variant this argument could be; put it into the argument entry.
39 arg1.push_back (cmd_arg);
40
41 // Push the data for the first argument into the m_arguments vector.
42 m_arguments.push_back (arg1);
43 }
Eugene Zelenko26cac3a2016-02-20 00:58:29 +000044
45 ~CommandObjectPluginLoad() override = default;
46
Enrico Granata21dfcd92012-09-28 23:57:51 +000047 int
48 HandleArgumentCompletion (Args &input,
49 int &cursor_index,
50 int &cursor_char_position,
51 OptionElementVector &opt_element_vector,
52 int match_start_point,
53 int max_return_elements,
54 bool &word_complete,
Bruce Mitchener13d21e92015-10-07 16:56:17 +000055 StringList &matches) override
Enrico Granata21dfcd92012-09-28 23:57:51 +000056 {
57 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
58 completion_str.erase (cursor_char_position);
59
Eugene Zelenko26cac3a2016-02-20 00:58:29 +000060 CommandCompletions::InvokeCommonCompletionCallbacks(m_interpreter,
61 CommandCompletions::eDiskFileCompletion,
62 completion_str.c_str(),
63 match_start_point,
64 max_return_elements,
65 nullptr,
66 word_complete,
67 matches);
Enrico Granata21dfcd92012-09-28 23:57:51 +000068 return matches.GetSize();
69 }
70
71protected:
72 bool
Bruce Mitchener13d21e92015-10-07 16:56:17 +000073 DoExecute (Args& command, CommandReturnObject &result) override
Enrico Granata21dfcd92012-09-28 23:57:51 +000074 {
Enrico Granata21dfcd92012-09-28 23:57:51 +000075 size_t argc = command.GetArgumentCount();
76
77 if (argc != 1)
78 {
79 result.AppendError ("'plugin load' requires one argument");
80 result.SetStatus (eReturnStatusFailed);
81 return false;
82 }
83
84 const char* path = command.GetArgumentAtIndex(0);
85
86 Error error;
87
88 FileSpec dylib_fspec(path,true);
89
Enrico Granatae743c782013-04-24 21:29:08 +000090 if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error))
Enrico Granata21dfcd92012-09-28 23:57:51 +000091 result.SetStatus(eReturnStatusSuccessFinishResult);
92 else
Enrico Granatae743c782013-04-24 21:29:08 +000093 {
94 result.AppendError(error.AsCString());
Enrico Granata21dfcd92012-09-28 23:57:51 +000095 result.SetStatus(eReturnStatusFailed);
Enrico Granatae743c782013-04-24 21:29:08 +000096 }
Enrico Granata21dfcd92012-09-28 23:57:51 +000097
98 return result.Succeeded();
99 }
100};
101
Kate Stone7428a182016-07-14 22:03:10 +0000102CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)
103 : CommandObjectMultiword(interpreter, "plugin", "Commands for managing LLDB plugins.",
104 "plugin <subcommand> [<subcommand-options>]")
Enrico Granata21dfcd92012-09-28 23:57:51 +0000105{
106 LoadSubCommand ("load", CommandObjectSP (new CommandObjectPluginLoad (interpreter)));
107}
108
Eugene Zelenko26cac3a2016-02-20 00:58:29 +0000109CommandObjectPlugin::~CommandObjectPlugin() = default;