1 //===-- ThisThread.cpp ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/Error.h"
12 #include "lldb/Host/ThisThread.h"
13 #include "lldb/Host/windows/windows.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/SmallVector.h"
19 using namespace lldb_private;
21 #if defined(_MSC_VER) && !defined(__clang__)
24 static const DWORD MS_VC_EXCEPTION = 0x406D1388;
27 struct THREADNAME_INFO {
28 DWORD dwType; // Must be 0x1000.
29 LPCSTR szName; // Pointer to thread name
30 DWORD dwThreadId; // Thread ID (-1 == current thread)
31 DWORD dwFlags; // Reserved. Do not use.
38 void ThisThread::SetName(llvm::StringRef name) {
39 // Other compilers don't yet support SEH, so we can only set the thread if
40 // compiling with MSVC.
41 // TODO(zturner): Once clang-cl supports SEH, relax this conditional.
42 #if defined(_MSC_VER) && !defined(__clang__)
45 info.szName = name.data();
46 info.dwThreadId = ::GetCurrentThreadId();
50 ::RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR),
52 } __except (EXCEPTION_EXECUTE_HANDLER) {
57 void ThisThread::GetName(llvm::SmallVectorImpl<char> &name) {
58 // Getting the thread name is not supported on Windows.
59 // TODO(zturner): In SetName(), make a TLS entry that contains the thread's
60 // name, and in this function
61 // try to extract that TLS entry.