From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17990 invoked by alias); 23 Jul 2016 16:43:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 17965 invoked by uid 89); 23 Jul 2016 16:43:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=thread_name, *thread_name, H*r:sk:c-73-23, H*RU:sk:c-73-23 X-HELO: bigwig.baldwin.cx Received: from bigwig.baldwin.cx (HELO bigwig.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Sat, 23 Jul 2016 16:43:46 +0000 Received: from ralph.baldwin.cx (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 057EBB922; Sat, 23 Jul 2016 12:43:44 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: LRN Subject: Re: Program-assigned thread names on Windows Date: Sat, 23 Jul 2016 16:43:00 -0000 Message-ID: <14995502.J10EtrK3xV@ralph.baldwin.cx> User-Agent: KMail/4.14.3 (FreeBSD/10.3-STABLE; KDE/4.14.3; amd64; ; ) In-Reply-To: <5052d495-ea40-b364-96ea-9e68c90bd747@gmail.com> References: <5052d495-ea40-b364-96ea-9e68c90bd747@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-IsSubscribed: yes X-SW-Source: 2016-07/txt/msg00312.txt.bz2 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); } -- John Baldwin