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/Host/Host.h"
16 #include "lldb/Interpreter/CommandInterpreter.h"
17 #include "lldb/Interpreter/CommandReturnObject.h"
20 using namespace lldb_private;
22 class CommandObjectPluginLoad : public CommandObjectParsed
26 CommandObjectPluginLoad (CommandInterpreter &interpreter) :
27 CommandObjectParsed (interpreter,
29 "Import a dylib that implements an LLDB plugin.",
32 CommandArgumentEntry arg1;
33 CommandArgumentData cmd_arg;
35 // Define the first (and only) variant of this arg.
36 cmd_arg.arg_type = eArgTypeFilename;
37 cmd_arg.arg_repetition = eArgRepeatPlain;
39 // There is only one variant this argument could be; put it into the argument entry.
40 arg1.push_back (cmd_arg);
42 // Push the data for the first argument into the m_arguments vector.
43 m_arguments.push_back (arg1);
46 ~CommandObjectPluginLoad ()
51 HandleArgumentCompletion (Args &input,
53 int &cursor_char_position,
54 OptionElementVector &opt_element_vector,
55 int match_start_point,
56 int max_return_elements,
60 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
61 completion_str.erase (cursor_char_position);
63 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
64 CommandCompletions::eDiskFileCompletion,
65 completion_str.c_str(),
71 return matches.GetSize();
76 DoExecute (Args& command, CommandReturnObject &result)
78 size_t argc = command.GetArgumentCount();
82 result.AppendError ("'plugin load' requires one argument");
83 result.SetStatus (eReturnStatusFailed);
87 const char* path = command.GetArgumentAtIndex(0);
91 FileSpec dylib_fspec(path,true);
93 if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error))
94 result.SetStatus(eReturnStatusSuccessFinishResult);
97 result.AppendError(error.AsCString());
98 result.SetStatus(eReturnStatusFailed);
101 return result.Succeeded();
105 CommandObjectPlugin::CommandObjectPlugin (CommandInterpreter &interpreter) :
106 CommandObjectMultiword (interpreter,
108 "A set of commands for managing or customizing plugin commands.",
109 "plugin <subcommand> [<subcommand-options>]")
111 LoadSubCommand ("load", CommandObjectSP (new CommandObjectPluginLoad (interpreter)));
114 CommandObjectPlugin::~CommandObjectPlugin ()