[PATCH] Cygwin: Set threadnames with SetThreadDescription()
Mon May 30 15:37:44 GMT 2022
On 5/29/2022 10:03 AM, Jon Turney wrote:
> gdb master recently learnt how to use GetThreadDescription() , so set
> threadnames using SetThreadDescription() [available since Windows
> 101607] as well.
> This is superior to using a special exception to indicate the thread
> name to the debugger, because the thread name isn't missed if you don't
> have a debugger attached at the time it's set.
> It's not clear what the encoding of a thread name string is, we assume
> UTF8 for the moment.
> For the moment, continue to use the old method as well, for the benefit
> of older gdb versions etc.
LGTM, except for a few missing spaces (see below), although maybe you did that
deliberately since the existing code was already like that.
> --- a/winsup/cygwin/miscfuncs.cc
> +++ b/winsup/cygwin/miscfuncs.cc
> @@ -18,6 +18,9 @@ details. */
> #include "tls_pbuf.h"
> #include "mmap_alloc.h"
> +/* not yet prototyped in w32api */
> +extern "C" HRESULT WINAPI SetThreadDescription(HANDLE hThread, PCWSTR lpThreadDescription);
> @@ -993,8 +996,8 @@ wmempcpy: \n\
> #define MS_VC_EXCEPTION 0x406D1388
> -SetThreadName(DWORD dwThreadID, const char* threadName)
> +static void
> +SetThreadNameExc(DWORD dwThreadID, const char* threadName)
> @@ -1025,6 +1028,32 @@ SetThreadName(DWORD dwThreadID, const char* threadName)
> +SetThreadName(DWORD dwThreadID, const char* threadName)
> + SetThreadNameExc(dwThreadID, threadName);
More information about the Cygwin-patches