Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 8/8] Fix PR gdb/14766 - vfork child exit with "set follow-fork-mode child" broken.
Date: Thu, 25 Oct 2012 17:42:00 -0000	[thread overview]
Message-ID: <20121025174247.13324.20062.stgit@brno.lan> (raw)
In-Reply-To: <20121025174002.13324.8164.stgit@brno.lan>

If "set detach-on-fork" is off (which it is by default), and we follow
the vfork child, we don't actually detach from the parent at vfork
time, but instead hold on to it until the child is done with the
shared memory region.  IOW, until the child execs or exits.  There's a
single function that handles all that work for both child execs and
exits, handle_vfork_child_exec_or_exit.  When that function goes about
detaching the parent, it tries to preserve the selected inferior (the
child), but while doing so, it is also trying to restore the selected
thread (as pointed at by inferior_ptid).  That makes sense for execs,
but not so for exits.  For exits, inferior_ptid, which has been
switched to the event ptid, does not point at a valid thread anymore.
Instead it just points at the process's pid.  The result is:

(gdb) r
Starting program:
/home/pedro/gdb/mygit/build/gdb/testsuite/gdb.base/foll-vfork-exit
[New process 4673]
I'm the child!
I'm the proud parent of child #4673!
Couldn't get registers: No such process.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Couldn't get registers: No such process.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Couldn't get registers: No such process.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(gdb)

The fix is not try to restore the thread, but just the inferior.

The bit in tcatch_vfork_then_child_follow_exit that kfails this PR is
just removed, as there's a specific test for this bug in the file.  It
was put there originally as this bug masked the gdb/14762 bug, and
thus the related gdb/14762 kfail in
tcatch_vfork_then_child_follow_exit was not reached.

gdb/
2012-10-25  Pedro Alves  <palves@redhat.com>

	PR gdb/14766

	* infrun.c (handle_inferior_event)
	<TARGET_WAITKIND_EXITED/TARGET_WAITKIND_SIGNALLED>: Switch to
	null_ptid before handling a vfork child exec or exit.  Switch to
	the event ptid afterwards.

gdb/testsuite/
2012-10-25  Pedro Alves  <palves@redhat.com>

	PR gdb/14766

	* gdb.base/foll-vfork.exp (vfork_child_follow_to_exit): Remove
	setup_kfail.
	(tcatch_vfork_then_child_follow_exit): No longer expect "Couldn't
	get registers".
---
 gdb/testsuite/gdb.base/foll-vfork.exp |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 0caa1ac..de9b137 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -663,7 +663,16 @@ handle_vfork_child_exec_or_exit (int exec)
 
 	  /* follow-fork child, detach-on-fork on.  */
 
-	  old_chain = make_cleanup_restore_current_thread ();
+	  if (!exec)
+	    {
+	      /* If we're handling a child exit, then inferior_ptid
+		 points at the inferior's pid, not to a thread.  */
+	      old_chain = save_inferior_ptid ();
+	      save_current_program_space ();
+	      save_current_inferior ();
+	    }
+	  else
+	    old_chain = save_current_space_and_thread ();
 
 	  /* We're letting loose of the parent.  */
 	  tp = any_live_thread_of_process (inf->vfork_parent->pid);
diff --git a/gdb/testsuite/gdb.base/foll-vfork.exp b/gdb/testsuite/gdb.base/foll-vfork.exp
index ca04cdc..12f7ec7 100644
--- a/gdb/testsuite/gdb.base/foll-vfork.exp
+++ b/gdb/testsuite/gdb.base/foll-vfork.exp
@@ -162,7 +162,7 @@ proc vfork_child_follow_to_exit {} {
    set test "continue to child exit"
    gdb_test_multiple "continue" $test {
       -re "Couldn't get registers.*$gdb_prompt " {
-	  setup_kfail "gdb/14766" *-*-*
+	  # PR gdb/14766
 	  fail "$test"
       }
       -re "Attaching after.* vfork to.*Detaching vfork parent .* after child exit.*$gdb_prompt " {
@@ -367,10 +367,6 @@ proc tcatch_vfork_then_child_follow_exit {} {
 
    set test "finish"
    gdb_test_multiple "finish" $test {
-      -re "Couldn't get registers.*$gdb_prompt " {
-	  setup_kfail "gdb/14766" *-*-*
-	  fail "$test "
-      }
       -re "Run till exit from.*vfork.*exited normally.*$gdb_prompt " {
 	  setup_kfail "gdb/14762" *-*-*
 	  fail $test


  parent reply	other threads:[~2012-10-25 17:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-25 17:42 [PATCH 0/8] Fix PR gdb/14766; cleanup foll-vfork.exp and extend it Pedro Alves
2012-10-25 17:42 ` [PATCH 7/8] foll-vfork.exp: Also test following vfork when the child exits Pedro Alves
2012-10-25 17:42 ` [PATCH 2/8] foll-vfork.exp: Don't hard code line numbers Pedro Alves
2012-10-25 17:42 ` [PATCH 6/8] foll-vfork.exp: Clean restart gdb before each test procedure Pedro Alves
2012-11-02 18:18   ` Pedro Alves
2012-10-25 17:42 ` [PATCH 5/8] foll-vfork.exp: Use with_test_prefix Pedro Alves
2012-10-25 17:42 ` Pedro Alves [this message]
2012-10-25 17:49   ` [PATCH 8/8] Fix PR gdb/14766 - vfork child exit with "set follow-fork-mode child" broken Pedro Alves
2012-10-25 17:42 ` [PATCH 4/8] foll-vfork.c/vforked-prog.c: Add copyright headers Pedro Alves
2012-10-25 17:42 ` [PATCH 3/8] foll-vfork.exp: Expose more testing on non-HP/UX targets Pedro Alves
2012-10-25 17:42 ` [PATCH 1/8] foll-vfork.exp: Modernize Pedro Alves
2012-10-30 20:50 ` [PATCH 0/8] Fix PR gdb/14766; cleanup foll-vfork.exp and extend it Tom Tromey
2012-11-02 18:15   ` Pedro Alves

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=20121025174247.13324.20062.stgit@brno.lan \
    --to=palves@redhat.com \
    --cc=gdb-patches@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