[binutils-gdb/gdb-11-branch] gdb: fall back on sigpending + sigwait if sigtimedwait is not available

Simon Marchi simark@sourceware.org
Mon Jul 5 13:56:50 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fa8740b675b0da1fa67370ccf042a78ae802b227

commit fa8740b675b0da1fa67370ccf042a78ae802b227
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Mon Jul 5 09:56:10 2021 -0400

    gdb: fall back on sigpending + sigwait if sigtimedwait is not available
    
    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>

Diff:
---
 gdbsupport/ChangeLog              |  6 ++++++
 gdbsupport/scoped_ignore_signal.h | 15 +++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog
index afe9171ff75..bb54ff82f86 100644
--- a/gdbsupport/ChangeLog
+++ b/gdbsupport/ChangeLog
@@ -1,3 +1,9 @@
+2021-07-05  Simon Marchi  <simon.marchi@polymtl.ca>
+
+	* scoped_ignore_signal.h (struct scoped_ignore_signal)
+	<~scoped_ignore_signal>: Use sigtimedwait if HAVE_SIGTIMEDWAIT
+	is defined, else use sigpending + sigwait.
+
 2021-07-05  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	* common.m4 (GDB_AC_COMMON): Check for sigtimedwait.
diff --git a/gdbsupport/scoped_ignore_signal.h b/gdbsupport/scoped_ignore_signal.h
index a14c96779bf..57dd4b6d402 100644
--- a/gdbsupport/scoped_ignore_signal.h
+++ b/gdbsupport/scoped_ignore_signal.h
@@ -58,7 +58,6 @@ public:
     if (!m_was_blocked)
       {
 	sigset_t set;
-	const timespec zero_timeout = {};
 
 	sigemptyset (&set);
 	sigaddset (&set, Sig);
@@ -66,7 +65,19 @@ public:
 	/* 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);
       }


More information about the Gdb-cvs mailing list