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