forked from OSchip/llvm-project
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
This commit is contained in:
parent
2325bb34c1
commit
ed96be99fa
|
@ -99,14 +99,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
|
||||
|
|
|
@ -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
|
|
@ -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()
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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.
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue