From 4a7dabea39556979cbf6bcbdd98a9413ce129fd0 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 12 Oct 2019 13:06:18 -0600 Subject: [PATCH] Set names of worker threads This adds some configury so that gdb can set the names of worker threads. This makes them show up more nicely when debugging gdb itself. 2019-10-19 Tom Tromey * gdbsupport/thread-pool.c (thread_pool::set_thread_count): Set name of worker thread. * gdbsupport/common.m4 (GDB_AC_COMMON): Check for pthread_setname_np. * configure, config.in: Rebuild. gdb/gdbserver/ChangeLog 2019-10-19 Tom Tromey * configure, config.in: Rebuild. Change-Id: I60473d65ae9ae14d8c56ddde39684240c16aaf35 --- gdb/ChangeLog | 8 ++++++++ gdb/config.in | 3 +++ gdb/configure | 9 +++++---- gdb/gdbserver/ChangeLog | 4 ++++ gdb/gdbserver/config.in | 3 +++ gdb/gdbserver/configure | 9 +++++---- gdb/gdbsupport/common.m4 | 2 +- gdb/gdbsupport/thread-pool.c | 14 ++++++++++++++ 8 files changed, 43 insertions(+), 9 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 538550c888e..f9ce32ebece 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2019-10-19 Tom Tromey + + * gdbsupport/thread-pool.c (thread_pool::set_thread_count): Set + name of worker thread. + * gdbsupport/common.m4 (GDB_AC_COMMON): Check for + pthread_setname_np. + * configure, config.in: Rebuild. + 2019-10-19 Tom Tromey * python/python.c (class gdbpy_gil): New. diff --git a/gdb/config.in b/gdb/config.in index d3e97021351..87df9ec9199 100644 --- a/gdb/config.in +++ b/gdb/config.in @@ -342,6 +342,9 @@ /* Have PTHREAD_PRIO_INHERIT. */ #undef HAVE_PTHREAD_PRIO_INHERIT +/* Define to 1 if you have the `pthread_setname_np' function. */ +#undef HAVE_PTHREAD_SETNAME_NP + /* Define to 1 if you have the `pthread_sigmask' function. */ #undef HAVE_PTHREAD_SIGMASK diff --git a/gdb/configure b/gdb/configure index 8b2012c436b..5e25cc618f3 100755 --- a/gdb/configure +++ b/gdb/configure @@ -14337,12 +14337,13 @@ $as_echo "$gdb_cv_cxx_std_thread" >&6; } # This check must be here, while LIBS includes any necessary # threading library. - for ac_func in pthread_sigmask + for ac_func in pthread_sigmask pthread_setname_np do : - ac_fn_cxx_check_func "$LINENO" "pthread_sigmask" "ac_cv_func_pthread_sigmask" -if test "x$ac_cv_func_pthread_sigmask" = xyes; then : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF -#define HAVE_PTHREAD_SIGMASK 1 +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 15f95770d82..83e7f081409 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,7 @@ +2019-10-19 Tom Tromey + + * configure, config.in: Rebuild. + 2019-10-19 Tom Tromey * remote-utils.c (block_unblock_async_io): Use gdb_sigmask. diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in index a8570c6759f..8fc2e90f871 100644 --- a/gdb/gdbserver/config.in +++ b/gdb/gdbserver/config.in @@ -195,6 +195,9 @@ /* Have PTHREAD_PRIO_INHERIT. */ #undef HAVE_PTHREAD_PRIO_INHERIT +/* Define to 1 if you have the `pthread_setname_np' function. */ +#undef HAVE_PTHREAD_SETNAME_NP + /* Define to 1 if you have the `pthread_sigmask' function. */ #undef HAVE_PTHREAD_SIGMASK diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure index c1c6fbde0cd..d0d0c794270 100755 --- a/gdb/gdbserver/configure +++ b/gdb/gdbserver/configure @@ -7725,12 +7725,13 @@ $as_echo "$gdb_cv_cxx_std_thread" >&6; } # This check must be here, while LIBS includes any necessary # threading library. - for ac_func in pthread_sigmask + for ac_func in pthread_sigmask pthread_setname_np do : - ac_fn_cxx_check_func "$LINENO" "pthread_sigmask" "ac_cv_func_pthread_sigmask" -if test "x$ac_cv_func_pthread_sigmask" = xyes; then : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF -#define HAVE_PTHREAD_SIGMASK 1 +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi diff --git a/gdb/gdbsupport/common.m4 b/gdb/gdbsupport/common.m4 index 46ca53cfc18..fe7fcb67e5b 100644 --- a/gdb/gdbsupport/common.m4 +++ b/gdb/gdbsupport/common.m4 @@ -57,7 +57,7 @@ AC_DEFUN([GDB_AC_COMMON], [ # This check must be here, while LIBS includes any necessary # threading library. - AC_CHECK_FUNCS([pthread_sigmask]) + AC_CHECK_FUNCS([pthread_sigmask pthread_setname_np]) LIBS="$save_LIBS" CXXFLAGS="$save_CXXFLAGS" diff --git a/gdb/gdbsupport/thread-pool.c b/gdb/gdbsupport/thread-pool.c index a3ebf424bba..fcbe7916fb2 100644 --- a/gdb/gdbsupport/thread-pool.c +++ b/gdb/gdbsupport/thread-pool.c @@ -23,6 +23,15 @@ #include "gdbsupport/block-signals.h" #include +/* On the off chance that we have the pthread library on a Windows + host, but std::thread is not using it, avoid calling + pthread_setname_np on Windows. */ +#ifndef _WIN32 +#ifdef HAVE_PTHREAD_SETNAME_NP +#include +#endif +#endif + namespace gdb { @@ -59,6 +68,11 @@ thread_pool::set_thread_count (size_t num_threads) for (size_t i = m_count; i < num_threads; ++i) { std::thread thread (&thread_pool::thread_function, this); +#ifndef _WIN32 /* See the comment at the top of the file. */ +#ifdef HAVE_PTHREAD_SETNAME_NP + pthread_setname_np (thread.native_handle (), "gdb worker"); +#endif +#endif thread.detach (); } } -- 2.47.2