* [review] Set names of worker threads
@ 2019-10-20 3:55 Tom Tromey (Code Review)
2019-10-20 21:02 ` [review v2] " Tom Tromey (Code Review)
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Tom Tromey (Code Review) @ 2019-10-20 3:55 UTC (permalink / raw)
To: gdb-patches
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.
gdb/ChangeLog
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
---
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, 43 insertions(+), 9 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ec8f644..17ec8e5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
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.
(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 ff2fd12..54f1dd1 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -345,6 +345,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 5571cf0..2a967bf 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -14387,12 +14387,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 28c3608..e5a5829 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,9 @@
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.
* 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 260e8c0..c5144c4 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 7da765b..0adcf26 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 993e097..0c3c1ec 100644
--- a/gdb/gdbsupport/thread-pool.c
+++ b/gdb/gdbsupport/thread-pool.c
@@ -23,6 +23,15 @@
#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
{
@@ -55,6 +64,11 @@
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 ();
}
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [review v2] Set names of worker threads
2019-10-20 3:55 [review] Set names of worker threads Tom Tromey (Code Review)
@ 2019-10-20 21:02 ` Tom Tromey (Code Review)
2019-11-06 0:50 ` [review v3] " Pedro Alves (Code Review)
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey (Code Review) @ 2019-10-20 21:02 UTC (permalink / raw)
To: gdb-patches
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-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
---
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, 43 insertions(+), 9 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3eeee1e..6da4e5b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
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.
(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 ff2fd12..54f1dd1 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -345,6 +345,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 5571cf0..2a967bf 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -14387,12 +14387,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 28c3608..e5a5829 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,9 @@
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.
* 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 260e8c0..c5144c4 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 7da765b..0adcf26 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 a3ebf42..fcbe791 100644
--- a/gdb/gdbsupport/thread-pool.c
+++ b/gdb/gdbsupport/thread-pool.c
@@ -23,6 +23,15 @@
#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 @@
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 ();
}
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [review v3] Set names of worker threads
2019-10-20 3:55 [review] Set names of worker threads Tom Tromey (Code Review)
2019-10-20 21:02 ` [review v2] " Tom Tromey (Code Review)
@ 2019-11-06 0:50 ` Pedro Alves (Code Review)
2019-11-26 19:38 ` [review v4] " Pedro Alves (Code Review)
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves (Code Review) @ 2019-11-06 0:50 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
Pedro Alves has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/176
......................................................................
Patch Set 3:
I'll try to take a look at this tomorrow.
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I60473d65ae9ae14d8c56ddde39684240c16aaf35
Gerrit-Change-Number: 176
Gerrit-PatchSet: 3
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Pedro Alves <palves@redhat.com>
Gerrit-Comment-Date: Wed, 06 Nov 2019 00:49:54 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
^ permalink raw reply [flat|nested] 7+ messages in thread
* [review v4] Set names of worker threads
2019-10-20 3:55 [review] Set names of worker threads Tom Tromey (Code Review)
2019-10-20 21:02 ` [review v2] " Tom Tromey (Code Review)
2019-11-06 0:50 ` [review v3] " Pedro Alves (Code Review)
@ 2019-11-26 19:38 ` Pedro Alves (Code Review)
2019-11-26 19:54 ` Tom Tromey (Code Review)
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves (Code Review) @ 2019-11-26 19:38 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
Pedro Alves has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/176
......................................................................
Patch Set 4:
(3 comments)
Some comments below. Nothing major.
| --- gdb/gdbsupport/thread-pool.c
| +++ gdb/gdbsupport/thread-pool.c
| @@ -22,15 +22,24 @@ #include "common-defs.h"
| #if CXX_STD_THREAD
|
| #include "gdbsupport/thread-pool.h"
| #include "gdbsupport/alt-stack.h"
| #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. */
PS4, Line 31:
Meh. Judging from
<https://stackoverflow.com/questions/19250008/mingw-stdthread-with-
windows-api>, I think this could be solved. But yeah, we really don't
have to bend backwards in this initial patch.
| +#ifndef _WIN32
| +#ifdef HAVE_PTHREAD_SETNAME_NP
| +#include <pthread.h>
| +#endif
| +#endif
PS4, Line 36:
I'd rather this was:
#ifndef _WIN32
# ifdef HAVE_PTHREAD_SETNAME_NP
# define USE_PTHREAD_SETNAME_NP
# endif
#endif
#ifdef USE_PTHREAD_SETNAME_NP
# include <pthread.h>
#endif
so that below we don't duplicate the checks, and we'd have a single
place to edit in the future if the checks evolve. See below...
| +
| namespace gdb
| {
|
| /* The thread pool detach()s its threads, so that the threads will not
| prevent the process from exiting. However, it was discovered that
| if any detached threads were still waiting on a condition variable,
| then the condition variable's destructor would wait for the threads
| to exit -- defeating the purpose.
...
| @@ -57,14 +66,19 @@ thread_pool::set_thread_count (size_t num_threads)
| if (m_thread_count < num_threads)
| {
| /* Ensure that signals used by gdb are blocked in the new
| threads. */
| block_signals blocker;
| for (size_t i = m_thread_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
PS4, Line 75:
... here, we'd do:
#ifdef USE_PTHREAD_SETNAME_NP
| + pthread_setname_np (thread.native_handle (), "gdb worker");
| +#endif
| +#endif
| thread.detach ();
| }
| }
| /* If the new size is smaller, terminate some existing threads. */
| if (num_threads < m_thread_count)
| {
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I60473d65ae9ae14d8c56ddde39684240c16aaf35
Gerrit-Change-Number: 176
Gerrit-PatchSet: 4
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Pedro Alves <palves@redhat.com>
Gerrit-Comment-Date: Tue, 26 Nov 2019 19:38:06 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
^ permalink raw reply [flat|nested] 7+ messages in thread
* [review v4] Set names of worker threads
2019-10-20 3:55 [review] Set names of worker threads Tom Tromey (Code Review)
` (2 preceding siblings ...)
2019-11-26 19:38 ` [review v4] " Pedro Alves (Code Review)
@ 2019-11-26 19:54 ` Tom Tromey (Code Review)
2019-11-26 21:14 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-11-26 21:21 ` Sourceware to Gerrit sync (Code Review)
5 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey (Code Review) @ 2019-11-26 19:54 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves
Tom Tromey has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/176
......................................................................
Patch Set 4:
(1 comment)
| --- gdb/gdbsupport/thread-pool.c
| +++ gdb/gdbsupport/thread-pool.c
| @@ -23,14 +23,23 @@ #if CXX_STD_THREAD
|
| #include "gdbsupport/thread-pool.h"
| #include "gdbsupport/alt-stack.h"
| #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
PS4, Line 36:
> I'd rather this was:
...
I made this change.
| +
| namespace gdb
| {
|
| /* The thread pool detach()s its threads, so that the threads will not
| prevent the process from exiting. However, it was discovered that
| if any detached threads were still waiting on a condition variable,
| then the condition variable's destructor would wait for the threads
| to exit -- defeating the purpose.
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I60473d65ae9ae14d8c56ddde39684240c16aaf35
Gerrit-Change-Number: 176
Gerrit-PatchSet: 4
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Pedro Alves <palves@redhat.com>
Gerrit-Comment-Date: Tue, 26 Nov 2019 19:54:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Pedro Alves <palves@redhat.com>
Gerrit-MessageType: comment
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pushed] Set names of worker threads
2019-10-20 3:55 [review] Set names of worker threads Tom Tromey (Code Review)
` (3 preceding siblings ...)
2019-11-26 19:54 ` Tom Tromey (Code Review)
@ 2019-11-26 21:14 ` Sourceware to Gerrit sync (Code Review)
2019-11-26 21:21 ` Sourceware to Gerrit sync (Code Review)
5 siblings, 0 replies; 7+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-11-26 21:14 UTC (permalink / raw)
To: Tom Tromey, gdb-patches; +Cc: Pedro Alves
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 <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
---
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 <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.
(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 <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.
* 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 <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 @@
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 ();
}
}
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I60473d65ae9ae14d8c56ddde39684240c16aaf35
Gerrit-Change-Number: 176
Gerrit-PatchSet: 5
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Pedro Alves <palves@redhat.com>
Gerrit-MessageType: newpatchset
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pushed] Set names of worker threads
2019-10-20 3:55 [review] Set names of worker threads Tom Tromey (Code Review)
` (4 preceding siblings ...)
2019-11-26 21:14 ` [pushed] " Sourceware to Gerrit sync (Code Review)
@ 2019-11-26 21:21 ` Sourceware to Gerrit sync (Code Review)
5 siblings, 0 replies; 7+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-11-26 21:21 UTC (permalink / raw)
To: Tom Tromey, gdb-patches; +Cc: Pedro Alves
Sourceware to Gerrit sync has submitted this change.
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 <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
---
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 <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.
(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 <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.
* 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 <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 @@
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 ();
}
}
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I60473d65ae9ae14d8c56ddde39684240c16aaf35
Gerrit-Change-Number: 176
Gerrit-PatchSet: 5
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Pedro Alves <palves@redhat.com>
Gerrit-MessageType: merged
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-11-26 21:21 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-20 3:55 [review] Set names of worker threads Tom Tromey (Code Review)
2019-10-20 21:02 ` [review v2] " Tom Tromey (Code Review)
2019-11-06 0:50 ` [review v3] " Pedro Alves (Code Review)
2019-11-26 19:38 ` [review v4] " Pedro Alves (Code Review)
2019-11-26 19:54 ` Tom Tromey (Code Review)
2019-11-26 21:14 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-11-26 21:21 ` Sourceware to Gerrit sync (Code Review)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).