]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
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>
Sun, 10 Nov 2019 17:44:50 +0000 (10:44 -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-10-19  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-10-19  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 538550c888e95b87f83a13cc28ac67ea4b9c1af4..f9ce32ebece6fb516c252776b1d8b24b6f4d9a98 100644 (file)
@@ -1,3 +1,11 @@
+2019-10-19  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-10-19  Tom Tromey  <tom@tromey.com>
 
        * python/python.c (class gdbpy_gil): New.
index d3e970213513dd161376a5104b9affdc4f429079..87df9ec91997c9c5bda119f6ce42ef1ecffed4a3 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 8b2012c436bc04b19c83e3a3781876298ead6c9f..5e25cc618f36f59b58daaece7e25dedec8da72a1 100755 (executable)
@@ -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
index 15f95770d82aefc5f10aa9336e85adf6c4242e57..83e7f081409fa2d4b2a22d466fd30ddb7edd94e6 100644 (file)
@@ -1,3 +1,7 @@
+2019-10-19  Tom Tromey  <tom@tromey.com>
+
+       * configure, config.in: Rebuild.
+
 2019-10-19  Tom Tromey  <tom@tromey.com>
 
        * remote-utils.c (block_unblock_async_io): Use gdb_sigmask.
index a8570c6759f23bfc11e58182b5c1f1ace2a45a54..8fc2e90f871aa3db6da4cbc33ee750078f7fbdbb 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 c1c6fbde0cdafef6eaf53c4758aecc22e4f55837..d0d0c794270803d7d618c39aabfc1c33ef7bfc78 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 46ca53cfc184c334c89dd20d3e6e95241dfc3bbe..fe7fcb67e5bd390e7e81027896338a16fcbbbbc3 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 a3ebf424bba30d0fbdae601ce7b4f6bf3d771929..fcbe7916fb23cb3e70e99b714dabcd544a0f95fa 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
+#include <pthread.h>
+#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 ();
        }
     }