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