[PATCH] gdb: iterate only on vfork parent threads in handle_vfork_child_exec_or_exit
John Baldwin
jhb@FreeBSD.org
Thu Aug 5 17:08:57 GMT 2021
On 8/5/21 9:21 AM, Simon Marchi via Gdb-patches wrote:
> I spotted what I think is a buglet in proceed_after_vfork_done. After a
> vfork child exits or execs, we resume all the threads of the parent. To
> do so, we iterate on all threads using iterate_over_threads with the
> proceed_after_vfork_done callback. Each thread is resumed if the
> following condition is true:
>
> if (thread->ptid.pid () == pid
> && thread->state == THREAD_RUNNING
> && !thread->executing
> && !thread->stop_requested
> && thread->stop_signal () == GDB_SIGNAL_0)
>
> where `pid` is the pid of the vfork parent. This is not multi-target
> aware: since it only filters on pid, if there is an inferior with the
> same pid in another target, we could end up resuming a thread of that
> other inferior. The chances of the stars aligning for this to happen
> are tiny, but still.
>
> Fix that by iterating only on the vfork parent's threads, instead of on
> all threads. This is more efficient, as we iterate on just the required
> threads (inferiors have their own thread list), and we can drop the pid
> check. The resulting code is also more straightforward in my opinion,
> so it's a win-win.
This looks sensible to me.
--
John Baldwin
More information about the Gdb-patches
mailing list