Re: [PATCH v2] [gdb] Prune inferior after switching inferior

Tom de Vries
2024-08-18T19:00:36Z

On 8/18/24 20:43, Kevin Buettner wrote:
> On Wed, 31 Jul 2024 09:46:05 +0200
> Tom de Vries <tdevries@suse.de> wrote:
>
>> Usually with test-case gdb.python/py-progspace-events.exp I get:
>> ...
>> (gdb) inferior 1^M
>> [Switching to inferior 1 [process 4116] (py-progspace-events)]^M
>> [Switching to thread 1.1 (Thread 0xf77d0ce0 (LWP 4116))]^M
>> 28 { /* Nothing. */ }^M
>> (gdb) PASS: gdb.python/py-progspace-events.exp: inferior 1
>> step^M
>> FreeProgspaceEvent: <gdb.Progspace object at 0xabf4f850>^M
>> do_parent_stuff () at py-progspace-events.c:41^M
>> 41 ++global_var;^M
>> (gdb) PASS: gdb.python/py-progspace-events.exp: step
>> ...
>>
>> But occasionally I run into the following FAIL:
>> ...
>> (gdb) inferior 1^M
>> [Switching to inferior 1 [process 5199] (py-progspace-events)]^M
>> [Switching to thread 1.1 (Thread 0xf77d0ce0 (LWP 5199))]^M
>> 28 { /* Nothing. */ }^M
>> (gdb) FreeProgspaceEvent: <gdb.Progspace object at 0xabaf03a0>^M
>> FAIL: gdb.python/py-progspace-events.exp: inferior 1 (timeout)
>> ...
>>
>> This is caused by a race between the handling of an event, and the
>> "inferior 1" command.
>>
>> In the passing case, the event is handled first. During which prune_inferiors
>> is called, but it can't remove inferior 2, because it's still the current one.
>>
>> In the failing case, the "inferior 1" command is handled first. Then during
>> handling of the event, prune_inferiors is called, and it can remove inferior 2
>> because it's no longer the current one.
>>
>> This looks like a test-case issue to me, but ISTM that we can do better: by
>> calling prune_inferiors asap, at the end of the "inferior 1" command, we
>> stabilize the moment when the inferior is removed:
>> ...
>> (gdb) inferior 1^M
>> [Switching to inferior 1 [process 5199] (py-progspace-events)]^M
>> [Switching to thread 1.1 (Thread 0xf77d0ce0 (LWP 5199))]^M
>> 28 { /* Nothing. */ }^M
>> FreeProgspaceEvent: <gdb.Progspace object at 0xabaf03a0>^M
>> (gdb) PASS: gdb.python/py-progspace-events.exp: inferior 1
>> ...
>>
>> This also allows us to simplify the test-case by removing the step command,
>> which is no longer required to trigger the pruning of the inferior.
>>
>> Tested on x86_64-linux.
>>
>> PR gdb/31440
>> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31440
>
> Approved-by: Kevin Buettner <kevinb@redhat.com>
>

Hi Kevin,

thanks for the review, pushed.

- Tom