Changeset 86170 in vbox for trunk/src/VBox/Runtime/r3/win
- Timestamp:
- Sep 18, 2020 1:38:40 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/thread-win.cpp
r85121 r86170 50 50 51 51 /********************************************************************************************************************************* 52 * Defined Constants And Macros * 52 * Structures and Typedefs * 53 *********************************************************************************************************************************/ 54 /** SetThreadDescription */ 55 typedef HRESULT (WINAPI *PFNSETTHREADDESCRIPTION)(HANDLE hThread, WCHAR *pwszName); /* Since W10 1607 */ 56 57 58 /********************************************************************************************************************************* 59 * Global Variables * 53 60 *********************************************************************************************************************************/ 54 61 /** The TLS index allocated for storing the RTTHREADINT pointer. */ 55 62 static DWORD g_dwSelfTLS = TLS_OUT_OF_INDEXES; 63 /** Pointer to SetThreadDescription (KERNEL32.DLL) if available. */ 64 static PFNSETTHREADDESCRIPTION g_pfnSetThreadDescription = NULL; 56 65 57 66 … … 61 70 static unsigned __stdcall rtThreadNativeMain(void *pvArgs) RT_NOTHROW_PROTO; 62 71 static void rtThreadWinTellDebuggerThreadName(uint32_t idThread, const char *pszName); 72 DECLINLINE(void) rtThreadWinSetThreadName(PRTTHREADINT pThread, DWORD idThread); 63 73 64 74 … … 68 78 if (g_dwSelfTLS == TLS_OUT_OF_INDEXES) 69 79 return VERR_NO_TLS_FOR_SELF; 80 81 g_pfnSetThreadDescription = (PFNSETTHREADDESCRIPTION)GetProcAddress(g_hModKernel32, "SetThreadDescription"); 70 82 return VINF_SUCCESS; 71 83 } … … 110 122 if (!TlsSetValue(g_dwSelfTLS, pThread)) 111 123 return VERR_FAILED_TO_SET_SELF_TLS; 112 if (IsDebuggerPresent()) 113 rtThreadWinTellDebuggerThreadName(GetCurrentThreadId(), pThread->szName); 124 rtThreadWinSetThreadName(pThread, GetCurrentThreadId()); 114 125 return VINF_SUCCESS; 115 126 } … … 149 160 { 150 161 162 } 163 } 164 165 166 /** 167 * Sets the thread name as best as we can. 168 */ 169 DECLINLINE(void) rtThreadWinSetThreadName(PRTTHREADINT pThread, DWORD idThread) 170 { 171 if (IsDebuggerPresent()) 172 rtThreadWinTellDebuggerThreadName(idThread, &pThread->szName[0]); 173 174 /* The SetThreadDescription API introduced in windows 10 1607 / server 2016 175 allows setting the thread name while the debugger isn't attached. Works 176 with WinDbgX, VisualStudio 2017 v15.6+, and presumeably some recent windbg 177 version. */ 178 if (g_pfnSetThreadDescription) 179 { 180 /* The name should be ASCII, so we just need to expand 'char' to 'WCHAR'. */ 181 WCHAR wszName[RTTHREAD_NAME_LEN]; 182 for (size_t i = 0; i < RTTHREAD_NAME_LEN; i++) 183 wszName[i] = pThread->szName[i]; 184 185 HRESULT hrc = g_pfnSetThreadDescription(GetCurrentThread(), wszName); 186 Assert(SUCCEEDED(hrc)); RT_NOREF(hrc); 151 187 } 152 188 } … … 250 286 if (!TlsSetValue(g_dwSelfTLS, pThread)) 251 287 AssertReleaseMsgFailed(("failed to set self TLS. lasterr=%d thread '%s'\n", GetLastError(), pThread->szName)); 252 if (IsDebuggerPresent()) 253 rtThreadWinTellDebuggerThreadName(dwThreadId, &pThread->szName[0]); 288 rtThreadWinSetThreadName(pThread, dwThreadId); 254 289 255 290 int rc = rtThreadMain(pThread, dwThreadId, &pThread->szName[0]);
Note:
See TracChangeset
for help on using the changeset viewer.