From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 974 invoked by alias); 11 Dec 2019 01:37:19 -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 965 invoked by uid 89); 11 Dec 2019 01:37:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-5.9 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Dec 2019 01:37:17 +0000 Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 5409A1E059; Tue, 10 Dec 2019 20:37:16 -0500 (EST) Subject: Re: [PATCH] Fix build on macOS To: Tom Tromey , gdb-patches@sourceware.org References: <20191210214717.25680-1-tromey@adacore.com> From: Simon Marchi Message-ID: <0aa60cb1-2138-6568-f99a-a9f54fa39f45@simark.ca> Date: Wed, 11 Dec 2019 01:37:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: <20191210214717.25680-1-tromey@adacore.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-12/txt/msg00401.txt.bz2 On 2019-12-10 4:47 p.m., Tom Tromey wrote: > PR build/25268 points out that the build fails on macOS, because on > macOS the "pthread_setname_np" function takes a single argument. > > This patch fixes the problem, by introducing a new template adapter > function that handles both styles of pthread_setname_np. This is a > technique I learned from Alexandre Oliva, and avoids the need for a > complicated autoconf check. > > This change also meant moving the pthread_setname_np call to the > thread function, because macOS only permits setting the name of the > current thread. This means that there can be a brief window when gdb > will see the wrong name; but I think this is a minor concern. > > Tested by rebuilding on x86-64 Fedora 30, and on macOS High Sierra. > On Linux I also debugged gdb to ensure that the thread names are still > set correctly. I think a version without templates would make it a bit simpler to understand: void set_thread_name (int (*set_name) (pthread_t, const char *), const char *name) { set_name (pthread_self (), name); } void set_thread_name (int (*set_name) (const char *), const char *name) { set_name (name); } Also, they should probably be static, disabling -Wunused-functions, if necessary, like in: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blobdiff;f=gdb/gdbsupport/safe-strerror.c;h=9973fa678577c3ff1d9188a6679a0c8cecfd5d26;hp=7425af590f789c1625013c9dc51b505a324ad7fd;hb=cb51113052d534b628c635ac7b86b95fe436d60d;hpb=ab7d13f07027e6232a21448ef51f0a52a96738a9 Simon