1*0b57cec5SDimitry Andric //===-- CommandObjectPlugin.cpp ---------------------------------*- C++ -*-===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric #include "CommandObjectPlugin.h" 10*0b57cec5SDimitry Andric #include "lldb/Host/Host.h" 11*0b57cec5SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h" 12*0b57cec5SDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h" 13*0b57cec5SDimitry Andric 14*0b57cec5SDimitry Andric using namespace lldb; 15*0b57cec5SDimitry Andric using namespace lldb_private; 16*0b57cec5SDimitry Andric 17*0b57cec5SDimitry Andric class CommandObjectPluginLoad : public CommandObjectParsed { 18*0b57cec5SDimitry Andric public: 19*0b57cec5SDimitry Andric CommandObjectPluginLoad(CommandInterpreter &interpreter) 20*0b57cec5SDimitry Andric : CommandObjectParsed(interpreter, "plugin load", 21*0b57cec5SDimitry Andric "Import a dylib that implements an LLDB plugin.", 22*0b57cec5SDimitry Andric nullptr) { 23*0b57cec5SDimitry Andric CommandArgumentEntry arg1; 24*0b57cec5SDimitry Andric CommandArgumentData cmd_arg; 25*0b57cec5SDimitry Andric 26*0b57cec5SDimitry Andric // Define the first (and only) variant of this arg. 27*0b57cec5SDimitry Andric cmd_arg.arg_type = eArgTypeFilename; 28*0b57cec5SDimitry Andric cmd_arg.arg_repetition = eArgRepeatPlain; 29*0b57cec5SDimitry Andric 30*0b57cec5SDimitry Andric // There is only one variant this argument could be; put it into the 31*0b57cec5SDimitry Andric // argument entry. 32*0b57cec5SDimitry Andric arg1.push_back(cmd_arg); 33*0b57cec5SDimitry Andric 34*0b57cec5SDimitry Andric // Push the data for the first argument into the m_arguments vector. 35*0b57cec5SDimitry Andric m_arguments.push_back(arg1); 36*0b57cec5SDimitry Andric } 37*0b57cec5SDimitry Andric 38*0b57cec5SDimitry Andric ~CommandObjectPluginLoad() override = default; 39*0b57cec5SDimitry Andric 40*0b57cec5SDimitry Andric int HandleArgumentCompletion( 41*0b57cec5SDimitry Andric CompletionRequest &request, 42*0b57cec5SDimitry Andric OptionElementVector &opt_element_vector) override { 43*0b57cec5SDimitry Andric CommandCompletions::InvokeCommonCompletionCallbacks( 44*0b57cec5SDimitry Andric GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion, 45*0b57cec5SDimitry Andric request, nullptr); 46*0b57cec5SDimitry Andric return request.GetNumberOfMatches(); 47*0b57cec5SDimitry Andric } 48*0b57cec5SDimitry Andric 49*0b57cec5SDimitry Andric protected: 50*0b57cec5SDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override { 51*0b57cec5SDimitry Andric size_t argc = command.GetArgumentCount(); 52*0b57cec5SDimitry Andric 53*0b57cec5SDimitry Andric if (argc != 1) { 54*0b57cec5SDimitry Andric result.AppendError("'plugin load' requires one argument"); 55*0b57cec5SDimitry Andric result.SetStatus(eReturnStatusFailed); 56*0b57cec5SDimitry Andric return false; 57*0b57cec5SDimitry Andric } 58*0b57cec5SDimitry Andric 59*0b57cec5SDimitry Andric Status error; 60*0b57cec5SDimitry Andric 61*0b57cec5SDimitry Andric FileSpec dylib_fspec(command[0].ref); 62*0b57cec5SDimitry Andric FileSystem::Instance().Resolve(dylib_fspec); 63*0b57cec5SDimitry Andric 64*0b57cec5SDimitry Andric if (GetDebugger().LoadPlugin(dylib_fspec, error)) 65*0b57cec5SDimitry Andric result.SetStatus(eReturnStatusSuccessFinishResult); 66*0b57cec5SDimitry Andric else { 67*0b57cec5SDimitry Andric result.AppendError(error.AsCString()); 68*0b57cec5SDimitry Andric result.SetStatus(eReturnStatusFailed); 69*0b57cec5SDimitry Andric } 70*0b57cec5SDimitry Andric 71*0b57cec5SDimitry Andric return result.Succeeded(); 72*0b57cec5SDimitry Andric } 73*0b57cec5SDimitry Andric }; 74*0b57cec5SDimitry Andric 75*0b57cec5SDimitry Andric CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter) 76*0b57cec5SDimitry Andric : CommandObjectMultiword(interpreter, "plugin", 77*0b57cec5SDimitry Andric "Commands for managing LLDB plugins.", 78*0b57cec5SDimitry Andric "plugin <subcommand> [<subcommand-options>]") { 79*0b57cec5SDimitry Andric LoadSubCommand("load", 80*0b57cec5SDimitry Andric CommandObjectSP(new CommandObjectPluginLoad(interpreter))); 81*0b57cec5SDimitry Andric } 82*0b57cec5SDimitry Andric 83*0b57cec5SDimitry Andric CommandObjectPlugin::~CommandObjectPlugin() = default; 84