Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(767)

Unified Diff: src/platform-win32.cc

Issue 206253003: Set thread name in MSVC debugger.
Patch Set: update Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform-win32.cc
diff --git a/src/platform-win32.cc b/src/platform-win32.cc
index fe84bcd3fff234bd69b2e834f8bda105f29f148b..52b616d35177369f81a27a74c693d50e2b89d2d3 100644
--- a/src/platform-win32.cc
+++ b/src/platform-win32.cc
@@ -1423,12 +1423,38 @@ bool VirtualMemory::HasLazyCommits() {
// Definition of invalid thread handle and id.
static const HANDLE kNoThread = INVALID_HANDLE_VALUE;
+static void SetCurrentThreadName(const char* name) {
+ // Reference: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx
+ // https://code.google.com/p/chromium/codesearch#chromium/src/base/threading/platform_thread_win.cc
+
+ typedef struct tagTHREADNAME_INFO {
+ DWORD dwType; // Must be 0x1000.
+ LPCSTR szName; // Pointer to name (in user addr space).
+ DWORD dwThreadID; // Thread ID (-1=caller thread).
+ DWORD dwFlags; // Reserved for future use, must be zero.
+ } THREADNAME_INFO;
+
+ THREADNAME_INFO info;
+ info.dwType = 0x1000;
+ info.szName = name;
+ info.dwThreadID = static_cast<DWORD>(-1);
+ info.dwFlags = 0;
+
+ __try {
+ RaiseException(
+ 0x406D1388 /* MSVC EXCEPTION */, 0,
+ sizeof(info)/sizeof(ULONG_PTR), reinterpret_cast<ULONG_PTR*>(&info));
+ }
+ __except(EXCEPTION_CONTINUE_EXECUTION) {}
+}
+
// Entry point for threads. The supplied argument is a pointer to the thread
// object. The entry function dispatches to the run method in the thread
// object. It is important that this function has __stdcall calling
// convention.
static unsigned int __stdcall ThreadEntry(void* arg) {
Thread* thread = reinterpret_cast<Thread*>(arg);
+ SetCurrentThreadName(thread->name());
thread->NotifyStartedAndRun();
return 0;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698