public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] gdbsupport/common.m4: check for sigtimedwait
@ 2021-06-27 19:13 Simon Marchi
  2021-06-27 19:13 ` [PATCH 2/2] gdb: fall back on sigpending + sigwait if sigtimedwait is not available Simon Marchi
  2021-07-05 13:03 ` [PATCH 1/2] gdbsupport/common.m4: check for sigtimedwait Pedro Alves
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Marchi @ 2021-06-27 19:13 UTC (permalink / raw)
  To: gdb-patches

The next patch will make the use of sigtimedwait conditional to whether
the platform provides it.  Start by adding a configure check for it.

gdbsupport/ChangeLog:

	* common.m4 (GDB_AC_COMMON): Check for sigtimedwait.
	* config.in, configure: Re-generate.

gdb/ChangeLog:

	* config.in, configure: Re-generate.

gdbserver/ChangeLog:

	* config.in, configure: Re-generate.

Change-Id: Ic7613fe14521b966b4d991bbcd0933ab14629c05
---
 gdb/config.in        | 3 +++
 gdb/configure        | 2 +-
 gdbserver/config.in  | 3 +++
 gdbserver/configure  | 2 +-
 gdbsupport/common.m4 | 2 +-
 gdbsupport/config.in | 3 +++
 gdbsupport/configure | 2 +-
 7 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/gdb/config.in b/gdb/config.in
index 9342604ac4c9..2c30504905b8 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -414,6 +414,9 @@
 /* Define to 1 if you have the `sigsetmask' function. */
 #undef HAVE_SIGSETMASK
 
+/* Define to 1 if you have the `sigtimedwait' function. */
+#undef HAVE_SIGTIMEDWAIT
+
 /* Define to 1 if you have the `socketpair' function. */
 #undef HAVE_SOCKETPAIR
 
diff --git a/gdb/configure b/gdb/configure
index a5c6fab118c5..de4528c43ad8 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -13857,7 +13857,7 @@ fi
 
   for ac_func in fdwalk getrlimit pipe pipe2 poll socketpair sigaction \
 		  ptrace64 sbrk setns sigaltstack sigprocmask \
-		  setpgid setpgrp getrusage getauxval
+		  setpgid setpgrp getrusage getauxval sigtimedwait
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/gdbserver/config.in b/gdbserver/config.in
index 611bfd7aa768..cf06c56421d1 100644
--- a/gdbserver/config.in
+++ b/gdbserver/config.in
@@ -266,6 +266,9 @@
 /* Define if sigsetjmp is available. */
 #undef HAVE_SIGSETJMP
 
+/* Define to 1 if you have the `sigtimedwait' function. */
+#undef HAVE_SIGTIMEDWAIT
+
 /* Define to 1 if you have the `socketpair' function. */
 #undef HAVE_SOCKETPAIR
 
diff --git a/gdbserver/configure b/gdbserver/configure
index b9d4653ae5e1..b227167e270c 100755
--- a/gdbserver/configure
+++ b/gdbserver/configure
@@ -7118,7 +7118,7 @@ fi
 
   for ac_func in fdwalk getrlimit pipe pipe2 poll socketpair sigaction \
 		  ptrace64 sbrk setns sigaltstack sigprocmask \
-		  setpgid setpgrp getrusage getauxval
+		  setpgid setpgrp getrusage getauxval sigtimedwait
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/gdbsupport/common.m4 b/gdbsupport/common.m4
index 2e709dbbdbb3..901c454ea8cb 100644
--- a/gdbsupport/common.m4
+++ b/gdbsupport/common.m4
@@ -53,7 +53,7 @@ AC_DEFUN([GDB_AC_COMMON], [
   AC_FUNC_FORK
   AC_CHECK_FUNCS([fdwalk getrlimit pipe pipe2 poll socketpair sigaction \
 		  ptrace64 sbrk setns sigaltstack sigprocmask \
-		  setpgid setpgrp getrusage getauxval])
+		  setpgid setpgrp getrusage getauxval sigtimedwait])
 
   AC_CHECK_DECLS([strstr])
 
diff --git a/gdbsupport/config.in b/gdbsupport/config.in
index c44a2a1e5de8..f46e2612c743 100644
--- a/gdbsupport/config.in
+++ b/gdbsupport/config.in
@@ -210,6 +210,9 @@
 /* Define if sigsetjmp is available. */
 #undef HAVE_SIGSETJMP
 
+/* Define to 1 if you have the `sigtimedwait' function. */
+#undef HAVE_SIGTIMEDWAIT
+
 /* Define to 1 if you have the `socketpair' function. */
 #undef HAVE_SOCKETPAIR
 
diff --git a/gdbsupport/configure b/gdbsupport/configure
index 60643c80b5a8..a9dd02c5b722 100755
--- a/gdbsupport/configure
+++ b/gdbsupport/configure
@@ -8131,7 +8131,7 @@ fi
 
   for ac_func in fdwalk getrlimit pipe pipe2 poll socketpair sigaction \
 		  ptrace64 sbrk setns sigaltstack sigprocmask \
-		  setpgid setpgrp getrusage getauxval
+		  setpgid setpgrp getrusage getauxval sigtimedwait
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
-- 
2.32.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] gdb: fall back on sigpending + sigwait if sigtimedwait is not available
  2021-06-27 19:13 [PATCH 1/2] gdbsupport/common.m4: check for sigtimedwait Simon Marchi
@ 2021-06-27 19:13 ` Simon Marchi
  2021-07-05 13:03   ` Pedro Alves
  2021-07-05 13:03 ` [PATCH 1/2] gdbsupport/common.m4: check for sigtimedwait Pedro Alves
  1 sibling, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2021-06-27 19:13 UTC (permalink / raw)
  To: gdb-patches

The macOS platform does not provide sigtimedwait, so we get:

      CXX    compile/compile.o
    In file included from /Users/smarchi/src/binutils-gdb/gdb/compile/compile.c:46:
    /Users/smarchi/src/binutils-gdb/gdb/../gdbsupport/scoped_ignore_signal.h:69:4: error: use of undeclared identifier 'sigtimedwait'
              sigtimedwait (&set, nullptr, &zero_timeout);
              ^

An alternative to sigtimedwait with a timeout of 0 is to use sigpending,
to first check which signals are pending, and then sigwait, to consume
them.  Since that's slightly more expensive (2 syscalls instead of 1),
keep using sigtimedwait for the platforms that provide it, and fall back
to sigpending + sigwait for the others.

gdbsupport/ChangeLog:

	* scoped_ignore_signal.h (struct scoped_ignore_signal)
	<~scoped_ignore_signal>: Use sigtimedwait if HAVE_SIGTIMEDWAIT
	is defined, else use sigpending + sigwait.

Change-Id: I2a72798337e81dd1bbd21214736a139dd350af87
Co-Authored-By: John Baldwin <jhb@FreeBSD.org>
---
 gdbsupport/scoped_ignore_signal.h | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/gdbsupport/scoped_ignore_signal.h b/gdbsupport/scoped_ignore_signal.h
index a14c96779bf2..57dd4b6d4025 100644
--- a/gdbsupport/scoped_ignore_signal.h
+++ b/gdbsupport/scoped_ignore_signal.h
@@ -58,7 +58,6 @@ class scoped_ignore_signal
     if (!m_was_blocked)
       {
 	sigset_t set;
-	const timespec zero_timeout = {};
 
 	sigemptyset (&set);
 	sigaddset (&set, Sig);
@@ -66,7 +65,19 @@ class scoped_ignore_signal
 	/* If we got a pending Sig signal, consume it before
 	   unblocking.  */
 	if (ConsumePending)
-	  sigtimedwait (&set, nullptr, &zero_timeout);
+	  {
+#ifdef HAVE_SIGTIMEDWAIT
+	    const timespec zero_timeout = {};
+
+	    sigtimedwait (&set, nullptr, &zero_timeout);
+#else
+	    sigset_t pending;
+
+	    sigpending (&pending);
+	    if (sigismember (&pending, Sig))
+	      sigwait (&set, nullptr);
+#endif
+	  }
 
 	sigprocmask (SIG_UNBLOCK, &set, nullptr);
       }
-- 
2.32.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] gdbsupport/common.m4: check for sigtimedwait
  2021-06-27 19:13 [PATCH 1/2] gdbsupport/common.m4: check for sigtimedwait Simon Marchi
  2021-06-27 19:13 ` [PATCH 2/2] gdb: fall back on sigpending + sigwait if sigtimedwait is not available Simon Marchi
@ 2021-07-05 13:03 ` Pedro Alves
  1 sibling, 0 replies; 5+ messages in thread
From: Pedro Alves @ 2021-07-05 13:03 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 2021-06-27 8:13 p.m., Simon Marchi via Gdb-patches wrote:
> The next patch will make the use of sigtimedwait conditional to whether
> the platform provides it.  Start by adding a configure check for it.
> 
> gdbsupport/ChangeLog:
> 
> 	* common.m4 (GDB_AC_COMMON): Check for sigtimedwait.
> 	* config.in, configure: Re-generate.
> 
> gdb/ChangeLog:
> 
> 	* config.in, configure: Re-generate.
> 
> gdbserver/ChangeLog:
> 
> 	* config.in, configure: Re-generate.

OK.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] gdb: fall back on sigpending + sigwait if sigtimedwait is not available
  2021-06-27 19:13 ` [PATCH 2/2] gdb: fall back on sigpending + sigwait if sigtimedwait is not available Simon Marchi
@ 2021-07-05 13:03   ` Pedro Alves
  2021-07-05 13:57     ` Simon Marchi
  0 siblings, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2021-07-05 13:03 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 2021-06-27 8:13 p.m., Simon Marchi via Gdb-patches wrote:
> The macOS platform does not provide sigtimedwait, so we get:
> 
>       CXX    compile/compile.o
>     In file included from /Users/smarchi/src/binutils-gdb/gdb/compile/compile.c:46:
>     /Users/smarchi/src/binutils-gdb/gdb/../gdbsupport/scoped_ignore_signal.h:69:4: error: use of undeclared identifier 'sigtimedwait'
>               sigtimedwait (&set, nullptr, &zero_timeout);
>               ^
> 
> An alternative to sigtimedwait with a timeout of 0 is to use sigpending,
> to first check which signals are pending, and then sigwait, to consume
> them.  Since that's slightly more expensive (2 syscalls instead of 1),
> keep using sigtimedwait for the platforms that provide it, and fall back
> to sigpending + sigwait for the others.
> 
> gdbsupport/ChangeLog:
> 
> 	* scoped_ignore_signal.h (struct scoped_ignore_signal)
> 	<~scoped_ignore_signal>: Use sigtimedwait if HAVE_SIGTIMEDWAIT
> 	is defined, else use sigpending + sigwait.

OK.  Thanks for doing this.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] gdb: fall back on sigpending + sigwait if sigtimedwait is not available
  2021-07-05 13:03   ` Pedro Alves
@ 2021-07-05 13:57     ` Simon Marchi
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Marchi @ 2021-07-05 13:57 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On 2021-07-05 9:03 a.m., Pedro Alves wrote:
> On 2021-06-27 8:13 p.m., Simon Marchi via Gdb-patches wrote:
>> The macOS platform does not provide sigtimedwait, so we get:
>>
>>       CXX    compile/compile.o
>>     In file included from /Users/smarchi/src/binutils-gdb/gdb/compile/compile.c:46:
>>     /Users/smarchi/src/binutils-gdb/gdb/../gdbsupport/scoped_ignore_signal.h:69:4: error: use of undeclared identifier 'sigtimedwait'
>>               sigtimedwait (&set, nullptr, &zero_timeout);
>>               ^
>>
>> An alternative to sigtimedwait with a timeout of 0 is to use sigpending,
>> to first check which signals are pending, and then sigwait, to consume
>> them.  Since that's slightly more expensive (2 syscalls instead of 1),
>> keep using sigtimedwait for the platforms that provide it, and fall back
>> to sigpending + sigwait for the others.
>>
>> gdbsupport/ChangeLog:
>>
>> 	* scoped_ignore_signal.h (struct scoped_ignore_signal)
>> 	<~scoped_ignore_signal>: Use sigtimedwait if HAVE_SIGTIMEDWAIT
>> 	is defined, else use sigpending + sigwait.
> 
> OK.  Thanks for doing this.

Thanks, pushed to master and to gdb-11-branch (with ChangeLog entries).

Simon

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-07-05 13:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27 19:13 [PATCH 1/2] gdbsupport/common.m4: check for sigtimedwait Simon Marchi
2021-06-27 19:13 ` [PATCH 2/2] gdb: fall back on sigpending + sigwait if sigtimedwait is not available Simon Marchi
2021-07-05 13:03   ` Pedro Alves
2021-07-05 13:57     ` Simon Marchi
2021-07-05 13:03 ` [PATCH 1/2] gdbsupport/common.m4: check for sigtimedwait Pedro Alves

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).