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

Unified Diff: src/platform-win32.cc

Issue 206253003: Set thread name in MSVC debugger.
Patch Set: set thread name in MSVC debugger 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..36fdf6c13c42b84e23d11fd8958bd5d5d222bc62 100644
--- a/src/platform-win32.cc
+++ b/src/platform-win32.cc
@@ -1423,12 +1423,39 @@ bool VirtualMemory::HasLazyCommits() {
// Definition of invalid thread handle and id.
static const HANDLE kNoThread = INVALID_HANDLE_VALUE;
+static void SetCurThreadName(const char* name) {
Benedikt Meurer 2014/03/31 06:57:02 Nit: Use SetCurrentThreadName()
Jarin 2014/03/31 07:46:00 How about taking the code from Chromium? See https
+ // Reference: http://www.codeproject.com/KB/threads/Name_threads_in_debugger.aspx
Jarin 2014/03/31 07:46:00 I would prefer to link Microsoft rather than codep
+
+ 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;
+ {
Benedikt Meurer 2014/03/31 06:57:02 Nit: no need for a {}-block here.
+ info.dwType = 0x1000;
+ info.szName = name;
+ info.dwThreadID = (DWORD)-1;
Benedikt Meurer 2014/03/31 06:57:02 Use static_cast<DWORD>(-1)
+ info.dwFlags = 0;
+ }
+
+ __try {
+ RaiseException(
+ 0x406D1388 /* MSVC EXCEPTION */, 0,
+ sizeof(info)/sizeof(DWORD), reinterpret_cast<ULONG_PTR*>(&info));
Jarin 2014/03/31 07:46:00 The Microsoft article says the third arg should be
+ }
+ __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);
+ SetCurThreadName(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