]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Host/windows/ThisThread.cpp
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / source / Host / windows / ThisThread.cpp
1 //===-- ThisThread.cpp ------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/Core/Error.h"
11
12 #include "lldb/Host/ThisThread.h"
13 #include "lldb/Host/windows/windows.h"
14
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/SmallVector.h"
17
18 using namespace lldb;
19 using namespace lldb_private;
20
21 #if defined(_MSC_VER) && !defined(__clang__)
22
23 namespace {
24 static const DWORD MS_VC_EXCEPTION = 0x406D1388;
25
26 #pragma pack(push, 8)
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.
32 };
33 #pragma pack(pop)
34 }
35
36 #endif
37
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__)
43   THREADNAME_INFO info;
44   info.dwType = 0x1000;
45   info.szName = name.data();
46   info.dwThreadId = ::GetCurrentThreadId();
47   info.dwFlags = 0;
48
49   __try {
50     ::RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR),
51                      (ULONG_PTR *)&info);
52   } __except (EXCEPTION_EXECUTE_HANDLER) {
53   }
54 #endif
55 }
56
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.
62   name.clear();
63 }