Set names of worker threads
authorTom Tromey <tom@tromey.com>
Sat, 12 Oct 2019 19:06:18 +0000 (13:06 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 26 Nov 2019 21:02:58 +0000 (14:02 -0700)
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-11-26  Tom Tromey  <tom@tromey.com>

* 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-11-26  Tom Tromey  <tom@tromey.com>

* configure, config.in: Rebuild.

Change-Id: I60473d65ae9ae14d8c56ddde39684240c16aaf35

gdb/ChangeLog
gdb/config.in
gdb/configure
gdb/gdbserver/ChangeLog
gdb/gdbserver/config.in
gdb/gdbserver/configure
gdb/gdbsupport/common.m4
gdb/gdbsupport/thread-pool.c

index 0c5aab26d302c2880a400e0c835330e50f89cb96..94a8bdc8dc1e24ba73ba1d86765a5451ba836872 100644 (file)
@@ -1,3 +1,11 @@
+2019-11-26  Tom Tromey  <tom@tromey.com>
+
+       * 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-11-26  Tom Tromey  <tom@tromey.com>
 
        * python/python.c (class gdbpy_gil): New.
index 61e63e2330033ef94cfb6a5dea752ca861ec5cbd..1caf76481b9dddfbdca8c53fb87840a1d0f146e2 100644 (file)
 /* 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
 
index dd936d247e395a6a860df17db78efdd4f1aa9ef8..6b64619df7a932155cb70d3a14cd273fff20198a 100755 (executable)
@@ -14333,12 +14333,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
index 00b0a0df025690be0f28289f81d0744c196af2a9..de6c311e076ddf550962263f339f41e49863b99a 100644 (file)
@@ -1,3 +1,7 @@
+2019-11-26  Tom Tromey  <tom@tromey.com>
+
+       * configure, config.in: Rebuild.
+
 2019-11-26  Tom Tromey  <tom@tromey.com>
 
        * remote-utils.c (block_unblock_async_io): Use gdb_sigmask.
index 3027ffa1b1c1f6c086c5f258060052e05a528746..14cf7099e39f8bdb297ca362607a9b78a4f61d3c 100644 (file)
 /* 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
 
index 8d34a6c30594f4335d7c87420180ee0025caf1dc..da17f8cb2cc6a21cb04d6138dd4a6b56652095c9 100755 (executable)
@@ -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
index e993b20248757846cdbbbbd89740b06dae21f809..4f2bb5218d554fe321d3356aada532c2abb9ad17 100644 (file)
@@ -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"
index 8282ea374bccc0bc479045a3ebb8dac33258f153..d19ae02e3ef18d8b42f4661ce3dcb023a28194e1 100644 (file)
 #include "gdbsupport/block-signals.h"
 #include <algorithm>
 
+/* 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
+#define USE_PTHREAD_SETNAME_NP
+#endif
+#endif
+
+#ifdef USE_PTHREAD_SETNAME_NP
+#include <pthread.h>
+#endif
+
 namespace gdb
 {
 
@@ -62,6 +75,9 @@ thread_pool::set_thread_count (size_t num_threads)
       for (size_t i = m_thread_count; i < num_threads; ++i)
        {
          std::thread thread (&thread_pool::thread_function, this);
+#ifdef USE_PTHREAD_SETNAME_NP
+         pthread_setname_np (thread.native_handle (), "gdb worker");
+#endif
          thread.detach ();
        }
     }
This page took 0.04625 seconds and 4 git commands to generate.