[PATCH] gdb/linux-nat: use LP's inferior when handling vfork done in linux_handle_extended_wait

Tom Tromey tom@tromey.com
Thu Aug 12 19:36:13 GMT 2021


Simon> I spotted this bug by reading the code and subsequently wrote a test to
Simon> reproduce it.  The bug is caught by the assertions that are added.
Simon> Otherwise the bug wouldn't cause a visible problem, but GDB would still
Simon> be in a wrong state.

This explanation is really great.

Simon> the bug explained above happens and waiting_for_vfork_done stays
Simon> wrongfully set, the assertion will fail when a different event.

The clause after the "," is missing some text, I guess something like
"when a different even is received".

Simon> If I run the test without the fix in linux-nat.c, I get:

Simon>     run^M
Simon>     Starting program: /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/vfork-multi-inferior/vfork-multi-inferior-vforker ^M
Simon>     [Detaching after vfork from child process 822537]^M
Simon>     /home/simark/src/binutils-gdb/gdb/infrun.c:5255: internal-error: void handle_inferior_event(execution_control_state*): Assertion `!inf->waiting_for_vfork_    done' failed.^M

Looks like some strange word wrapping in here, those spaces before the "done".

Simon>    if (event == PTRACE_EVENT_VFORK_DONE)
Simon>      {
Simon> -      if (current_inferior ()->waiting_for_vfork_done)
Simon> +      inferior *inf = find_inferior_ptid (linux_target, lp->ptid);
Simon> +
Simon> +      if (inf->waiting_for_vfork_done)

I was curious about this and looked, and saw that this is the only use
of current_inferior in this function.  A downside of our globals-based
approach is that it's hard to enforce a rule poisoning this kind of use
here.  Oh well.

Simon> index 000000000000..cb3f3d6abd78
Simon> --- /dev/null
Simon> +++ b/gdb/testsuite/gdb.base/vfork-multi-inferior-other.c
Simon> @@ -0,0 +1,12 @@
Simon> +#include <unistd.h>
Simon> +

I think we normally are sticking the GPL comment in all new files.

Otherwise this all looks reasonable to me.

Tom


More information about the Gdb-patches mailing list