This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix gdb.base/fork-running-state.exp race


On 2018-03-28 11:06, Pedro Alves wrote:
On my multi-target branch I was occasionaly seeing a FAIL like this:

  (gdb) PASS: gdb.base/fork-running-state.exp: detach-on-fork=off:
follow-fork=parent: non-stop: kill parent
  [Inferior 2 (process 32672) exited normally]
  kill inferior 2
  warning: Inferior ID 2 is not running.
  (gdb) FAIL: gdb.base/fork-running-state.exp: detach-on-fork=off:
follow-fork=parent: non-stop: kill child (the program exited)
  ... other similar fails ...

Turns out to be a testcase bug/race.  A tweak like this increases the
changes of hitting the race substancially:

  --- a/gdb/testsuite/gdb.base/fork-running-state.c
  +++ b/gdb/testsuite/gdb.base/fork-running-state.c
  @@ -29,7 +29,7 @@ fork_child (void)
   {
     while (1)
       {
  -      sleep (1);
  +      usleep (100);


The testcase has two processes, parent and child fork.  The problem is
that the child exits itself if it notices the parent is gone, but the
testcase .exp does not expect that.

I first wrote a patch that handled the different combinations of
non-stop/detach-on-fork/follow-fork/schedule-multiple, making the .exp
file know when to expect the child to exit itself vs when to kill it
explicitly, but the result was that the code to kill the parent and
child was getting about as large as the test code that is the actual
point of the testcase, above the kills.

So I scratched that approach and came up with a simpler patch --
simply make the child not exit itself when the parent exits.

The .exp file is going to kill both parent and child explicitly, and,
main() already calls alarm() as a safeguard.  I don't think we lose
anything.

Does the parent exit as part of the test, or only when we kill it at the end when we clean up?

If I understand correctly, we kill the parent, and by the time we want to kill the child, it has already noticed the parent is gone and has itself exited, is that right? In that case I think it makes sense to have only one way of cleaning up, either we kill the process or we let it exit, not both. So the patch LGTM.

Simon


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]