From 7f98240df65cfabd6d4bbf95907711f6a2734298 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Mon, 15 Jul 2013 22:54:20 +0000 Subject: [PATCH] Added a setting to control timeout for kdp response packets. While I was at it, I also added a way to control the response timeout for gdb-remote packets. KDP defaults to 5 seconds, and GDB defaults to 1 second. These were the default values that were in the code prior to adding these settings. (lldb) settings set plugin.process.gdb-remote.packet-timeout 10 (lldb) settings set plugin.process.kdp-remote.packet-timeout 10 llvm-svn: 186360 --- lldb/include/lldb/Core/PluginManager.h | 16 +++- lldb/source/Core/PluginManager.cpp | 106 +++++++++++++++------ .../Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp | 76 ++++++++++++++- .../Plugins/Process/MacOSX-Kernel/ProcessKDP.h | 3 + .../gdb-remote/GDBRemoteCommunicationClient.h | 8 -- .../Process/gdb-remote/ProcessGDBRemote.cpp | 78 ++++++++++++++- .../Plugins/Process/gdb-remote/ProcessGDBRemote.h | 3 + 7 files changed, 250 insertions(+), 40 deletions(-) diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h index c13a858..91f8fbb 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -234,7 +234,8 @@ public: static bool RegisterPlugin (const ConstString &name, const char *description, - ProcessCreateInstance create_callback); + ProcessCreateInstance create_callback, + DebuggerInitializeCallback debugger_init_callback = NULL); static bool UnregisterPlugin (ProcessCreateInstance create_callback); @@ -315,7 +316,7 @@ public: static lldb::OptionValuePropertiesSP GetSettingForDynamicLoaderPlugin (Debugger &debugger, - const ConstString &setting_name); + const ConstString &setting_name); static bool CreateSettingForDynamicLoaderPlugin (Debugger &debugger, @@ -332,6 +333,17 @@ public: const lldb::OptionValuePropertiesSP &properties_sp, const ConstString &description, bool is_global_property); + + static lldb::OptionValuePropertiesSP + GetSettingForProcessPlugin (Debugger &debugger, + const ConstString &setting_name); + + static bool + CreateSettingForProcessPlugin (Debugger &debugger, + const lldb::OptionValuePropertiesSP &properties_sp, + const ConstString &description, + bool is_global_property); + }; diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index a143b95d..7647b1b 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -1388,15 +1388,17 @@ PluginManager::AutoCompletePlatformName (const char *name, StringList &matches) struct ProcessInstance { ProcessInstance() : - name(), - description(), - create_callback(NULL) + name(), + description(), + create_callback(NULL), + debugger_init_callback(NULL) { } ConstString name; std::string description; ProcessCreateInstance create_callback; + DebuggerInitializeCallback debugger_init_callback; }; typedef std::vector ProcessInstances; @@ -1417,12 +1419,10 @@ GetProcessInstances () bool -PluginManager::RegisterPlugin -( - const ConstString &name, - const char *description, - ProcessCreateInstance create_callback - ) +PluginManager::RegisterPlugin (const ConstString &name, + const char *description, + ProcessCreateInstance create_callback, + DebuggerInitializeCallback debugger_init_callback) { if (create_callback) { @@ -1432,6 +1432,7 @@ PluginManager::RegisterPlugin if (description && description[0]) instance.description = description; instance.create_callback = create_callback; + instance.debugger_init_callback = debugger_init_callback; Mutex::Locker locker (GetProcessMutex ()); GetProcessInstances ().push_back (instance); } @@ -1851,13 +1852,26 @@ PluginManager::DebuggerInitialize (Debugger &debugger) pos->debugger_init_callback (debugger); } } + + // Initialize the Process plugins + { + Mutex::Locker locker (GetProcessMutex()); + ProcessInstances &instances = GetProcessInstances(); + + ProcessInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (pos->debugger_init_callback) + pos->debugger_init_callback (debugger); + } + } + } -// This will put a plugin's settings under e.g. "plugin.dynamic-loader.darwin-kernel.SETTINGNAME". -// The new preferred ordering is to put plugins under "dynamic-loader.plugin.darwin-kernel.SETTINGNAME" -// and if there were a generic dynamic-loader setting, it would be "dynamic-loader.SETTINGNAME". +// This is the preferred new way to register plugin specific settings. e.g. +// This will put a plugin's settings under e.g. "plugin...SETTINGNAME". static lldb::OptionValuePropertiesSP -GetDebuggerPropertyForPluginsOldStyle (Debugger &debugger, +GetDebuggerPropertyForPlugins (Debugger &debugger, const ConstString &plugin_type_name, const ConstString &plugin_type_desc, bool can_create) @@ -1894,14 +1908,14 @@ GetDebuggerPropertyForPluginsOldStyle (Debugger &debugger, return lldb::OptionValuePropertiesSP(); } -// This is the preferred new way to register plugin specific settings. e.g. -// "platform.plugin.darwin-kernel.SETTINGNAME" +// This is deprecated way to register plugin specific settings. e.g. +// ".plugin..SETTINGNAME" // and Platform generic settings would be under "platform.SETTINGNAME". static lldb::OptionValuePropertiesSP -GetDebuggerPropertyForPlugins (Debugger &debugger, - const ConstString &plugin_type_name, - const ConstString &plugin_type_desc, - bool can_create) +GetDebuggerPropertyForPluginsOldStyle (Debugger &debugger, + const ConstString &plugin_type_name, + const ConstString &plugin_type_desc, + bool can_create) { static ConstString g_property_name("plugin"); lldb::OptionValuePropertiesSP parent_properties_sp (debugger.GetValueProperties()); @@ -1939,7 +1953,7 @@ lldb::OptionValuePropertiesSP PluginManager::GetSettingForDynamicLoaderPlugin (Debugger &debugger, const ConstString &setting_name) { lldb::OptionValuePropertiesSP properties_sp; - lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPluginsOldStyle (debugger, + lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPlugins (debugger, ConstString("dynamic-loader"), ConstString(), // not creating to so we don't need the description false)); @@ -1956,7 +1970,7 @@ PluginManager::CreateSettingForDynamicLoaderPlugin (Debugger &debugger, { if (properties_sp) { - lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPluginsOldStyle (debugger, + lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPlugins (debugger, ConstString("dynamic-loader"), ConstString("Settings for dynamic loader plug-ins"), true)); @@ -1977,10 +1991,10 @@ lldb::OptionValuePropertiesSP PluginManager::GetSettingForPlatformPlugin (Debugger &debugger, const ConstString &setting_name) { lldb::OptionValuePropertiesSP properties_sp; - lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPlugins (debugger, - ConstString("platform"), - ConstString(), // not creating to so we don't need the description - false)); + 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; @@ -1994,9 +2008,47 @@ PluginManager::CreateSettingForPlatformPlugin (Debugger &debugger, { 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; +} + + +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; +} + +bool +PluginManager::CreateSettingForProcessPlugin (Debugger &debugger, + const lldb::OptionValuePropertiesSP &properties_sp, + const ConstString &description, + bool is_global_property) +{ + if (properties_sp) + { lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPlugins (debugger, - ConstString("platform"), - ConstString("Settings for platform plug-ins"), + ConstString("process"), + ConstString("Settings for process plug-ins"), true)); if (plugin_type_properties_sp) { diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp index 1685517..a30b7ff 100644 --- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp @@ -44,6 +44,63 @@ using namespace lldb; using namespace lldb_private; +namespace { + + static PropertyDefinition + g_properties[] = + { + { "packet-timeout" , OptionValue::eTypeUInt64 , true , 5, NULL, NULL, "Specify the default packet timeout in seconds." }, + { NULL , OptionValue::eTypeInvalid, false, 0, NULL, NULL, NULL } + }; + + enum + { + ePropertyPacketTimeout + }; + + class PluginProperties : public Properties + { + public: + + static ConstString + GetSettingName () + { + return ProcessKDP::GetPluginNameStatic(); + } + + PluginProperties() : + Properties () + { + m_collection_sp.reset (new OptionValueProperties(GetSettingName())); + m_collection_sp->Initialize(g_properties); + } + + virtual + ~PluginProperties() + { + } + + uint64_t + GetPacketTimeout() + { + const uint32_t idx = ePropertyPacketTimeout; + return m_collection_sp->GetPropertyAtIndexAsUInt64(NULL, idx, g_properties[idx].default_uint_value); + } + }; + + typedef std::shared_ptr ProcessKDPPropertiesSP; + + static const ProcessKDPPropertiesSP & + GetGlobalPluginProperties() + { + static ProcessKDPPropertiesSP g_settings_sp; + if (!g_settings_sp) + g_settings_sp.reset (new PluginProperties ()); + return g_settings_sp; + } + +} // anonymous namespace end + static const lldb::tid_t g_kernel_tid = 1; ConstString @@ -124,6 +181,9 @@ ProcessKDP::ProcessKDP(Target& target, Listener &listener) : { m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadShouldExit, "async thread should exit"); m_async_broadcaster.SetEventName (eBroadcastBitAsyncContinue, "async thread continue"); + const uint64_t timeout_seconds = GetGlobalPluginProperties()->GetPacketTimeout(); + if (timeout_seconds > 0) + m_comm.SetPacketTimeout(timeout_seconds); } //---------------------------------------------------------------------- @@ -716,7 +776,8 @@ ProcessKDP::Initialize() g_initialized = true; PluginManager::RegisterPlugin (GetPluginNameStatic(), GetPluginDescriptionStatic(), - CreateInstance); + CreateInstance, + DebuggerInitialize); Log::Callbacks log_callbacks = { ProcessKDPLog::DisableLog, @@ -728,6 +789,19 @@ ProcessKDP::Initialize() } } +void +ProcessKDP::DebuggerInitialize (lldb_private::Debugger &debugger) +{ + if (!PluginManager::GetSettingForProcessPlugin(debugger, PluginProperties::GetSettingName())) + { + const bool is_global_setting = true; + PluginManager::CreateSettingForProcessPlugin (debugger, + GetGlobalPluginProperties()->GetValueProperties(), + ConstString ("Properties for the kdp-remote process plug-in."), + is_global_setting); + } +} + bool ProcessKDP::StartAsyncThread () { diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h index da2ee3f..5099040 100644 --- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h @@ -48,6 +48,9 @@ public: Initialize(); static void + DebuggerInitialize (lldb_private::Debugger &debugger); + + static void Terminate(); static lldb_private::ConstString diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index 4075eeb..5bb8387 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -285,14 +285,6 @@ public: return GetVContSupported ('a'); } - uint32_t - SetPacketTimeout (uint32_t packet_timeout) - { - const uint32_t old_packet_timeout = m_packet_timeout; - m_packet_timeout = packet_timeout; - return old_packet_timeout; - } - bool GetStopReply (StringExtractorGDBRemote &response); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 4a2899d..d27207f 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -83,11 +83,68 @@ namespace lldb } } - #define DEBUGSERVER_BASENAME "debugserver" using namespace lldb; using namespace lldb_private; + +namespace { + + static PropertyDefinition + g_properties[] = + { + { "packet-timeout" , OptionValue::eTypeUInt64 , true , 1, NULL, NULL, "Specify the default packet timeout in seconds." }, + { NULL , OptionValue::eTypeInvalid, false, 0, NULL, NULL, NULL } + }; + + enum + { + ePropertyPacketTimeout + }; + + class PluginProperties : public Properties + { + public: + + static ConstString + GetSettingName () + { + return ProcessGDBRemote::GetPluginNameStatic(); + } + + PluginProperties() : + Properties () + { + m_collection_sp.reset (new OptionValueProperties(GetSettingName())); + m_collection_sp->Initialize(g_properties); + } + + virtual + ~PluginProperties() + { + } + + uint64_t + GetPacketTimeout() + { + const uint32_t idx = ePropertyPacketTimeout; + return m_collection_sp->GetPropertyAtIndexAsUInt64(NULL, idx, g_properties[idx].default_uint_value); + } + }; + + typedef std::shared_ptr ProcessKDPPropertiesSP; + + static const ProcessKDPPropertiesSP & + GetGlobalPluginProperties() + { + static ProcessKDPPropertiesSP g_settings_sp; + if (!g_settings_sp) + g_settings_sp.reset (new PluginProperties ()); + return g_settings_sp; + } + +} // anonymous namespace end + static bool rand_initialized = false; // TODO Randomly assigning a port is unsafe. We should get an unused @@ -208,6 +265,9 @@ ProcessGDBRemote::ProcessGDBRemote(Target& target, Listener &listener) : m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadShouldExit, "async thread should exit"); m_async_broadcaster.SetEventName (eBroadcastBitAsyncContinue, "async thread continue"); m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadDidExit, "async thread did exit"); + const uint64_t timeout_seconds = GetGlobalPluginProperties()->GetPacketTimeout(); + if (timeout_seconds > 0) + m_gdb_comm.SetPacketTimeout(timeout_seconds); } //---------------------------------------------------------------------- @@ -2642,7 +2702,8 @@ ProcessGDBRemote::Initialize() g_initialized = true; PluginManager::RegisterPlugin (GetPluginNameStatic(), GetPluginDescriptionStatic(), - CreateInstance); + CreateInstance, + DebuggerInitialize); Log::Callbacks log_callbacks = { ProcessGDBRemoteLog::DisableLog, @@ -2654,6 +2715,19 @@ ProcessGDBRemote::Initialize() } } +void +ProcessGDBRemote::DebuggerInitialize (lldb_private::Debugger &debugger) +{ + if (!PluginManager::GetSettingForProcessPlugin(debugger, PluginProperties::GetSettingName())) + { + const bool is_global_setting = true; + PluginManager::CreateSettingForProcessPlugin (debugger, + GetGlobalPluginProperties()->GetValueProperties(), + ConstString ("Properties for the gdb-remote process plug-in."), + is_global_setting); + } +} + bool ProcessGDBRemote::StartAsyncThread () { diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h index ab8fef3..e104b71 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h @@ -49,6 +49,9 @@ public: Initialize(); static void + DebuggerInitialize (lldb_private::Debugger &debugger); + + static void Terminate(); static lldb_private::ConstString -- 2.7.4