Eugene Zelenko | 26cac3a | 2016-02-20 00:58:29 +0000 | [diff] [blame] | 1 | //===-- CommandObjectPlugin.cpp ---------------------------------*- C++ -*-===// |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 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 | |
Eugene Zelenko | 26cac3a | 2016-02-20 00:58:29 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
| 13 | // Project includes |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 14 | #include "CommandObjectPlugin.h" |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 15 | #include "lldb/Host/Host.h" |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 16 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 17 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 18 | |
| 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
| 22 | class CommandObjectPluginLoad : public CommandObjectParsed |
| 23 | { |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 24 | public: |
| 25 | CommandObjectPluginLoad (CommandInterpreter &interpreter) : |
Eugene Zelenko | 26cac3a | 2016-02-20 00:58:29 +0000 | [diff] [blame] | 26 | CommandObjectParsed(interpreter, |
| 27 | "plugin load", |
| 28 | "Import a dylib that implements an LLDB plugin.", |
| 29 | nullptr) |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 30 | { |
| 31 | CommandArgumentEntry arg1; |
| 32 | CommandArgumentData cmd_arg; |
| 33 | |
| 34 | // Define the first (and only) variant of this arg. |
| 35 | cmd_arg.arg_type = eArgTypeFilename; |
| 36 | cmd_arg.arg_repetition = eArgRepeatPlain; |
| 37 | |
| 38 | // There is only one variant this argument could be; put it into the argument entry. |
| 39 | arg1.push_back (cmd_arg); |
| 40 | |
| 41 | // Push the data for the first argument into the m_arguments vector. |
| 42 | m_arguments.push_back (arg1); |
| 43 | } |
Eugene Zelenko | 26cac3a | 2016-02-20 00:58:29 +0000 | [diff] [blame] | 44 | |
| 45 | ~CommandObjectPluginLoad() override = default; |
| 46 | |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 47 | int |
| 48 | HandleArgumentCompletion (Args &input, |
| 49 | int &cursor_index, |
| 50 | int &cursor_char_position, |
| 51 | OptionElementVector &opt_element_vector, |
| 52 | int match_start_point, |
| 53 | int max_return_elements, |
| 54 | bool &word_complete, |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 55 | StringList &matches) override |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 56 | { |
| 57 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 58 | completion_str.erase (cursor_char_position); |
| 59 | |
Eugene Zelenko | 26cac3a | 2016-02-20 00:58:29 +0000 | [diff] [blame] | 60 | CommandCompletions::InvokeCommonCompletionCallbacks(m_interpreter, |
| 61 | CommandCompletions::eDiskFileCompletion, |
| 62 | completion_str.c_str(), |
| 63 | match_start_point, |
| 64 | max_return_elements, |
| 65 | nullptr, |
| 66 | word_complete, |
| 67 | matches); |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 68 | return matches.GetSize(); |
| 69 | } |
| 70 | |
| 71 | protected: |
| 72 | bool |
Bruce Mitchener | 13d21e9 | 2015-10-07 16:56:17 +0000 | [diff] [blame] | 73 | DoExecute (Args& command, CommandReturnObject &result) override |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 74 | { |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 75 | size_t argc = command.GetArgumentCount(); |
| 76 | |
| 77 | if (argc != 1) |
| 78 | { |
| 79 | result.AppendError ("'plugin load' requires one argument"); |
| 80 | result.SetStatus (eReturnStatusFailed); |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | const char* path = command.GetArgumentAtIndex(0); |
| 85 | |
| 86 | Error error; |
| 87 | |
| 88 | FileSpec dylib_fspec(path,true); |
| 89 | |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 90 | if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error)) |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 91 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 92 | else |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 93 | { |
| 94 | result.AppendError(error.AsCString()); |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 95 | result.SetStatus(eReturnStatusFailed); |
Enrico Granata | e743c78 | 2013-04-24 21:29:08 +0000 | [diff] [blame] | 96 | } |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 97 | |
| 98 | return result.Succeeded(); |
| 99 | } |
| 100 | }; |
| 101 | |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 102 | CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter) |
| 103 | : CommandObjectMultiword(interpreter, "plugin", "Commands for managing LLDB plugins.", |
| 104 | "plugin <subcommand> [<subcommand-options>]") |
Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 105 | { |
| 106 | LoadSubCommand ("load", CommandObjectSP (new CommandObjectPluginLoad (interpreter))); |
| 107 | } |
| 108 | |
Eugene Zelenko | 26cac3a | 2016-02-20 00:58:29 +0000 | [diff] [blame] | 109 | CommandObjectPlugin::~CommandObjectPlugin() = default; |