summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/windows/ThisThread.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2014-09-09 20:54:56 +0000
committerZachary Turner <zturner@google.com>2014-09-09 20:54:56 +0000
commit39de3110712cb4547a835777310dbead46c1a002 (patch)
treed0f99eb4b7f8ab35272587ad4a0e070675752b54 /lldb/source/Host/windows/ThisThread.cpp
parent7decae153bdb4b4a98fa48bb27564fa4597d1cfa (diff)
downloadbcm5719-llvm-39de3110712cb4547a835777310dbead46c1a002.tar.gz
bcm5719-llvm-39de3110712cb4547a835777310dbead46c1a002.zip
Create a HostThread abstraction.
This patch moves creates a thread abstraction that represents a thread running inside the LLDB process. This is a replacement for otherwise using lldb::thread_t, and provides a platform agnostic interface to managing these threads. Differential Revision: http://reviews.llvm.org/D5198 Reviewed by: Jim Ingham llvm-svn: 217460
Diffstat (limited to 'lldb/source/Host/windows/ThisThread.cpp')
-rw-r--r--lldb/source/Host/windows/ThisThread.cpp60
1 files changed, 60 insertions, 0 deletions
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();
+}
OpenPOWER on IntegriCloud