diff options
author | Zachary Turner <zturner@google.com> | 2017-03-04 01:31:06 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-03-04 01:31:06 +0000 |
commit | ed96be99fa780edd51876f769b74252bfb2d8b1b (patch) | |
tree | ae9113a6f3f450d182cbc38ccbcb1337b07ca37d | |
parent | 2325bb34c1ce78849925eb43213116e5a74e8041 (diff) | |
download | bcm5719-llvm-ed96be99fa780edd51876f769b74252bfb2d8b1b.tar.gz bcm5719-llvm-ed96be99fa780edd51876f769b74252bfb2d8b1b.zip |
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.
llvm-svn: 296946
-rw-r--r-- | lldb/include/lldb/Host/Host.h | 8 | ||||
-rw-r--r-- | lldb/include/lldb/Host/ThisThread.h | 37 | ||||
-rw-r--r-- | lldb/source/Host/CMakeLists.txt | 6 | ||||
-rw-r--r-- | lldb/source/Host/common/Host.cpp | 21 | ||||
-rw-r--r-- | lldb/source/Host/common/HostNativeThreadBase.cpp | 5 | ||||
-rw-r--r-- | lldb/source/Host/common/ThisThread.cpp | 50 | ||||
-rw-r--r-- | lldb/source/Host/common/ThreadLauncher.cpp | 1 | ||||
-rw-r--r-- | lldb/source/Host/freebsd/ThisThread.cpp | 35 | ||||
-rw-r--r-- | lldb/source/Host/linux/ThisThread.cpp | 25 | ||||
-rw-r--r-- | lldb/source/Host/macosx/ThisThread.cpp | 25 | ||||
-rw-r--r-- | lldb/source/Host/netbsd/ThisThread.cpp | 26 | ||||
-rw-r--r-- | lldb/source/Host/windows/Host.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Host/windows/ThisThread.cpp | 63 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | 4 |
15 files changed, 7 insertions, 307 deletions
diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h index 64c0dd6cef6..91ca40dcb9e 100644 --- a/lldb/include/lldb/Host/Host.h +++ b/lldb/include/lldb/Host/Host.h @@ -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. diff --git a/lldb/include/lldb/Host/ThisThread.h b/lldb/include/lldb/Host/ThisThread.h deleted file mode 100644 index 1392b10e138..00000000000 --- a/lldb/include/lldb/Host/ThisThread.h +++ /dev/null @@ -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 diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index 5f011bd8cc5..4ac9300c311 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -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() diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index a5f70aa269f..6b958201c20 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -314,27 +314,6 @@ lldb::pid_t Host::GetCurrentProcessID() { return ::getpid(); } #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()); } diff --git a/lldb/source/Host/common/HostNativeThreadBase.cpp b/lldb/source/Host/common/HostNativeThreadBase.cpp index a39cc875378..402d3caacfc 100644 --- a/lldb/source/Host/common/HostNativeThreadBase.cpp +++ b/lldb/source/Host/common/HostNativeThreadBase.cpp @@ -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; diff --git a/lldb/source/Host/common/ThisThread.cpp b/lldb/source/Host/common/ThisThread.cpp deleted file mode 100644 index de87839b8b5..00000000000 --- a/lldb/source/Host/common/ThisThread.cpp +++ /dev/null @@ -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); -} diff --git a/lldb/source/Host/common/ThreadLauncher.cpp b/lldb/source/Host/common/ThreadLauncher.cpp index 71c3afb1ba8..32641efe408 100644 --- a/lldb/source/Host/common/ThreadLauncher.cpp +++ b/lldb/source/Host/common/ThreadLauncher.cpp @@ -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) diff --git a/lldb/source/Host/freebsd/ThisThread.cpp b/lldb/source/Host/freebsd/ThisThread.cpp deleted file mode 100644 index da0f2379a87..00000000000 --- a/lldb/source/Host/freebsd/ThisThread.cpp +++ /dev/null @@ -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 -} diff --git a/lldb/source/Host/linux/ThisThread.cpp b/lldb/source/Host/linux/ThisThread.cpp deleted file mode 100644 index f65440b9d77..00000000000 --- a/lldb/source/Host/linux/ThisThread.cpp +++ /dev/null @@ -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); -} diff --git a/lldb/source/Host/macosx/ThisThread.cpp b/lldb/source/Host/macosx/ThisThread.cpp deleted file mode 100644 index 5244ba01412..00000000000 --- a/lldb/source/Host/macosx/ThisThread.cpp +++ /dev/null @@ -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. -} diff --git a/lldb/source/Host/netbsd/ThisThread.cpp b/lldb/source/Host/netbsd/ThisThread.cpp deleted file mode 100644 index ea16981ef25..00000000000 --- a/lldb/source/Host/netbsd/ThisThread.cpp +++ /dev/null @@ -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); -} diff --git a/lldb/source/Host/windows/Host.cpp b/lldb/source/Host/windows/Host.cpp index b86cd3ea015..4505164e053 100644 --- a/lldb/source/Host/windows/Host.cpp +++ b/lldb/source/Host/windows/Host.cpp @@ -101,10 +101,6 @@ lldb::DataBufferSP Host::GetAuxvData(lldb_private::Process *process) { return 0; } -lldb::tid_t Host::GetCurrentThreadID() { - return lldb::tid_t(::GetCurrentThreadId()); -} - lldb::thread_t Host::GetCurrentThread() { return lldb::thread_t(::GetCurrentThread()); } diff --git a/lldb/source/Host/windows/ThisThread.cpp b/lldb/source/Host/windows/ThisThread.cpp deleted file mode 100644 index 6a11e5d1af9..00000000000 --- a/lldb/source/Host/windows/ThisThread.cpp +++ /dev/null @@ -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(); -} diff --git a/lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp b/lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp index d1b1bdda723..6107c5a9586 100644 --- a/lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp +++ b/lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp @@ -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(const CREATE_PROCESS_DEBUG_INFO &info, 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. diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 9559df90b3e..27d077e7e6d 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -72,7 +72,7 @@ void GDBRemoteCommunication::History::AddPacket(char packet_char, 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::AddPacket(const std::string &src, 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(); } } |