public inbox for gdb-testers@sourceware.org
help / color / mirror / Atom feed
From: sergiodj+buildbot@sergiodj.net
To: gdb-testers@sourceware.org
Subject: [binutils-gdb] [gdb] Handle vfork in thread with follow-fork-mode child
Date: Thu, 18 Apr 2019 16:30:00 -0000	[thread overview]
Message-ID: <b73715df01e6e9b3de5a49cd7bf4170deef48461@gdb-build> (raw)

*** TEST RESULTS FOR COMMIT b73715df01e6e9b3de5a49cd7bf4170deef48461 ***

Author: Tom de Vries <tdevries@suse.de>
Branch: master
Commit: b73715df01e6e9b3de5a49cd7bf4170deef48461

[gdb] Handle vfork in thread with follow-fork-mode child

When debugging any of the testcases added by this commit, which do a
vfork in a thread with "set follow-fork-mode child" + "set
detach-on-fork on", we run into this assertion:

...
src/gdb/nat/x86-linux-dregs.c:146: internal-error: \
  void x86_linux_update_debug_registers(lwp_info*): \
  Assertion `lwp_is_stopped (lwp)' failed.
...

The assert is caused by the following: the vfork-child exit or exec
event is handled by handle_vfork_child_exec_or_exit, which calls
target_detach to detach from the vfork parent.  During target_detach
we call linux_nat_target::detach, which:

#1 - stops all the threads
#2 - waits for all the threads to be stopped
#3 - detaches all the threads

However, during the second step we run into this code in
stop_wait_callback:

...
  /* If this is a vfork parent, bail out, it is not going to report
     any SIGSTOP until the vfork is done with.  */
  if (inf->vfork_child != NULL)
    return 0;
...

and we don't wait for the threads to be stopped, which results in this
assert in x86_linux_update_debug_registers triggering during the third
step:

...
  gdb_assert (lwp_is_stopped (lwp));
...

The fix is to reset the vfork parent's vfork_child field before
calling target_detach in handle_vfork_child_exec_or_exit.  There's
already similar code for the other paths handled by
handle_vfork_child_exec_or_exit, so this commit refactors the code a
bit so that all paths share the same code.

The new tests cover both a vfork child exiting, and a vfork child
execing, since both cases would trigger the assertion.

The new testcases also exercise following the vfork children with "set
detach-on-fork off", since it doesn't seem to be tested anywhere.

Tested on x86_64-linux, using native and native-gdbserver.

gdb/ChangeLog:
2019-04-18  Tom de Vries  <tdevries@suse.de>
	    Pedro Alves  <palves@redhat.com>

	PR gdb/24454
	* infrun.c (handle_vfork_child_exec_or_exit): Reset vfork parent's
	vfork_child field before calling target_detach.

gdb/testsuite/ChangeLog:
2019-04-18  Tom de Vries  <tdevries@suse.de>
	    Pedro Alves  <palves@redhat.com>

	PR gdb/24454
	* gdb.threads/vfork-follow-child-exec.c: New file.
	* gdb.threads/vfork-follow-child-exec.exp: New file.
	* gdb.threads/vfork-follow-child-exit.c: New file.
	* gdb.threads/vfork-follow-child-exit.exp: New file.


             reply	other threads:[~2019-04-18 16:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-18 16:30 sergiodj+buildbot [this message]
2019-04-18 16:52 ` Failures on RHEL-s390x-m64, branch master sergiodj+buildbot
2019-04-18 18:03 ` Failures on Debian-s390x-native-gdbserver-m64, " sergiodj+buildbot
2019-04-18 18:04 ` Failures on Debian-s390x-m64, " sergiodj+buildbot
2019-04-23  9:06 ` Failures on Fedora-x86_64-native-gdbserver-m64, " sergiodj+buildbot
2019-04-23  9:10 ` Failures on Fedora-x86_64-m64, " sergiodj+buildbot
2019-04-23  9:42 ` Failures on Fedora-x86_64-native-gdbserver-m32, " sergiodj+buildbot
2019-04-24  3:12 ` Failures on Fedora-x86_64-cc-with-index, " sergiodj+buildbot
2019-04-26 23:21 ` Failures on Fedora-x86_64-native-extended-gdbserver-m32, " sergiodj+buildbot
2019-05-01  1:57 ` Failures on Fedora-x86_64-m32, " sergiodj+buildbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b73715df01e6e9b3de5a49cd7bf4170deef48461@gdb-build \
    --to=sergiodj+buildbot@sergiodj.net \
    --cc=gdb-testers@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).