[binutils-gdb] Restore previous sigmask in gdb.block_signals

Tom Tromey tromey@sourceware.org
Mon Jul 31 12:37:01 GMT 2023


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

commit 30c01bb104e4dfc50e8cf3d0312bbf7d22f73d10
Author: Tom Tromey <tromey@adacore.com>
Date:   Fri Jul 28 12:02:38 2023 -0600

    Restore previous sigmask in gdb.block_signals
    
    Tom de Vries found a bug where, sometimes, a SIGCHLD would be
    delivered to a non-main thread, wreaking havoc.
    
    The problem is that gdb.block_signals after first blocking a set of
    signals, then unblocked the same set rather than restoring the initial
    situation.  This function being called from the DAP thread lead to
    SIGCHLD being unblocked there.
    
    This patch fixes the problem by restoring the previous set of signals
    instead.
    
    Tested-by: Tom de Vries <tdevries@suse.de>
    Reviewed-By: Tom de Vries <tdevries@suse.de>
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30680

Diff:
---
 gdb/python/lib/gdb/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index 98aadb1dfea..b3124369fe8 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -271,11 +271,11 @@ def blocked_signals():
         return
 
     to_block = {signal.SIGCHLD, signal.SIGINT, signal.SIGALRM, signal.SIGWINCH}
-    signal.pthread_sigmask(signal.SIG_BLOCK, to_block)
+    old_mask = signal.pthread_sigmask(signal.SIG_BLOCK, to_block)
     try:
         yield None
     finally:
-        signal.pthread_sigmask(signal.SIG_UNBLOCK, to_block)
+        signal.pthread_sigmask(signal.SIG_SETMASK, old_mask)
 
 
 class Thread(threading.Thread):


More information about the Gdb-cvs mailing list