From patchwork Tue Nov 26 21:13:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 36259 Received: (qmail 113490 invoked by alias); 26 Nov 2019 21:14:03 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 113135 invoked by uid 89); 26 Nov 2019 21:14:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Nov 2019 21:13:58 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id F2A3C20577; Tue, 26 Nov 2019 16:13:57 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id D2AC721063; Tue, 26 Nov 2019 16:13:13 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id B232220AF6; Tue, 26 Nov 2019 16:13:13 -0500 (EST) X-Gerrit-PatchSet: 5 Date: Tue, 26 Nov 2019 16:13:07 -0500 From: "Sourceware to Gerrit sync (Code Review)" To: Tom Tromey , gdb-patches@sourceware.org Cc: Pedro Alves Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [pushed] Set names of worker threads X-Gerrit-Change-Id: I60473d65ae9ae14d8c56ddde39684240c16aaf35 X-Gerrit-Change-Number: 176 X-Gerrit-ChangeURL: X-Gerrit-Commit: 4da8c3a8a5d1962d24fb374122c473f930eba386 In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, tromey@sourceware.org, palves@redhat.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Message-Id: <20191126211313.B232220AF6@gnutoolchain-gerrit.osci.io> The original change was created by Tom Tromey. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/176 ...................................................................... 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-11-26 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-11-26 Tom Tromey * configure, config.in: Rebuild. Change-Id: I60473d65ae9ae14d8c56ddde39684240c16aaf35 --- M gdb/ChangeLog M gdb/config.in M gdb/configure M gdb/gdbserver/ChangeLog M gdb/gdbserver/config.in M gdb/gdbserver/configure M gdb/gdbsupport/common.m4 M gdb/gdbsupport/thread-pool.c 8 files changed, 45 insertions(+), 9 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0c5aab2..94a8bdc 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2019-11-26 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-11-26 Tom Tromey + * python/python.c (class gdbpy_gil): New. (struct gdbpy_event): Add constructor, destructor, operator(). (gdbpy_post_event): Use run_on_main_thread. diff --git a/gdb/config.in b/gdb/config.in index 61e63e2..1caf764 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 dd936d2..6b64619 100755 --- a/gdb/configure +++ b/gdb/configure @@ -14333,12 +14333,13 @@ # 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 00b0a0d..de6c311 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,5 +1,9 @@ 2019-11-26 Tom Tromey + * configure, config.in: Rebuild. + +2019-11-26 Tom Tromey + * remote-utils.c (block_unblock_async_io): Use gdb_sigmask. * linux-low.c (linux_wait_for_event_filtered, linux_async): Use gdb_sigmask. diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in index 3027ffa..14cf709 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 8d34a6c..da17f8c 100755 --- a/gdb/gdbserver/configure +++ b/gdb/gdbserver/configure @@ -7725,12 +7725,13 @@ # 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 e993b20..4f2bb52 100644 --- a/gdb/gdbsupport/common.m4 +++ b/gdb/gdbsupport/common.m4 @@ -57,7 +57,7 @@ # 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 8282ea3..d19ae02 100644 --- a/gdb/gdbsupport/thread-pool.c +++ b/gdb/gdbsupport/thread-pool.c @@ -26,6 +26,19 @@ #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 +#define USE_PTHREAD_SETNAME_NP +#endif +#endif + +#ifdef USE_PTHREAD_SETNAME_NP +#include +#endif + namespace gdb { @@ -62,6 +75,9 @@ 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 (); } }