diff options
Diffstat (limited to 'lldb/source/Host/windows')
| -rw-r--r-- | lldb/source/Host/windows/Host.cpp | 51 | ||||
| -rw-r--r-- | lldb/source/Host/windows/HostThreadWindows.cpp | 80 | ||||
| -rw-r--r-- | lldb/source/Host/windows/ThisThread.cpp | 60 |
3 files changed, 143 insertions, 48 deletions
diff --git a/lldb/source/Host/windows/Host.cpp b/lldb/source/Host/windows/Host.cpp index bc0f48b49c7..4542025f6ee 100644 --- a/lldb/source/Host/windows/Host.cpp +++ b/lldb/source/Host/windows/Host.cpp @@ -110,12 +110,6 @@ Host::GetAuxvData(lldb_private::Process *process) return 0; } -std::string -Host::GetThreadName (lldb::pid_t pid, lldb::tid_t tid) -{ - return std::string(); -} - lldb::tid_t Host::GetCurrentThreadID() { @@ -128,26 +122,6 @@ Host::GetCurrentThread () return lldb::thread_t(::GetCurrentThread()); } -bool -Host::ThreadCancel (lldb::thread_t thread, Error *error) -{ - int err = ::TerminateThread((HANDLE)thread, 0); - return err == 0; -} - -bool -Host::ThreadDetach (lldb::thread_t thread, Error *error) -{ - return ThreadCancel(thread, error); -} - -bool -Host::ThreadJoin (lldb::thread_t thread, thread_result_t *thread_result_ptr, Error *error) -{ - WaitForSingleObject((HANDLE) thread, INFINITE); - return true; -} - lldb::thread_key_t Host::ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback) { @@ -166,19 +140,6 @@ Host::ThreadLocalStorageSet(lldb::thread_key_t key, void *value) ::TlsSetValue (key, value); } -bool -Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name) -{ - return false; -} - -bool -Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid, - const char *thread_name, size_t len) -{ - return false; -} - void Host::Kill(lldb::pid_t pid, int signo) { @@ -260,14 +221,8 @@ Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info) return true; } -lldb::thread_t -Host::StartMonitoringChildProcess -( - Host::MonitorChildProcessCallback callback, - void *callback_baton, - lldb::pid_t pid, - bool monitor_signals -) +HostThread +Host::StartMonitoringChildProcess(Host::MonitorChildProcessCallback callback, void *callback_baton, lldb::pid_t pid, bool monitor_signals) { - return LLDB_INVALID_HOST_THREAD; + return HostThread(); }
\ No newline at end of file diff --git a/lldb/source/Host/windows/HostThreadWindows.cpp b/lldb/source/Host/windows/HostThreadWindows.cpp new file mode 100644 index 00000000000..5d526cc2530 --- /dev/null +++ b/lldb/source/Host/windows/HostThreadWindows.cpp @@ -0,0 +1,80 @@ +//===-- HostThreadWindows.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/Core/Error.h" + +#include "lldb/Host/windows/windows.h" +#include "lldb/Host/windows/HostThreadWindows.h" + +#include "llvm/ADT/STLExtras.h" + +using namespace lldb; +using namespace lldb_private; + +HostThreadWindows::HostThreadWindows() + : HostNativeThreadBase() +{ +} + +HostThreadWindows::HostThreadWindows(lldb::thread_t thread) + : HostNativeThreadBase(thread) +{ +} + +HostThreadWindows::~HostThreadWindows() +{ + Reset(); +} + +Error +HostThreadWindows::Join(lldb::thread_result_t *result) +{ + Error error; + if (WAIT_OBJECT_0 != ::WaitForSingleObject(m_thread, INFINITE)) + { + error.SetError(::GetLastError(), lldb::eErrorTypeWin32); + return error; + } + + m_state = (m_state == eThreadStateCancelling) ? eThreadStateCancelled : eThreadStateExited; + + if (result) + { + DWORD dword_result = 0; + if (!::GetExitCodeThread(m_thread, &dword_result)) + *result = 0; + *result = dword_result; + } + return error; +} + +Error +HostThreadWindows::Cancel() +{ + Error error; + + DWORD result = ::QueueUserAPC(::ExitThread, m_thread, 0); + error.SetError(result, eErrorTypeWin32); + return error; +} + +lldb::tid_t +HostThreadWindows::GetThreadId() const +{ + return ::GetThreadId(m_thread); +} + +void +HostThreadWindows::Reset() +{ + if (m_thread != LLDB_INVALID_HOST_THREAD) + ::CloseHandle(m_thread); + + HostNativeThreadBase::Reset(); +} diff --git a/lldb/source/Host/windows/ThisThread.cpp b/lldb/source/Host/windows/ThisThread.cpp new file mode 100644 index 00000000000..9c37d7c57e7 --- /dev/null +++ b/lldb/source/Host/windows/ThisThread.cpp @@ -0,0 +1,60 @@ +//===-- 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/Core/Error.h" + +#include "lldb/Host/windows/windows.h" +#include "lldb/Host/ThisThread.h" + +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" + +using namespace lldb; +using namespace lldb_private; + +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) +} + +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) + 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(); +} |

