[Lldb-commits] [lldb] r296946 - Delete LLDB's code for getting / setting thread name.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 3 17:31:06 PST 2017


Author: zturner
Date: Fri Mar  3 19:31:06 2017
New Revision: 296946

URL: http://llvm.org/viewvc/llvm-project?rev=296946&view=rev
Log:
Delete LLDB's code for getting / setting thread name.

This is now functionality in LLVM, and all callers have
already been updated to use the LLVM functions.

Removed:
    lldb/trunk/include/lldb/Host/ThisThread.h
    lldb/trunk/source/Host/common/ThisThread.cpp
    lldb/trunk/source/Host/freebsd/ThisThread.cpp
    lldb/trunk/source/Host/linux/ThisThread.cpp
    lldb/trunk/source/Host/macosx/ThisThread.cpp
    lldb/trunk/source/Host/netbsd/ThisThread.cpp
    lldb/trunk/source/Host/windows/ThisThread.cpp
Modified:
    lldb/trunk/include/lldb/Host/Host.h
    lldb/trunk/source/Host/CMakeLists.txt
    lldb/trunk/source/Host/common/Host.cpp
    lldb/trunk/source/Host/common/HostNativeThreadBase.cpp
    lldb/trunk/source/Host/common/ThreadLauncher.cpp
    lldb/trunk/source/Host/windows/Host.cpp
    lldb/trunk/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp

Modified: lldb/trunk/include/lldb/Host/Host.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=296946&r1=296945&r2=296946&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Host.h (original)
+++ lldb/trunk/include/lldb/Host/Host.h Fri Mar  3 19:31:06 2017
@@ -100,14 +100,6 @@ public:
   static void Kill(lldb::pid_t pid, int signo);
 
   //------------------------------------------------------------------
-  /// Get the thread ID for the calling thread in the current process.
-  ///
-  /// @return
-  ///     The thread ID for the calling thread in the current process.
-  //------------------------------------------------------------------
-  static lldb::tid_t GetCurrentThreadID();
-
-  //------------------------------------------------------------------
   /// Get the thread token (the one returned by ThreadCreate when the thread was
   /// created) for the
   /// calling thread in the current process.

Removed: lldb/trunk/include/lldb/Host/ThisThread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/ThisThread.h?rev=296945&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Host/ThisThread.h (original)
+++ lldb/trunk/include/lldb/Host/ThisThread.h (removed)
@@ -1,37 +0,0 @@
-//===-- ThisThread.h --------------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef lldb_Host_ThisThread_h_
-#define lldb_Host_ThisThread_h_
-
-#include "llvm/ADT/StringRef.h"
-
-#include <string>
-
-namespace llvm {
-template <class T> class SmallVectorImpl;
-}
-
-namespace lldb_private {
-
-class ThisThread {
-private:
-  ThisThread();
-
-public:
-  // ThisThread common functions.
-  static void SetName(llvm::StringRef name, int max_length);
-
-  // ThisThread platform-specific functions.
-  static void SetName(llvm::StringRef name);
-  static void GetName(llvm::SmallVectorImpl<char> &name);
-};
-}
-
-#endif

Modified: lldb/trunk/source/Host/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/CMakeLists.txt?rev=296946&r1=296945&r2=296946&view=diff
==============================================================================
--- lldb/trunk/source/Host/CMakeLists.txt (original)
+++ lldb/trunk/source/Host/CMakeLists.txt Fri Mar  3 19:31:06 2017
@@ -35,7 +35,6 @@ add_host_subdirectory(common
   common/Symbols.cpp
   common/TCPSocket.cpp
   common/Terminal.cpp
-  common/ThisThread.cpp
   common/ThreadLauncher.cpp
   common/XML.cpp
   common/UDPSocket.cpp
@@ -73,7 +72,6 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows")
     windows/PipeWindows.cpp
     windows/ProcessLauncherWindows.cpp
     windows/ProcessRunLock.cpp
-    windows/ThisThread.cpp
     windows/Windows.cpp
     )
 else()
@@ -107,7 +105,6 @@ else()
       macosx/HostInfoMacOSX.mm
       macosx/HostThreadMacOSX.mm
       macosx/Symbols.cpp
-      macosx/ThisThread.cpp
       macosx/cfcpp/CFCBundle.cpp
       macosx/cfcpp/CFCData.cpp
       macosx/cfcpp/CFCMutableArray.cpp
@@ -124,7 +121,6 @@ else()
       linux/HostInfoLinux.cpp
       linux/HostThreadLinux.cpp
       linux/LibcGlue.cpp
-      linux/ThisThread.cpp
       )
     list(APPEND LLDB_PLUGINS lldbPluginProcessLinux)
     if (CMAKE_SYSTEM_NAME MATCHES "Android")
@@ -138,7 +134,6 @@ else()
       freebsd/Host.cpp
       freebsd/HostInfoFreeBSD.cpp
       freebsd/HostThreadFreeBSD.cpp
-      freebsd/ThisThread.cpp
       )
 
   elseif (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
@@ -146,7 +141,6 @@ else()
       netbsd/Host.cpp
       netbsd/HostInfoNetBSD.cpp
       netbsd/HostThreadNetBSD.cpp
-      netbsd/ThisThread.cpp
       )
   endif()
 endif()

Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=296946&r1=296945&r2=296946&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Fri Mar  3 19:31:06 2017
@@ -314,27 +314,6 @@ lldb::pid_t Host::GetCurrentProcessID()
 
 #ifndef _WIN32
 
-lldb::tid_t Host::GetCurrentThreadID() {
-#if defined(__APPLE__)
-  // Calling "mach_thread_self()" bumps the reference count on the thread
-  // port, so we need to deallocate it. mach_task_self() doesn't bump the ref
-  // count.
-  thread_port_t thread_self = mach_thread_self();
-  mach_port_deallocate(mach_task_self(), thread_self);
-  return thread_self;
-#elif defined(__FreeBSD__)
-  return lldb::tid_t(pthread_getthreadid_np());
-#elif defined(__NetBSD__)
-  return lldb::tid_t(_lwp_self());
-#elif defined(__ANDROID__)
-  return lldb::tid_t(gettid());
-#elif defined(__linux__)
-  return lldb::tid_t(syscall(SYS_gettid));
-#else
-  return lldb::tid_t(pthread_self());
-#endif
-}
-
 lldb::thread_t Host::GetCurrentThread() {
   return lldb::thread_t(pthread_self());
 }

Modified: lldb/trunk/source/Host/common/HostNativeThreadBase.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostNativeThreadBase.cpp?rev=296946&r1=296945&r2=296946&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/HostNativeThreadBase.cpp (original)
+++ lldb/trunk/source/Host/common/HostNativeThreadBase.cpp Fri Mar  3 19:31:06 2017
@@ -9,10 +9,11 @@
 
 #include "lldb/Host/HostNativeThreadBase.h"
 #include "lldb/Host/HostInfo.h"
-#include "lldb/Host/ThisThread.h"
 #include "lldb/Host/ThreadLauncher.h"
 #include "lldb/Utility/Log.h"
+
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Threading.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -52,7 +53,7 @@ lldb::thread_result_t
 HostNativeThreadBase::ThreadCreateTrampoline(lldb::thread_arg_t arg) {
   ThreadLauncher::HostThreadCreateInfo *info =
       (ThreadLauncher::HostThreadCreateInfo *)arg;
-  ThisThread::SetName(info->thread_name, HostInfo::GetMaxThreadNameLength());
+  llvm::set_thread_name(info->thread_name);
 
   thread_func_t thread_fptr = info->thread_fptr;
   thread_arg_t thread_arg = info->thread_arg;

Removed: lldb/trunk/source/Host/common/ThisThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/ThisThread.cpp?rev=296945&view=auto
==============================================================================
--- lldb/trunk/source/Host/common/ThisThread.cpp (original)
+++ lldb/trunk/source/Host/common/ThisThread.cpp (removed)
@@ -1,50 +0,0 @@
-//===-- ThisThread.cpp ------------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Host/ThisThread.h"
-#include "lldb/Host/HostInfo.h"
-#include "lldb/Utility/Error.h"
-
-#include "llvm/ADT/STLExtras.h"
-
-#include <algorithm>
-
-using namespace lldb;
-using namespace lldb_private;
-
-void ThisThread::SetName(llvm::StringRef name, int max_length) {
-  std::string truncated_name(name.data());
-
-  // Thread names are coming in like '<lldb.comm.debugger.edit>' and
-  // '<lldb.comm.debugger.editline>'.  So just chopping the end of the string
-  // off leads to a lot of similar named threads.  Go through the thread name
-  // and search for the last dot and use that.
-
-  if (max_length > 0 &&
-      truncated_name.length() > static_cast<size_t>(max_length)) {
-    // First see if we can get lucky by removing any initial or final braces.
-    std::string::size_type begin = truncated_name.find_first_not_of("(<");
-    std::string::size_type end = truncated_name.find_last_not_of(")>.");
-    if (end - begin > static_cast<size_t>(max_length)) {
-      // We're still too long.  Since this is a dotted component, use everything
-      // after the last
-      // dot, up to a maximum of |length| characters.
-      std::string::size_type last_dot = truncated_name.rfind('.');
-      if (last_dot != std::string::npos)
-        begin = last_dot + 1;
-
-      end = std::min(end, begin + max_length);
-    }
-
-    std::string::size_type count = end - begin + 1;
-    truncated_name = truncated_name.substr(begin, count);
-  }
-
-  SetName(truncated_name);
-}

Modified: lldb/trunk/source/Host/common/ThreadLauncher.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/ThreadLauncher.cpp?rev=296946&r1=296945&r2=296946&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/ThreadLauncher.cpp (original)
+++ lldb/trunk/source/Host/common/ThreadLauncher.cpp Fri Mar  3 19:31:06 2017
@@ -12,7 +12,6 @@
 #include "lldb/Host/ThreadLauncher.h"
 #include "lldb/Host/HostNativeThread.h"
 #include "lldb/Host/HostThread.h"
-#include "lldb/Host/ThisThread.h"
 #include "lldb/Utility/Log.h"
 
 #if defined(_WIN32)

Removed: lldb/trunk/source/Host/freebsd/ThisThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/freebsd/ThisThread.cpp?rev=296945&view=auto
==============================================================================
--- lldb/trunk/source/Host/freebsd/ThisThread.cpp (original)
+++ lldb/trunk/source/Host/freebsd/ThisThread.cpp (removed)
@@ -1,35 +0,0 @@
-//===-- ThisThread.cpp ------------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Host/ThisThread.h"
-#include "lldb/Host/HostNativeThread.h"
-
-#include "llvm/ADT/SmallVector.h"
-
-#include <pthread.h>
-#if defined(__FreeBSD__)
-#include <pthread_np.h>
-#endif
-
-using namespace lldb_private;
-
-void ThisThread::SetName(llvm::StringRef name) {
-#if defined(__FreeBSD__) // Kfreebsd does not have a simple alternative
-  ::pthread_set_name_np(::pthread_self(), name.data());
-#endif
-}
-
-void ThisThread::GetName(llvm::SmallVectorImpl<char> &name) {
-#if defined(__FreeBSD__)
-  HostNativeThread::GetName(::pthread_getthreadid_np(), name);
-#else
-  // Kfreebsd
-  HostNativeThread::GetName((unsigned)pthread_self(), name);
-#endif
-}

Removed: lldb/trunk/source/Host/linux/ThisThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/ThisThread.cpp?rev=296945&view=auto
==============================================================================
--- lldb/trunk/source/Host/linux/ThisThread.cpp (original)
+++ lldb/trunk/source/Host/linux/ThisThread.cpp (removed)
@@ -1,25 +0,0 @@
-//===-- ThisThread.cpp ------------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Host/ThisThread.h"
-#include "lldb/Host/HostNativeThread.h"
-
-#include "llvm/ADT/SmallVector.h"
-
-#include <pthread.h>
-
-using namespace lldb_private;
-
-void ThisThread::SetName(llvm::StringRef name) {
-  HostNativeThread::SetName(::pthread_self(), name);
-}
-
-void ThisThread::GetName(llvm::SmallVectorImpl<char> &name) {
-  HostNativeThread::GetName(::pthread_self(), name);
-}

Removed: lldb/trunk/source/Host/macosx/ThisThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/ThisThread.cpp?rev=296945&view=auto
==============================================================================
--- lldb/trunk/source/Host/macosx/ThisThread.cpp (original)
+++ lldb/trunk/source/Host/macosx/ThisThread.cpp (removed)
@@ -1,25 +0,0 @@
-//===-- ThisThread.cpp ------------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Host/ThisThread.h"
-
-#include "llvm/ADT/SmallVector.h"
-#include <pthread.h>
-
-using namespace lldb_private;
-
-void ThisThread::SetName(llvm::StringRef name) {
-#if defined(__APPLE__)
-  ::pthread_setname_np(name.str().c_str());
-#endif
-}
-
-void ThisThread::GetName(llvm::SmallVectorImpl<char> &name) {
-  // FIXME - implement this.
-}

Removed: lldb/trunk/source/Host/netbsd/ThisThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/netbsd/ThisThread.cpp?rev=296945&view=auto
==============================================================================
--- lldb/trunk/source/Host/netbsd/ThisThread.cpp (original)
+++ lldb/trunk/source/Host/netbsd/ThisThread.cpp (removed)
@@ -1,26 +0,0 @@
-//===-- ThisThread.cpp ------------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Host/ThisThread.h"
-#include "lldb/Host/HostNativeThread.h"
-
-#include "llvm/ADT/SmallVector.h"
-
-#include <pthread.h>
-#include <string.h>
-
-using namespace lldb_private;
-
-void ThisThread::SetName(llvm::StringRef name) {
-  HostNativeThread::SetName(::pthread_self(), name);
-}
-
-void ThisThread::GetName(llvm::SmallVectorImpl<char> &name) {
-  HostNativeThread::GetName(::pthread_self(), name);
-}

Modified: lldb/trunk/source/Host/windows/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/Host.cpp?rev=296946&r1=296945&r2=296946&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/Host.cpp (original)
+++ lldb/trunk/source/Host/windows/Host.cpp Fri Mar  3 19:31:06 2017
@@ -101,10 +101,6 @@ lldb::DataBufferSP Host::GetAuxvData(lld
   return 0;
 }
 
-lldb::tid_t Host::GetCurrentThreadID() {
-  return lldb::tid_t(::GetCurrentThreadId());
-}
-
 lldb::thread_t Host::GetCurrentThread() {
   return lldb::thread_t(::GetCurrentThread());
 }

Removed: lldb/trunk/source/Host/windows/ThisThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/ThisThread.cpp?rev=296945&view=auto
==============================================================================
--- lldb/trunk/source/Host/windows/ThisThread.cpp (original)
+++ lldb/trunk/source/Host/windows/ThisThread.cpp (removed)
@@ -1,63 +0,0 @@
-//===-- ThisThread.cpp ------------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Utility/Error.h"
-
-#include "lldb/Host/ThisThread.h"
-#include "lldb/Host/windows/windows.h"
-
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-#if defined(_MSC_VER) && !defined(__clang__)
-
-namespace {
-static const DWORD MS_VC_EXCEPTION = 0x406D1388;
-
-#pragma pack(push, 8)
-struct THREADNAME_INFO {
-  DWORD dwType;     // Must be 0x1000.
-  LPCSTR szName;    // Pointer to thread name
-  DWORD dwThreadId; // Thread ID (-1 == current thread)
-  DWORD dwFlags;    // Reserved.  Do not use.
-};
-#pragma pack(pop)
-}
-
-#endif
-
-void ThisThread::SetName(llvm::StringRef name) {
-// Other compilers don't yet support SEH, so we can only set the thread if
-// compiling with MSVC.
-// TODO(zturner): Once clang-cl supports SEH, relax this conditional.
-#if defined(_MSC_VER) && !defined(__clang__)
-  THREADNAME_INFO info;
-  info.dwType = 0x1000;
-  info.szName = name.data();
-  info.dwThreadId = ::GetCurrentThreadId();
-  info.dwFlags = 0;
-
-  __try {
-    ::RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR),
-                     (ULONG_PTR *)&info);
-  } __except (EXCEPTION_EXECUTE_HANDLER) {
-  }
-#endif
-}
-
-void ThisThread::GetName(llvm::SmallVectorImpl<char> &name) {
-  // Getting the thread name is not supported on Windows.
-  // TODO(zturner): In SetName(), make a TLS entry that contains the thread's
-  // name, and in this function
-  // try to extract that TLS entry.
-  name.clear();
-}

Modified: lldb/trunk/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/Common/DebuggerThread.cpp?rev=296946&r1=296945&r2=296946&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/Common/DebuggerThread.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Windows/Common/DebuggerThread.cpp Fri Mar  3 19:31:06 2017
@@ -14,7 +14,6 @@
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Host/FileSpec.h"
 #include "lldb/Host/Predicate.h"
-#include "lldb/Host/ThisThread.h"
 #include "lldb/Host/ThreadLauncher.h"
 #include "lldb/Host/windows/HostProcessWindows.h"
 #include "lldb/Host/windows/HostThreadWindows.h"
@@ -28,6 +27,7 @@
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/Threading.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace lldb;
@@ -406,7 +406,7 @@ DebuggerThread::HandleCreateProcessEvent
   llvm::raw_string_ostream name_stream(thread_name);
   name_stream << "lldb.plugin.process-windows.slave[" << process_id << "]";
   name_stream.flush();
-  ThisThread::SetName(thread_name.c_str());
+  llvm::set_thread_name(thread_name);
 
   // info.hProcess and info.hThread are closed automatically by Windows when
   // EXIT_PROCESS_DEBUG_EVENT is received.

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=296946&r1=296945&r2=296946&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Fri Mar  3 19:31:06 2017
@@ -72,7 +72,7 @@ void GDBRemoteCommunication::History::Ad
     m_packets[idx].type = type;
     m_packets[idx].bytes_transmitted = bytes_transmitted;
     m_packets[idx].packet_idx = m_total_packet_count;
-    m_packets[idx].tid = Host::GetCurrentThreadID();
+    m_packets[idx].tid = llvm::get_threadid();
   }
 }
 
@@ -87,7 +87,7 @@ void GDBRemoteCommunication::History::Ad
     m_packets[idx].type = type;
     m_packets[idx].bytes_transmitted = bytes_transmitted;
     m_packets[idx].packet_idx = m_total_packet_count;
-    m_packets[idx].tid = Host::GetCurrentThreadID();
+    m_packets[idx].tid = llvm::get_threadid();
   }
 }
 




More information about the lldb-commits mailing list