(svn r27673) -Add: [Win32] Thread names for windows debuggers.

This commit is contained in:
michi_cc
2016-10-30 18:22:55 +00:00
parent b2fe2c6e3d
commit c83306391e
7 changed files with 59 additions and 4 deletions

View File

@@ -785,3 +785,36 @@ uint GetCPUCoreCount()
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
}
#ifdef _MSC_VER
/* Code from MSDN: https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx */
const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
typedef struct {
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;
#pragma pack(pop)
/**
* Signal thread name to any attached debuggers.
*/
void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
{
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = threadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
#pragma warning(push)
#pragma warning(disable: 6320 6322)
__try {
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info);
} __except (EXCEPTION_EXECUTE_HANDLER) {
}
#pragma warning(pop)
}
#endif