From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 400273858C53 for ; Wed, 13 Apr 2022 19:33:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 400273858C53 Received: from fencepost.gnu.org ([2001:470:142:3::e]:41704) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1neijh-0007Dn-Os; Wed, 13 Apr 2022 15:33:05 -0400 Received: from [87.69.77.57] (port=4787 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1neijb-0006KL-T9; Wed, 13 Apr 2022 15:33:05 -0400 Date: Wed, 13 Apr 2022 22:33:07 +0300 Message-Id: <834k2w4w3w.fsf@gnu.org> From: Eli Zaretskii To: Tom Tromey Cc: gdb-patches@sourceware.org In-Reply-To: <20220413191756.1146768-10-tromey@adacore.com> (message from Tom Tromey via Gdb-patches on Wed, 13 Apr 2022 13:17:56 -0600) Subject: Re: [PATCH 9/9] Use GetThreadDescription on Windows References: <20220413191756.1146768-1-tromey@adacore.com> <20220413191756.1146768-10-tromey@adacore.com> X-Spam-Status: No, score=2.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Apr 2022 19:33:07 -0000 > Date: Wed, 13 Apr 2022 13:17:56 -0600 > From: Tom Tromey via Gdb-patches > Cc: Tom Tromey > > Windows 10 introduced SetThreadDescription and GetThreadDescription, a > simpler way to set a thread's name. This changes gdb and gdbserver to > use this convention when it is available. Thanks for doing this. > +const char * > +windows_thread_info::thread_name () > +{ > + if (GetThreadDescription != nullptr) > + { > + PWSTR value; > + HRESULT result = GetThreadDescription (h, &value); > + if (SUCCEEDED (result)) > + { > + size_t needed; > + if (wcstombs_s (&needed, nullptr, 0, value, _TRUNCATE) == 0) > + { > + name.reset ((char *) xmalloc (needed)); > + if (wcstombs_s (&needed, name.get (), needed, > + value, needed - 1) != 0) > + name.reset (); > + } > + LocalFree (value); > + } > + } > + > + return name.get (); > +} AFAIK, wcstombs_s is only available since Vista, so I think we need a configure-time test for that, and use wcstombs as fallback.