Index: include/lldb/Core/PluginManager.h =================================================================== --- include/lldb/Core/PluginManager.h +++ include/lldb/Core/PluginManager.h @@ -470,6 +470,16 @@ const lldb::OptionValuePropertiesSP &properties_sp, const ConstString &description, bool is_global_property); + + static lldb::OptionValuePropertiesSP + GetSettingForJITLoaderPlugin (Debugger &debugger, + const ConstString &setting_name); + + static bool + CreateSettingForJITLoaderPlugin (Debugger &debugger, + const lldb::OptionValuePropertiesSP &properties_sp, + const ConstString &description, + bool is_global_property); }; Index: source/Core/PluginManager.cpp =================================================================== --- source/Core/PluginManager.cpp +++ source/Core/PluginManager.cpp @@ -2661,32 +2661,40 @@ return lldb::OptionValuePropertiesSP(); } +namespace { + +typedef lldb::OptionValuePropertiesSP +GetDebuggerPropertyForPluginsPtr (Debugger&, const ConstString&, const ConstString&, bool can_create); lldb::OptionValuePropertiesSP -PluginManager::GetSettingForDynamicLoaderPlugin (Debugger &debugger, const ConstString &setting_name) +GetSettingForPlugin (Debugger &debugger, + const ConstString &setting_name, + const ConstString &plugin_type_name, + GetDebuggerPropertyForPluginsPtr get_debugger_property= GetDebuggerPropertyForPlugins) { lldb::OptionValuePropertiesSP properties_sp; - lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPlugins (debugger, - ConstString("dynamic-loader"), - ConstString(), // not creating to so we don't need the description - false)); + lldb::OptionValuePropertiesSP plugin_type_properties_sp (get_debugger_property (debugger, + plugin_type_name, + ConstString(), // not creating to so we don't need the description + false)); if (plugin_type_properties_sp) - properties_sp = plugin_type_properties_sp->GetSubProperty (NULL, setting_name); + properties_sp = plugin_type_properties_sp->GetSubProperty (nullptr, setting_name); return properties_sp; } bool -PluginManager::CreateSettingForDynamicLoaderPlugin (Debugger &debugger, - const lldb::OptionValuePropertiesSP &properties_sp, - const ConstString &description, - bool is_global_property) +CreateSettingForPlugin (Debugger &debugger, + const ConstString &plugin_type_name, + const ConstString &plugin_type_desc, + const lldb::OptionValuePropertiesSP &properties_sp, + const ConstString &description, + bool is_global_property, + GetDebuggerPropertyForPluginsPtr get_debugger_property = GetDebuggerPropertyForPlugins) { if (properties_sp) { - lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPlugins (debugger, - ConstString("dynamic-loader"), - ConstString("Settings for dynamic loader plug-ins"), - true)); + lldb::OptionValuePropertiesSP plugin_type_properties_sp (get_debugger_property ( + debugger, plugin_type_name, plugin_type_desc, true)); if (plugin_type_properties_sp) { plugin_type_properties_sp->AppendProperty (properties_sp->GetName(), @@ -2699,56 +2707,65 @@ return false; } +const char* kDynamicLoaderPluginName("dynamic-loader"); +const char* kPlatformPluginName("platform"); +const char* kProcessPluginName("process"); +const char* kSymbolFilePluginName("symbol-file"); +const char* kJITLoaderPluginName("jit-loader"); + +} lldb::OptionValuePropertiesSP -PluginManager::GetSettingForPlatformPlugin (Debugger &debugger, const ConstString &setting_name) +PluginManager::GetSettingForDynamicLoaderPlugin (Debugger &debugger, + const ConstString &setting_name) { - lldb::OptionValuePropertiesSP properties_sp; - lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPluginsOldStyle (debugger, - ConstString("platform"), - ConstString(), // not creating to so we don't need the description - false)); - if (plugin_type_properties_sp) - properties_sp = plugin_type_properties_sp->GetSubProperty (NULL, setting_name); - return properties_sp; + return GetSettingForPlugin(debugger, setting_name, ConstString(kDynamicLoaderPluginName)); } bool -PluginManager::CreateSettingForPlatformPlugin (Debugger &debugger, +PluginManager::CreateSettingForDynamicLoaderPlugin (Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, const ConstString &description, bool is_global_property) { - if (properties_sp) - { - lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPluginsOldStyle (debugger, - ConstString("platform"), - ConstString("Settings for platform plug-ins"), - true)); - if (plugin_type_properties_sp) - { - plugin_type_properties_sp->AppendProperty (properties_sp->GetName(), - description, - is_global_property, - properties_sp); - return true; - } - } - return false; + return CreateSettingForPlugin(debugger, + ConstString(kDynamicLoaderPluginName), + ConstString("Settings for dynamic loader plug-ins"), + properties_sp, + description, + is_global_property); +} + + +lldb::OptionValuePropertiesSP +PluginManager::GetSettingForPlatformPlugin (Debugger &debugger, const ConstString &setting_name) +{ + return GetSettingForPlugin(debugger, + setting_name, + ConstString(kPlatformPluginName), + GetDebuggerPropertyForPluginsOldStyle); +} + +bool +PluginManager::CreateSettingForPlatformPlugin (Debugger &debugger, + const lldb::OptionValuePropertiesSP &properties_sp, + const ConstString &description, + bool is_global_property) +{ + return CreateSettingForPlugin(debugger, + ConstString(kPlatformPluginName), + ConstString("Settings for platform plug-ins"), + properties_sp, + description, + is_global_property, + GetDebuggerPropertyForPluginsOldStyle); } lldb::OptionValuePropertiesSP PluginManager::GetSettingForProcessPlugin (Debugger &debugger, const ConstString &setting_name) { - lldb::OptionValuePropertiesSP properties_sp; - lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPlugins (debugger, - ConstString("process"), - ConstString(), // not creating to so we don't need the description - false)); - if (plugin_type_properties_sp) - properties_sp = plugin_type_properties_sp->GetSubProperty (NULL, setting_name); - return properties_sp; + return GetSettingForPlugin(debugger, setting_name, ConstString(kProcessPluginName)); } bool @@ -2757,39 +2774,19 @@ const ConstString &description, bool is_global_property) { - if (properties_sp) - { - lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPlugins (debugger, - ConstString("process"), - ConstString("Settings for process plug-ins"), - true)); - if (plugin_type_properties_sp) - { - plugin_type_properties_sp->AppendProperty (properties_sp->GetName(), - description, - is_global_property, - properties_sp); - return true; - } - } - return false; + return CreateSettingForPlugin(debugger, + ConstString(kProcessPluginName), + ConstString("Settings for process plug-ins"), + properties_sp, + description, + is_global_property); } - -static const char* kSymbolFilePluginName("symbol-file"); - lldb::OptionValuePropertiesSP PluginManager::GetSettingForSymbolFilePlugin (Debugger &debugger, const ConstString &setting_name) { - lldb::OptionValuePropertiesSP properties_sp; - lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPlugins (debugger, - ConstString(kSymbolFilePluginName), - ConstString(), // not creating to so we don't need the description - false)); - if (plugin_type_properties_sp) - properties_sp = plugin_type_properties_sp->GetSubProperty (nullptr, setting_name); - return properties_sp; + return GetSettingForPlugin(debugger, setting_name, ConstString(kSymbolFilePluginName)); } bool @@ -2798,20 +2795,31 @@ const ConstString &description, bool is_global_property) { - if (properties_sp) - { - lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPlugins (debugger, - ConstString(kSymbolFilePluginName), - ConstString("Settings for symbol file plug-ins"), - true)); - if (plugin_type_properties_sp) - { - plugin_type_properties_sp->AppendProperty (properties_sp->GetName(), - description, - is_global_property, - properties_sp); - return true; - } - } - return false; + return CreateSettingForPlugin(debugger, + ConstString(kSymbolFilePluginName), + ConstString("Settings for symbol file plug-ins"), + properties_sp, + description, + is_global_property); +} + +lldb::OptionValuePropertiesSP +PluginManager::GetSettingForJITLoaderPlugin (Debugger &debugger, + const ConstString &setting_name) +{ + return GetSettingForPlugin(debugger, setting_name, ConstString(kJITLoaderPluginName)); +} + +bool +PluginManager::CreateSettingForJITLoaderPlugin (Debugger &debugger, + const lldb::OptionValuePropertiesSP &properties_sp, + const ConstString &description, + bool is_global_property) +{ + return CreateSettingForPlugin(debugger, + ConstString(kJITLoaderPluginName), + ConstString("Settings for JIT loader plug-ins"), + properties_sp, + description, + is_global_property); } Index: source/Plugins/JITLoader/GDB/JITLoaderGDB.h =================================================================== --- source/Plugins/JITLoader/GDB/JITLoaderGDB.h +++ source/Plugins/JITLoader/GDB/JITLoaderGDB.h @@ -42,6 +42,9 @@ JITLoaderGDB (lldb_private::Process *process); + static void + DebuggerInitialize(lldb_private::Debugger &debugger); + virtual ~JITLoaderGDB (); Index: source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp =================================================================== --- source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp +++ source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp @@ -16,6 +16,7 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/Section.h" #include "lldb/Core/StreamString.h" +#include "lldb/Interpreter/OptionValueProperties.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Target/Process.h" @@ -27,6 +28,58 @@ using namespace lldb; using namespace lldb_private; +namespace { + + PropertyDefinition + g_properties[] = + { + { "enable-jit-breakpoint", OptionValue::eTypeBoolean, true, true , nullptr, nullptr, "Enable breakpoint on __jit_debug_register_code." }, + { nullptr , OptionValue::eTypeInvalid, false, 0, nullptr, nullptr, nullptr } + }; + + enum + { + ePropertyEnableJITBreakpoint + }; + + + class PluginProperties : public Properties + { + public: + static ConstString + GetSettingName() + { + return JITLoaderGDB::GetPluginNameStatic(); + } + + PluginProperties() + { + m_collection_sp.reset (new OptionValueProperties(GetSettingName())); + m_collection_sp->Initialize(g_properties); + } + + bool + GetEnableJITBreakpoint() const + { + return m_collection_sp->GetPropertyAtIndexAsBoolean( + nullptr, + ePropertyEnableJITBreakpoint, + g_properties[ePropertyEnableJITBreakpoint].default_uint_value != 0); + } + + }; + + typedef std::shared_ptr JITLoaderGDBPropertiesSP; + + static const JITLoaderGDBPropertiesSP& + GetGlobalPluginProperties() + { + static const auto g_settings_sp(std::make_shared()); + return g_settings_sp; + } + +} // anonymous namespace end + //------------------------------------------------------------------ // Debug Interface Structures //------------------------------------------------------------------ @@ -70,6 +123,19 @@ m_process->GetTarget().RemoveBreakpointByID (m_jit_break_id); } +void +JITLoaderGDB::DebuggerInitialize(Debugger &debugger) +{ + if (!PluginManager::GetSettingForJITLoaderPlugin(debugger, PluginProperties::GetSettingName())) + { + const bool is_global_setting = true; + PluginManager::CreateSettingForJITLoaderPlugin(debugger, + GetGlobalPluginProperties()->GetValueProperties(), + ConstString ("Properties for the JIT LoaderGDB plug-in."), + is_global_setting); + } +} + void JITLoaderGDB::DidAttach() { Target &target = m_process->GetTarget(); @@ -88,7 +154,7 @@ JITLoaderGDB::ModulesDidLoad(ModuleList &module_list) { if (!DidSetJITBreakpoint() && m_process->IsAlive()) - SetJITBreakpoint(module_list); + SetJITBreakpoint(module_list); } //------------------------------------------------------------------ @@ -97,11 +163,13 @@ void JITLoaderGDB::SetJITBreakpoint(lldb_private::ModuleList &module_list) { - Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_JIT_LOADER)); + if (!GetGlobalPluginProperties()->GetEnableJITBreakpoint()) + return; if ( DidSetJITBreakpoint() ) return; + Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_JIT_LOADER)); if (log) log->Printf("JITLoaderGDB::%s looking for JIT register hook", __FUNCTION__); @@ -407,7 +475,8 @@ { PluginManager::RegisterPlugin (GetPluginNameStatic(), GetPluginDescriptionStatic(), - CreateInstance); + CreateInstance, + DebuggerInitialize); } void