public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Restore previous sigmask in gdb.block_signals
@ 2023-07-28 18:10 Tom Tromey
  2023-07-29  6:25 ` Tom de Vries
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2023-07-28 18:10 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom de Vries, Tom Tromey

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 was unblocking the signals it
blocked -- but it was being called from the DAP thread, leading to
SIGCHLD being unblocked there.

This patch fixes the problem by restoring the previous set of signals
instead.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30680
---
 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):
-- 
2.40.1


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

* Re: [PATCH] Restore previous sigmask in gdb.block_signals
  2023-07-28 18:10 [PATCH] Restore previous sigmask in gdb.block_signals Tom Tromey
@ 2023-07-29  6:25 ` Tom de Vries
  2023-07-29  6:37   ` Tom de Vries
  0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2023-07-29  6:25 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 7/28/23 20:10, Tom Tromey wrote:
> 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 was unblocking the signals it
> blocked -- but it was being called from the DAP thread, leading to
> SIGCHLD being unblocked there.
> 
> This patch fixes the problem by restoring the previous set of signals
> instead.
> 

I've done a build and reg-test on x86_64-linux, no regressions.

I also build this in combination with the assert patch mentioned in the 
PR, and ran the dap tests 50 times, and the assert no longer triggers.

Also, the patch LGTM.

I had a bit of trouble parsing the commit message, I'd suggest for 
instance instead:
...
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.
...

Tested-by: Tom de Vries <tdevries@suse.de>
Reviewed-By: Tom de Vries <tdevries@suse.de>

Thanks,
- Tom

> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30680
> ---
>   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):


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

* Re: [PATCH] Restore previous sigmask in gdb.block_signals
  2023-07-29  6:25 ` Tom de Vries
@ 2023-07-29  6:37   ` Tom de Vries
  0 siblings, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2023-07-29  6:37 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 7/29/23 08:25, Tom de Vries via Gdb-patches wrote:
> On 7/28/23 20:10, Tom Tromey wrote:
>> 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 was unblocking the signals it
>> blocked -- but it was being called from the DAP thread, leading to
>> SIGCHLD being unblocked there.
>>
>> This patch fixes the problem by restoring the previous set of signals
>> instead.
>>
> 
> I've done a build and reg-test on x86_64-linux, no regressions.
> 
> I also build this in combination with the assert patch mentioned in the 
> PR, and ran the dap tests 50 times, and the assert no longer triggers.
> 

Also, I build with -fsanitize=thread and tested the dap tests, that's 
also clean now.

Thanks,
- Tom

> Also, the patch LGTM.
> 
> I had a bit of trouble parsing the commit message, I'd suggest for 
> instance instead:
> ...
> 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.
> ...
> 
> Tested-by: Tom de Vries <tdevries@suse.de>
> Reviewed-By: Tom de Vries <tdevries@suse.de>
> 
> Thanks,
> - Tom
> 
>> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30680
>> ---
>>   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):
> 


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

end of thread, other threads:[~2023-07-29  6:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-28 18:10 [PATCH] Restore previous sigmask in gdb.block_signals Tom Tromey
2023-07-29  6:25 ` Tom de Vries
2023-07-29  6:37   ` Tom de Vries

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