Reviewers: ,

Message:
Hi,

That's my first patch for V8. I thought this can be useful when you debug V8 in
the MSVC debugger.

Note that you can do the same also on most other platforms, e.g. there is
pthread_setname_np. I'm usually doing this:


#ifdef HAVE_PTHREAD_NAME
//
http://stackoverflow.com/questions/2369738/can-i-set-the-name-of-a-thread-in-pthreads-linux/7989973#7989973
#ifdef __APPLE__
        pthread_setname_np(name.c_str());
#else
        pthread_setname_np(pthread_self(), name.c_str());
#endif
#endif


I can submit separate patches, if there is interest for it.

Regards,
Albert


Description:
set thread name in MSVC debugger

Please review this at https://codereview.chromium.org/206253003/

Affected files (+27, -0 lines):
  M src/platform-win32.cc


Index: src/platform-win32.cc
diff --git a/src/platform-win32.cc b/src/platform-win32.cc
index fe84bcd3fff234bd69b2e834f8bda105f29f148b..2f4b1b8156b9477646e4c3608e815a5eab91942f 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) {
+ // Reference: http://www.codeproject.com/KB/threads/Name_threads_in_debugger.aspx
+
+  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 = (DWORD)-1;
+    info.dwFlags = 0;
+  }
+
+  __try {
+    RaiseException(
+      0x406D1388 /* MSVC EXCEPTION */, 0,
+      sizeof(info)/sizeof(DWORD), 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);
+  setCurThreadName(thread->name());
   thread->NotifyStartedAndRun();
   return 0;
 }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to