1 //===-- CommandObjectPlugin.cpp ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "CommandObjectPlugin.h"
14 #include "lldb/API/SBDebugger.h"
15 #include "lldb/API/SBCommandInterpreter.h"
16 #include "lldb/API/SBCommandReturnObject.h"
18 #include "lldb/Host/Host.h"
20 #include "lldb/Interpreter/CommandInterpreter.h"
21 #include "lldb/Interpreter/CommandReturnObject.h"
24 using namespace lldb_private;
26 class CommandObjectPluginLoad : public CommandObjectParsed
30 CommandObjectPluginLoad (CommandInterpreter &interpreter) :
31 CommandObjectParsed (interpreter,
33 "Import a dylib that implements an LLDB plugin.",
36 CommandArgumentEntry arg1;
37 CommandArgumentData cmd_arg;
39 // Define the first (and only) variant of this arg.
40 cmd_arg.arg_type = eArgTypeFilename;
41 cmd_arg.arg_repetition = eArgRepeatPlain;
43 // There is only one variant this argument could be; put it into the argument entry.
44 arg1.push_back (cmd_arg);
46 // Push the data for the first argument into the m_arguments vector.
47 m_arguments.push_back (arg1);
50 ~CommandObjectPluginLoad ()
55 HandleArgumentCompletion (Args &input,
57 int &cursor_char_position,
58 OptionElementVector &opt_element_vector,
59 int match_start_point,
60 int max_return_elements,
64 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
65 completion_str.erase (cursor_char_position);
67 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
68 CommandCompletions::eDiskFileCompletion,
69 completion_str.c_str(),
75 return matches.GetSize();
80 DoExecute (Args& command, CommandReturnObject &result)
82 typedef void (*LLDBCommandPluginInit) (lldb::SBDebugger debugger);
84 size_t argc = command.GetArgumentCount();
88 result.AppendError ("'plugin load' requires one argument");
89 result.SetStatus (eReturnStatusFailed);
93 const char* path = command.GetArgumentAtIndex(0);
97 FileSpec dylib_fspec(path,true);
99 if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error))
100 result.SetStatus(eReturnStatusSuccessFinishResult);
103 result.AppendError(error.AsCString());
104 result.SetStatus(eReturnStatusFailed);
107 return result.Succeeded();
111 CommandObjectPlugin::CommandObjectPlugin (CommandInterpreter &interpreter) :
112 CommandObjectMultiword (interpreter,
114 "A set of commands for managing or customizing plugin commands.",
115 "plugin <subcommand> [<subcommand-options>]")
117 LoadSubCommand ("load", CommandObjectSP (new CommandObjectPluginLoad (interpreter)));
120 CommandObjectPlugin::~CommandObjectPlugin ()