]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Fix gdb.threads/current-lwp-dead.exp race
authorPedro Alves <pedro@palves.net>
Wed, 23 Feb 2022 11:17:26 +0000 (11:17 +0000)
committerPedro Alves <pedro@palves.net>
Thu, 10 Mar 2022 11:35:53 +0000 (11:35 +0000)
commitb7b1008c0b1af5379656bd8e3063d01daf2bd764
treecd270d68a9c46bdcbcdf9c6a527c9e7b591c1a04
parentcdff184f42743670a499bbac6b69c2d504760a78
Fix gdb.threads/current-lwp-dead.exp race

If we make GDB report the process EXIT event for the leader thread, as
will be done in a latter patch of this series, then
gdb.threads/current-lwp-dead.exp starts failing:

 (gdb) break fn_return
 Breakpoint 2 at 0x5555555551b5: file /home/pedro/rocm/gdb/build/gdb/testsuite/../../../src/gdb/testsuite/gdb.threads/current-lwp-dead.c, line 45.
 (gdb) continue
 Continuing.
 [New LWP 2138466]
 [Inferior 1 (process 2138459) exited normally]
 (gdb) FAIL: gdb.threads/current-lwp-dead.exp: continue to breakpoint: fn_return (the program exited)

The inferior exit reported is actually correct.  The main thread has
indeed exited, and that's the thread that has the right exit code to
report to the user, as that's the exit code that is reported to the
program's parent.  In this case, GDB managed to collect the exit code
for the leader thread before reaping the other thread, because in
reality, the testcase isn't creating standard threads, it is using raw
clone, and the new clones are put in their own thread group.

Fix it by making the main "thread" not exit until the scenario we're
exercising plays out.  Also, run the program to completion for
completeness.

The original program really wanted the leader thread to exit before
the fn_return function was reached -- it was important that the
current thread as pointed by inferior_ptid was gone when infrun got
the breakpoint event.  I've tweaked the testcase to ensure that that
condition is still held, though it is no longer the main thread that
exits.  This required a bit of synchronization between the threads,
which required using CLONE_VM unconditionally.  The #ifdef guards were
added as a fix for
https://sourceware.org/bugzilla/show_bug.cgi?id=11214, though I don't
think they were necessary because the program is not using TLS.  If it
turns out they were necessary, we can link the testcase with "-z now"
instead, which was mentioned as an alternative workaround in that
Bugzilla.

Change-Id: I7be2f0da4c2fe8f80a60bdde5e6c623d8bd5a0aa
gdb/testsuite/gdb.threads/current-lwp-dead.c
gdb/testsuite/gdb.threads/current-lwp-dead.exp