This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Program-assigned thread names on Windows


On 23.07.2016 19:39, John Baldwin wrote:
> On Saturday, July 23, 2016 12:25:15 PM LRN wrote:
>> The attached patch adds thread naming support on Windows.
>>
>> This works as documented[1] on MSDN - by catching a specific
>> exception that the program throws.
>>
>> Setting thread name this way is supported by glib[2] and winpthreads[3]
>> at least, as well as any program developed with MS toolchain (because
>> WinDbg supported this for a long time).
>>
>> [1] https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
>> [2] https://git.gnome.org/browse/glib/commit/glib
>> /gthread-win32.c?id=e118856430a798bbc529691ad235fd0b0684439d
>> [3] https://sourceforge.net/p/mingw-w64/mingw-w64/ci
>> /0d95c795b44b76e1b60dfc119fd93cfd0cb35816/
> 
> Does this leak 'thread_name' if the first character is '\0'?
> 
> +         thread_name = NULL;
> +         if (!target_read_string ((CORE_ADDR) thread_name_target, &thread_name, 1024, 0)
> +             || !thread_name || !*thread_name)
> +           /* nothing to do */;
> +         else
> +           {
> +             xfree (named_thread->name);
> +             named_thread->name = thread_name;
> +           }
> +         result = 2;
> 
> Maybe restructure as:
> 
>     if (target_read_string (...))
>       {
>         if (thread_name && thread_name[0] != '\0')
>           {
>             xfree (named_thread->name);
>             named_thread->name = thread_name;
>           }
>         else
>           xfree (thread_name);
>       }
> 

You're right, it can leak. Fixed patch attached.

That said, handle_output_debug_string() does the same thing (and, judging
by the "nothing to do" comment, i've copied this call from there back when
i made wrote this code).

-- 
O< ascii ribbon - stop html email! - www.asciiribbon.org

Attachment: 0001-Support-settings-thread-name-MS-Windows.patch
Description: Text document

Attachment: 0x6759BA74.asc
Description: application/pgp-keys

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]