Skip to content

Commit 04a6df8

Browse files
simarkbsdjhb
authored andcommitted
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 <[email protected]>
1 parent 116a737 commit 04a6df8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

gdbsupport/scoped_ignore_signal.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,26 @@ class scoped_ignore_signal
5858
if (!m_was_blocked)
5959
{
6060
sigset_t set;
61-
const timespec zero_timeout = {};
6261

6362
sigemptyset (&set);
6463
sigaddset (&set, Sig);
6564

6665
/* If we got a pending Sig signal, consume it before
6766
unblocking. */
6867
if (ConsumePending)
69-
sigtimedwait (&set, nullptr, &zero_timeout);
68+
{
69+
#ifdef HAVE_SIGTIMEDWAIT
70+
const timespec zero_timeout = {};
71+
72+
sigtimedwait (&set, nullptr, &zero_timeout);
73+
#else
74+
sigset_t pending;
75+
76+
sigpending (&pending);
77+
if (sigismember (&pending, Sig))
78+
sigwait (&set, nullptr);
79+
#endif
80+
}
7081

7182
sigprocmask (SIG_UNBLOCK, &set, nullptr);
7283
}

0 commit comments

Comments
 (0)