1254721Semaste//===-- CommandObjectPlugin.cpp ----------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#include "lldb/lldb-python.h" 11254721Semaste 12254721Semaste#include "CommandObjectPlugin.h" 13254721Semaste 14254721Semaste#include "lldb/Host/Host.h" 15254721Semaste 16254721Semaste#include "lldb/Interpreter/CommandInterpreter.h" 17254721Semaste#include "lldb/Interpreter/CommandReturnObject.h" 18254721Semaste 19254721Semasteusing namespace lldb; 20254721Semasteusing namespace lldb_private; 21254721Semaste 22254721Semasteclass CommandObjectPluginLoad : public CommandObjectParsed 23254721Semaste{ 24254721Semasteprivate: 25254721Semastepublic: 26254721Semaste CommandObjectPluginLoad (CommandInterpreter &interpreter) : 27254721Semaste CommandObjectParsed (interpreter, 28254721Semaste "plugin load", 29254721Semaste "Import a dylib that implements an LLDB plugin.", 30254721Semaste NULL) 31254721Semaste { 32254721Semaste CommandArgumentEntry arg1; 33254721Semaste CommandArgumentData cmd_arg; 34254721Semaste 35254721Semaste // Define the first (and only) variant of this arg. 36254721Semaste cmd_arg.arg_type = eArgTypeFilename; 37254721Semaste cmd_arg.arg_repetition = eArgRepeatPlain; 38254721Semaste 39254721Semaste // There is only one variant this argument could be; put it into the argument entry. 40254721Semaste arg1.push_back (cmd_arg); 41254721Semaste 42254721Semaste // Push the data for the first argument into the m_arguments vector. 43254721Semaste m_arguments.push_back (arg1); 44254721Semaste } 45254721Semaste 46254721Semaste ~CommandObjectPluginLoad () 47254721Semaste { 48254721Semaste } 49254721Semaste 50254721Semaste int 51254721Semaste HandleArgumentCompletion (Args &input, 52254721Semaste int &cursor_index, 53254721Semaste int &cursor_char_position, 54254721Semaste OptionElementVector &opt_element_vector, 55254721Semaste int match_start_point, 56254721Semaste int max_return_elements, 57254721Semaste bool &word_complete, 58254721Semaste StringList &matches) 59254721Semaste { 60254721Semaste std::string completion_str (input.GetArgumentAtIndex(cursor_index)); 61254721Semaste completion_str.erase (cursor_char_position); 62254721Semaste 63254721Semaste CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, 64254721Semaste CommandCompletions::eDiskFileCompletion, 65254721Semaste completion_str.c_str(), 66254721Semaste match_start_point, 67254721Semaste max_return_elements, 68254721Semaste NULL, 69254721Semaste word_complete, 70254721Semaste matches); 71254721Semaste return matches.GetSize(); 72254721Semaste } 73254721Semaste 74254721Semasteprotected: 75254721Semaste bool 76254721Semaste DoExecute (Args& command, CommandReturnObject &result) 77254721Semaste { 78254721Semaste size_t argc = command.GetArgumentCount(); 79254721Semaste 80254721Semaste if (argc != 1) 81254721Semaste { 82254721Semaste result.AppendError ("'plugin load' requires one argument"); 83254721Semaste result.SetStatus (eReturnStatusFailed); 84254721Semaste return false; 85254721Semaste } 86254721Semaste 87254721Semaste const char* path = command.GetArgumentAtIndex(0); 88254721Semaste 89254721Semaste Error error; 90254721Semaste 91254721Semaste FileSpec dylib_fspec(path,true); 92254721Semaste 93254721Semaste if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error)) 94254721Semaste result.SetStatus(eReturnStatusSuccessFinishResult); 95254721Semaste else 96254721Semaste { 97254721Semaste result.AppendError(error.AsCString()); 98254721Semaste result.SetStatus(eReturnStatusFailed); 99254721Semaste } 100254721Semaste 101254721Semaste return result.Succeeded(); 102254721Semaste } 103254721Semaste}; 104254721Semaste 105254721SemasteCommandObjectPlugin::CommandObjectPlugin (CommandInterpreter &interpreter) : 106254721SemasteCommandObjectMultiword (interpreter, 107254721Semaste "plugin", 108254721Semaste "A set of commands for managing or customizing plugin commands.", 109254721Semaste "plugin <subcommand> [<subcommand-options>]") 110254721Semaste{ 111254721Semaste LoadSubCommand ("load", CommandObjectSP (new CommandObjectPluginLoad (interpreter))); 112254721Semaste} 113254721Semaste 114254721SemasteCommandObjectPlugin::~CommandObjectPlugin () 115254721Semaste{ 116254721Semaste} 117