[PATCH] Fix build on macOS

Simon Marchi simark@simark.ca
Wed Dec 11 01:37:00 GMT 2019


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



More information about the Gdb-patches mailing list