Add Host::MAX_THREAD_NAME_LENGTH constant.
authorTodd Fiala <todd.fiala@gmail.com>
Wed, 16 Jul 2014 19:03:16 +0000 (19:03 +0000)
committerTodd Fiala <todd.fiala@gmail.com>
Wed, 16 Jul 2014 19:03:16 +0000 (19:03 +0000)
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
lldb/source/Host/common/Host.cpp
lldb/source/Target/Process.cpp

index 92349f9..1203f1c 100644 (file)
@@ -32,6 +32,10 @@ namespace lldb_private {
 class Host
 {
 public:
+
+    /// A value of std::numeric_limits<uint32_t>::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,
index 5c8d382..79ae92a 100644 (file)
@@ -49,6 +49,9 @@
 #include <pthread_np.h>
 #endif
 
+// C++ includes
+#include <limits>
+
 #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<uint32_t>::max ();
+#endif
 
 #if !defined (__APPLE__) && !defined (_WIN32)
 struct MonitorInfo
index 58c6df7..20947b9 100644 (file)
@@ -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), "<lldb.process.internal-state-override(pid=%" PRIu64 ")>", 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), "<lldb.process.internal-state(pid=%" PRIu64 ")>", GetID());
-        
+    {
+        if (already_running)
+                snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state-override(pid=%" PRIu64 ")>", GetID());
+        else
+                snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state(pid=%" PRIu64 ")>", 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);