Add support for listing inferior thread names on Linux.

llvm-svn: 186033
diff --git a/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp b/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp
index 09f0525..e55ba26 100644
--- a/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp
+++ b/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp
@@ -41,7 +41,9 @@
 
 POSIXThread::POSIXThread(Process &process, lldb::tid_t tid)
     : Thread(process, tid),
-      m_frame_ap()
+      m_frame_ap (),
+      m_breakpoint (),
+      m_thread_name ()
 {
     Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
     if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
@@ -104,6 +106,23 @@
     return NULL;
 }
 
+void
+POSIXThread::SetName (const char *name)
+{
+    if (name && name[0])
+        m_thread_name.assign (name);
+    else
+        m_thread_name.clear();
+}
+
+const char *
+POSIXThread::GetName ()
+{
+    if (m_thread_name.empty())
+        return NULL;
+    return m_thread_name.c_str();
+}
+
 lldb::RegisterContextSP
 POSIXThread::GetRegisterContext()
 {
diff --git a/lldb/source/Plugins/Process/POSIX/POSIXThread.h b/lldb/source/Plugins/Process/POSIX/POSIXThread.h
index d0c081f..59b02a7 100644
--- a/lldb/source/Plugins/Process/POSIX/POSIXThread.h
+++ b/lldb/source/Plugins/Process/POSIX/POSIXThread.h
@@ -13,6 +13,7 @@
 // C Includes
 // C++ Includes
 #include <memory>
+#include <string>
 
 // Other libraries and framework includes
 #include "lldb/Target/Thread.h"
@@ -46,6 +47,12 @@
     const char *
     GetInfo();
 
+    void
+    SetName (const char *name);
+
+    const char *
+    GetName ();
+
     virtual lldb::RegisterContextSP
     GetRegisterContext();
 
@@ -100,6 +107,8 @@
 
     lldb::BreakpointSiteSP m_breakpoint;
 
+    std::string m_thread_name;
+
     ProcessMonitor &
     GetMonitor();
 
diff --git a/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp b/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
index e09bfca..d55609a 100644
--- a/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
+++ b/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
@@ -491,8 +491,13 @@
         {
             if (log)
                 log->Printf ("ProcessPOSIX::%s() adding thread, tid = %" PRIi64, __FUNCTION__, message.GetChildTID());
+            lldb::tid_t child_tid = message.GetChildTID();
             ThreadSP thread_sp;
-            thread_sp.reset(new POSIXThread(*this, message.GetChildTID()));
+            thread_sp.reset(new POSIXThread(*this, child_tid));
+
+            POSIXThread *thread = static_cast<POSIXThread*>(thread_sp.get());
+            thread->SetName(Host::GetThreadName(GetID(), child_tid).c_str());
+
             m_thread_list.AddThread(thread_sp);
         }