JDevlieghere created this revision. JDevlieghere added reviewers: labath, xiaobai. Herald added subscribers: lldb-commits, abidh. Herald added a project: LLDB.
This is a step towards making the initialize and terminate calls be generated by CMake, which in turn is towards making it possible to disable plugins at configuration time. The other alternative discussed was static initializers, but that requires a non-portable linker flag that will prevent the linker from performing dead code elimination. For this path I just did the ScriptInterpreter plugins. If everyone is on board with the approach I plan to land this in two patches, one with the macros as shown here and another patch where CMake generates the macro expansion for us. Repository: rLLDB LLDB https://reviews.llvm.org/D74245 Files: lldb/include/lldb/Core/PluginManager.h lldb/source/API/SystemInitializerFull.cpp lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp lldb/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -56,6 +56,8 @@ using namespace lldb_private::python; using llvm::Expected; +LLDB_PLUGIN(ScriptInterpreterPython) + // Defined in the SWIG source file #if PY_MAJOR_VERSION >= 3 extern "C" PyObject *PyInit__lldb(void); Index: lldb/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp +++ lldb/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp @@ -20,6 +20,8 @@ using namespace lldb; using namespace lldb_private; +LLDB_PLUGIN(ScriptInterpreterNone) + ScriptInterpreterNone::ScriptInterpreterNone(Debugger &debugger) : ScriptInterpreter(debugger, eScriptLanguageNone) {} Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp +++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp @@ -19,6 +19,8 @@ using namespace lldb; using namespace lldb_private; +LLDB_PLUGIN(ScriptInterpreterLua) + class IOHandlerLuaInterpreter : public IOHandlerDelegate, public IOHandlerEditline { public: Index: lldb/source/API/SystemInitializerFull.cpp =================================================================== --- lldb/source/API/SystemInitializerFull.cpp +++ lldb/source/API/SystemInitializerFull.cpp @@ -10,15 +10,8 @@ #include "lldb/API/SBCommandInterpreter.h" #include "lldb/Host/Config.h" -#if LLDB_ENABLE_PYTHON -#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h" -#endif - -#if LLDB_ENABLE_LUA -#include "Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h" -#endif - #include "lldb/Core/Debugger.h" +#include "lldb/Core/PluginManager.h" #include "lldb/Host/Host.h" #include "lldb/Initialization/SystemInitializerCommon.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -86,7 +79,6 @@ #include "Plugins/Process/gdb-remote/ProcessGDBRemote.h" #include "Plugins/Process/mach-core/ProcessMachCore.h" #include "Plugins/Process/minidump/ProcessMinidump.h" -#include "Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h" #include "Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h" @@ -126,6 +118,10 @@ using namespace lldb_private; +LLDB_PLUGIN_DECLARATION(ScriptInterpreterNone) +LLDB_PLUGIN_DECLARATION(ScriptInterpreterPython) +LLDB_PLUGIN_DECLARATION(ScriptInterpreterLua) + SystemInitializerFull::SystemInitializerFull() {} SystemInitializerFull::~SystemInitializerFull() {} @@ -176,18 +172,18 @@ ObjectContainerBSDArchive::Initialize(); ObjectContainerUniversalMachO::Initialize(); - ScriptInterpreterNone::Initialize(); + LLDB_PLUGIN_INITIALIZE(ScriptInterpreterNone) #if LLDB_ENABLE_PYTHON OperatingSystemPython::Initialize(); #endif #if LLDB_ENABLE_PYTHON - ScriptInterpreterPython::Initialize(); + LLDB_PLUGIN_INITIALIZE(ScriptInterpreterPython) #endif #if LLDB_ENABLE_LUA - ScriptInterpreterLua::Initialize(); + LLDB_PLUGIN_INITIALIZE(ScriptInterpreterLua) #endif platform_freebsd::PlatformFreeBSD::Initialize(); @@ -388,13 +384,15 @@ #endif #if LLDB_ENABLE_PYTHON - ScriptInterpreterPython::Terminate(); + LLDB_PLUGIN_TERMINATE(ScriptInterpreterPython) #endif #if LLDB_ENABLE_LUA - ScriptInterpreterLua::Terminate(); + LLDB_PLUGIN_TERMINATE(ScriptInterpreterLua) #endif + LLDB_PLUGIN_TERMINATE(ScriptInterpreterNone) + // Now shutdown the common parts, in reverse order. SystemInitializerCommon::Terminate(); } Index: lldb/include/lldb/Core/PluginManager.h =================================================================== --- lldb/include/lldb/Core/PluginManager.h +++ lldb/include/lldb/Core/PluginManager.h @@ -22,6 +22,18 @@ #include <stddef.h> #include <stdint.h> +#define LLDB_PLUGIN(PluginName) \ + void lldb_initialize_##PluginName() { PluginName::Initialize(); } \ + void lldb_terminate_##PluginName() { PluginName::Terminate(); } + +#define LLDB_PLUGIN_DECLARATION(PluginName) \ + extern void lldb_initialize_##PluginName(); \ + extern void lldb_terminate_##PluginName(); + +// FIXME: Generate me with CMake +#define LLDB_PLUGIN_INITIALIZE(PluginName) lldb_initialize_##PluginName(); +#define LLDB_PLUGIN_TERMINATE(PluginName) lldb_terminate_##PluginName(); + namespace lldb_private { class CommandInterpreter; class ConstString; @@ -42,15 +54,13 @@ static ABICreateInstance GetABICreateCallbackAtIndex(uint32_t idx); - static ABICreateInstance - GetABICreateCallbackForPluginName(ConstString name); + static ABICreateInstance GetABICreateCallbackForPluginName(ConstString name); // Architecture using ArchitectureCreateInstance = std::unique_ptr<Architecture> (*)(const ArchSpec &); - static void RegisterPlugin(ConstString name, - llvm::StringRef description, + static void RegisterPlugin(ConstString name, llvm::StringRef description, ArchitectureCreateInstance create_callback); static void UnregisterPlugin(ArchitectureCreateInstance create_callback);
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits