Author: abhishek Date: Fri Jul 29 02:46:32 2016 New Revision: 277125 URL: http://llvm.org/viewvc/llvm-project?rev=277125&view=rev Log: Improve code of loading plugins that provide cmnds
Summary: - Modified code that enables writing new user-defined commands and use them through LLDB CLI. Modifications are: -- Define the 'syntax' for each user-defined command --- Added an argument in SBCommandInterpreter::AddCommand() and SBCommand::AddCommand() API --- Allow passing syntax for each user-defined command --- Earlier, only 'help' could be defined and passed for commands -- Passed 'number of arguments' entered on CLI for user-defined commands --- Added an argument (number of options) in SBCommandPluginInterface::DoExecute() API to know the number of arguments passed for commands -- In CommandPluginInterfaceImplementation class: --- Make the data member m_backend a shared_ptr --- Avoids memory leaks of dynamically allocated SBCommandPluginInterface instances created in lldb::PluginInitialize() API Signed-off-by: Abhishek Aggarwal <abhishek.a.aggar...@intel.com> Reviewers: jingham, granata.enrico, clayborg Subscribers: labath, lldb-commits Differential Revision: https://reviews.llvm.org/D22863 Modified: lldb/trunk/include/lldb/API/SBCommandInterpreter.h lldb/trunk/source/API/SBCommandInterpreter.cpp Modified: lldb/trunk/include/lldb/API/SBCommandInterpreter.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBCommandInterpreter.h?rev=277125&r1=277124&r2=277125&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBCommandInterpreter.h (original) +++ lldb/trunk/include/lldb/API/SBCommandInterpreter.h Fri Jul 29 02:46:32 2016 @@ -141,6 +141,9 @@ public: lldb::SBCommand AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help); + lldb::SBCommand + AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help, const char* syntax); + void SourceInitFileInHomeDirectory (lldb::SBCommandReturnObject &result); @@ -308,6 +311,9 @@ public: lldb::SBCommand AddCommand(const char* name, lldb::SBCommandPluginInterface* impl, const char* help = nullptr); + lldb::SBCommand + AddCommand(const char* name, lldb::SBCommandPluginInterface* impl, const char* help, const char* syntax); + private: friend class SBDebugger; friend class SBCommandInterpreter; Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=277125&r1=277124&r2=277125&view=diff ============================================================================== --- lldb/trunk/source/API/SBCommandInterpreter.cpp (original) +++ lldb/trunk/source/API/SBCommandInterpreter.cpp Fri Jul 29 02:46:32 2016 @@ -153,7 +153,7 @@ protected: sb_return.Release(); return ret; } - lldb::SBCommandPluginInterface* m_backend; + std::shared_ptr<lldb::SBCommandPluginInterface> m_backend; }; SBCommandInterpreter::SBCommandInterpreter (CommandInterpreter *interpreter) : @@ -605,6 +605,17 @@ SBCommandInterpreter::AddCommand (const return lldb::SBCommand(); } +lldb::SBCommand +SBCommandInterpreter::AddCommand (const char* name, lldb::SBCommandPluginInterface* impl, const char* help, const char* syntax) +{ + lldb::CommandObjectSP new_command_sp; + new_command_sp.reset(new CommandPluginInterfaceImplementation(*m_opaque_ptr,name, impl, help, syntax)); + + if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) + return lldb::SBCommand(new_command_sp); + return lldb::SBCommand(); +} + SBCommand::SBCommand() = default; SBCommand::SBCommand (lldb::CommandObjectSP cmd_sp) : m_opaque_sp (cmd_sp) @@ -677,6 +688,21 @@ SBCommand::AddCommand (const char* name, return lldb::SBCommand(); } +lldb::SBCommand +SBCommand::AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help, const char* syntax) +{ + if (!IsValid ()) + return lldb::SBCommand(); + if (!m_opaque_sp->IsMultiwordObject()) + return lldb::SBCommand(); + lldb::CommandObjectSP new_command_sp; + new_command_sp.reset(new CommandPluginInterfaceImplementation(m_opaque_sp->GetCommandInterpreter(),name,impl,help, syntax)); + if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp)) + return lldb::SBCommand(new_command_sp); + return lldb::SBCommand(); +} + + uint32_t SBCommand::GetFlags () { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits