From 17096d7669051be0dc42b0058b5eb44d9d0c479a Mon Sep 17 00:00:00 2001 From: Todd Fiala Date: Wed, 16 Jul 2014 19:03:16 +0000 Subject: [PATCH] Add Host::MAX_THREAD_NAME_LENGTH constant. This value gets set to a max uint32_t value when there is no known limit; otherwise, it is set to a value appropriate for the platform. For the moment, only Linux, FreeBSD and NetBSD set it to 16. All other platforms set it to the max uint32_t value. Modifies the Process private state thread names to fit within a 16-character limit when the max thread name length is <= 16. These guarantee that the thread names can be distinguished within the first 16 characters. Prior to this change, those threads had names in the final dotted name segment that were not distinguishable within the first 16 characters. llvm-svn: 213183 --- lldb/include/lldb/Host/Host.h | 4 ++++ lldb/source/Host/common/Host.cpp | 9 +++++++++ lldb/source/Target/Process.cpp | 20 ++++++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h index 92349f9..1203f1c 100644 --- a/lldb/include/lldb/Host/Host.h +++ b/lldb/include/lldb/Host/Host.h @@ -32,6 +32,10 @@ namespace lldb_private { class Host { public: + + /// A value of std::numeric_limits::max() is used if there is no practical limit. + static const uint32_t MAX_THREAD_NAME_LENGTH; + typedef bool (*MonitorChildProcessCallback) (void *callback_baton, lldb::pid_t pid, bool exited, diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index 5c8d382..79ae92a 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -49,6 +49,9 @@ #include #endif +// C++ includes +#include + #include "lldb/Host/Host.h" #include "lldb/Core/ArchSpec.h" #include "lldb/Core/ConstString.h" @@ -87,6 +90,12 @@ extern "C" using namespace lldb; using namespace lldb_private; +// Define maximum thread name length +#if defined (__linux__) || defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__NetBSD__) +uint32_t const Host::MAX_THREAD_NAME_LENGTH = 16; +#else +uint32_t const Host::MAX_THREAD_NAME_LENGTH = std::numeric_limits::max (); +#endif #if !defined (__APPLE__) && !defined (_WIN32) struct MonitorInfo diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 58c6df7..20947b9 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -3657,11 +3657,23 @@ Process::StartPrivateStateThread (bool force) // Create a thread that watches our internal state and controls which // events make it to clients (into the DCProcess event queue). char thread_name[1024]; - if (already_running) - snprintf(thread_name, sizeof(thread_name), "", GetID()); + + if (Host::MAX_THREAD_NAME_LENGTH <= 16) + { + // On platforms with abbreviated thread name lengths, choose thread names that fit within the limit. + if (already_running) + snprintf(thread_name, sizeof(thread_name), "intern-state-OV"); + else + snprintf(thread_name, sizeof(thread_name), "intern-state"); + } else - snprintf(thread_name, sizeof(thread_name), "", GetID()); - + { + if (already_running) + snprintf(thread_name, sizeof(thread_name), "", GetID()); + else + snprintf(thread_name, sizeof(thread_name), "", GetID()); + } + // Create the private state thread, and start it running. m_private_state_thread = Host::ThreadCreate (thread_name, Process::PrivateStateThread, this, NULL); bool success = IS_VALID_LLDB_HOST_THREAD(m_private_state_thread); -- 2.7.4