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 "CommandObjectPlugin.h"
12 #include "lldb/Host/Host.h"
14 #include "lldb/Interpreter/CommandInterpreter.h"
15 #include "lldb/Interpreter/CommandReturnObject.h"
18 using namespace lldb_private;
20 class CommandObjectPluginLoad : public CommandObjectParsed
24 CommandObjectPluginLoad (CommandInterpreter &interpreter) :
25 CommandObjectParsed (interpreter,
27 "Import a dylib that implements an LLDB plugin.",
30 CommandArgumentEntry arg1;
31 CommandArgumentData cmd_arg;
33 // Define the first (and only) variant of this arg.
34 cmd_arg.arg_type = eArgTypeFilename;
35 cmd_arg.arg_repetition = eArgRepeatPlain;
37 // There is only one variant this argument could be; put it into the argument entry.
38 arg1.push_back (cmd_arg);
40 // Push the data for the first argument into the m_arguments vector.
41 m_arguments.push_back (arg1);
44 ~CommandObjectPluginLoad () override
49 HandleArgumentCompletion (Args &input,
51 int &cursor_char_position,
52 OptionElementVector &opt_element_vector,
53 int match_start_point,
54 int max_return_elements,
56 StringList &matches) override
58 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
59 completion_str.erase (cursor_char_position);
61 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
62 CommandCompletions::eDiskFileCompletion,
63 completion_str.c_str(),
69 return matches.GetSize();
74 DoExecute (Args& command, CommandReturnObject &result) override
76 size_t argc = command.GetArgumentCount();
80 result.AppendError ("'plugin load' requires one argument");
81 result.SetStatus (eReturnStatusFailed);
85 const char* path = command.GetArgumentAtIndex(0);
89 FileSpec dylib_fspec(path,true);
91 if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error))
92 result.SetStatus(eReturnStatusSuccessFinishResult);
95 result.AppendError(error.AsCString());
96 result.SetStatus(eReturnStatusFailed);
99 return result.Succeeded();
103 CommandObjectPlugin::CommandObjectPlugin (CommandInterpreter &interpreter) :
104 CommandObjectMultiword (interpreter,
106 "A set of commands for managing or customizing plugin commands.",
107 "plugin <subcommand> [<subcommand-options>]")
109 LoadSubCommand ("load", CommandObjectSP (new CommandObjectPluginLoad (interpreter)));
112 CommandObjectPlugin::~CommandObjectPlugin ()