| 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 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 22 | class CommandObjectPluginLoad : public CommandObjectParsed { |
| Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 23 | public: |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | CommandObjectPluginLoad(CommandInterpreter &interpreter) |
| 25 | : CommandObjectParsed(interpreter, "plugin load", |
| Eugene Zelenko | 26cac3a | 2016-02-20 00:58:29 +0000 | [diff] [blame] | 26 | "Import a dylib that implements an LLDB plugin.", |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | nullptr) { |
| 28 | CommandArgumentEntry arg1; |
| 29 | CommandArgumentData cmd_arg; |
| Eugene Zelenko | 26cac3a | 2016-02-20 00:58:29 +0000 | [diff] [blame] | 30 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 31 | // Define the first (and only) variant of this arg. |
| 32 | cmd_arg.arg_type = eArgTypeFilename; |
| 33 | cmd_arg.arg_repetition = eArgRepeatPlain; |
| Eugene Zelenko | 26cac3a | 2016-02-20 00:58:29 +0000 | [diff] [blame] | 34 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | // There is only one variant this argument could be; put it into the |
| 36 | // argument entry. |
| 37 | arg1.push_back(cmd_arg); |
| Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 38 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 39 | // Push the data for the first argument into the m_arguments vector. |
| 40 | m_arguments.push_back(arg1); |
| 41 | } |
| 42 | |
| 43 | ~CommandObjectPluginLoad() override = default; |
| 44 | |
| Raphael Isemann | 2443bbd | 2018-07-02 21:29:56 +0000 | [diff] [blame] | 45 | int HandleArgumentCompletion( |
| 46 | CompletionRequest &request, |
| 47 | OptionElementVector &opt_element_vector) override { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 49 | GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion, |
| Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame] | 50 | request, nullptr); |
| Raphael Isemann | 1a6d7ab | 2018-07-27 18:42:46 +0000 | [diff] [blame^] | 51 | return request.GetNumberOfMatches(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | } |
| Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 53 | |
| 54 | protected: |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
| 56 | size_t argc = command.GetArgumentCount(); |
| 57 | |
| 58 | if (argc != 1) { |
| 59 | result.AppendError("'plugin load' requires one argument"); |
| 60 | result.SetStatus(eReturnStatusFailed); |
| 61 | return false; |
| Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 62 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | |
| Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 64 | Status error; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | |
| Zachary Turner | 2c84f90 | 2016-12-09 05:46:41 +0000 | [diff] [blame] | 66 | FileSpec dylib_fspec(command[0].ref, true); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | |
| 68 | if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error)) |
| 69 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 70 | else { |
| 71 | result.AppendError(error.AsCString()); |
| 72 | result.SetStatus(eReturnStatusFailed); |
| 73 | } |
| 74 | |
| 75 | return result.Succeeded(); |
| 76 | } |
| Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 79 | CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | : CommandObjectMultiword(interpreter, "plugin", |
| 81 | "Commands for managing LLDB plugins.", |
| 82 | "plugin <subcommand> [<subcommand-options>]") { |
| 83 | LoadSubCommand("load", |
| 84 | CommandObjectSP(new CommandObjectPluginLoad(interpreter))); |
| Enrico Granata | 21dfcd9 | 2012-09-28 23:57:51 +0000 | [diff] [blame] | 85 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 86 | |
| Eugene Zelenko | 26cac3a | 2016-02-20 00:58:29 +0000 | [diff] [blame] | 87 | CommandObjectPlugin::~CommandObjectPlugin() = default; |