blob: 6570c1d897885afdb2bee2e1fc46bd53806cb30f [file] [log] [blame]
Enrico Granata6d101882012-09-28 23:57:51 +00001//===-- CommandObjectPlugin.cpp ----------------------------------*- C++ -*-===//
2//
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
10#include "CommandObjectPlugin.h"
11
12#include "lldb/API/SBDebugger.h"
13#include "lldb/API/SBCommandInterpreter.h"
14#include "lldb/API/SBCommandReturnObject.h"
15
16#include "lldb/Host/Host.h"
17
18#include "lldb/Interpreter/CommandInterpreter.h"
19#include "lldb/Interpreter/CommandReturnObject.h"
20
21using namespace lldb;
22using namespace lldb_private;
23
24class CommandObjectPluginLoad : public CommandObjectParsed
25{
26private:
27public:
28 CommandObjectPluginLoad (CommandInterpreter &interpreter) :
29 CommandObjectParsed (interpreter,
30 "plugin load",
31 "Import a dylib that implements an LLDB plugin.",
32 NULL)
33 {
34 CommandArgumentEntry arg1;
35 CommandArgumentData cmd_arg;
36
37 // Define the first (and only) variant of this arg.
38 cmd_arg.arg_type = eArgTypeFilename;
39 cmd_arg.arg_repetition = eArgRepeatPlain;
40
41 // There is only one variant this argument could be; put it into the argument entry.
42 arg1.push_back (cmd_arg);
43
44 // Push the data for the first argument into the m_arguments vector.
45 m_arguments.push_back (arg1);
46 }
47
48 ~CommandObjectPluginLoad ()
49 {
50 }
51
52 int
53 HandleArgumentCompletion (Args &input,
54 int &cursor_index,
55 int &cursor_char_position,
56 OptionElementVector &opt_element_vector,
57 int match_start_point,
58 int max_return_elements,
59 bool &word_complete,
60 StringList &matches)
61 {
62 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
63 completion_str.erase (cursor_char_position);
64
65 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
66 CommandCompletions::eDiskFileCompletion,
67 completion_str.c_str(),
68 match_start_point,
69 max_return_elements,
70 NULL,
71 word_complete,
72 matches);
73 return matches.GetSize();
74 }
75
76protected:
77 bool
78 DoExecute (Args& command, CommandReturnObject &result)
79 {
80 typedef void (*LLDBCommandPluginInit) (lldb::SBDebugger debugger);
81
82 size_t argc = command.GetArgumentCount();
83
84 if (argc != 1)
85 {
86 result.AppendError ("'plugin load' requires one argument");
87 result.SetStatus (eReturnStatusFailed);
88 return false;
89 }
90
91 const char* path = command.GetArgumentAtIndex(0);
92
93 Error error;
94
95 FileSpec dylib_fspec(path,true);
96
97 if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec))
98 result.SetStatus(eReturnStatusSuccessFinishResult);
99 else
100 result.SetStatus(eReturnStatusFailed);
101
102 return result.Succeeded();
103 }
104};
105
106CommandObjectPlugin::CommandObjectPlugin (CommandInterpreter &interpreter) :
107CommandObjectMultiword (interpreter,
108 "plugin",
109 "A set of commands for managing or customizing plugin commands.",
110 "plugin <subcommand> [<subcommand-options>]")
111{
112 LoadSubCommand ("load", CommandObjectSP (new CommandObjectPluginLoad (interpreter)));
113}
114
115CommandObjectPlugin::~CommandObjectPlugin ()
116{
117}