Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: GDB Patches <gdb-patches@sourceware.org>
Subject: [linux] fix stepping over fork in follow-child mode.
Date: Tue, 18 Mar 2008 20:47:00 -0000	[thread overview]
Message-ID: <200803182046.46420.pedro@codesourcery.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 971 bytes --]

Hi,

I noticed that issuing a next over a fork call, with
"follow-fork-mode child", wasn't working.  The problem is that when we
update the breakpoints in the child to attach them to the current thread
if their thread their currently attached to doesn't exist anymore, 
inferior_ptid doesn't hold the tid yet.

static int
linux_child_follow_fork (struct target_ops *ops, int follow_child)

(...)

      inferior_ptid = ptid_build (child_pid, child_pid, 0);

      /* Reinstall ourselves, since we might have been removed in
	 target_detach (which does other necessary cleanup).  */

      push_target (ops);
      linux_nat_switch_fork (inferior_ptid);
      check_for_thread_db ();

      /* Reset breakpoints in the child as appropriate.  */
      follow_inferior_reset_breakpoints (); <- this would fail
    }

The patch attached updates fork-child-threads.exp with a
test that would fail without the fix.

No regressions on x86_64-unknown-linux-gnu.

-- 
Pedro Alves

[-- Attachment #2: follow_fork_child_step_resume.diff --]
[-- Type: text/x-diff, Size: 2224 bytes --]

2008-03-18  Pedro Alves  <pedro@codesourcery.com>

	gdb/
	* linux-nat.c (linux_child_follow_fork): Update inferior_ptid with
	the thread id.

	gdb/testsuite/
	gdb.threads/fork-child-threads.exp: Add "next" test.

---
 gdb/linux-nat.c                                  |    9 +++++++++
 gdb/testsuite/gdb.threads/fork-child-threads.exp |    1 +
 2 files changed, 10 insertions(+)

Index: src/gdb/testsuite/gdb.threads/fork-child-threads.exp
===================================================================
--- src.orig/gdb/testsuite/gdb.threads/fork-child-threads.exp	2008-03-18 18:31:12.000000000 +0000
+++ src/gdb/testsuite/gdb.threads/fork-child-threads.exp	2008-03-18 18:31:53.000000000 +0000
@@ -38,6 +38,7 @@ if ![runto_main] then {
 
 gdb_test "set follow-fork-mode child"
 gdb_breakpoint "start"
+gdb_test "next" ".*pthread_create \\(&thread, NULL, start, NULL\\);.*" "next over fork"
 gdb_test "continue" "Breakpoint 2, start.*" "get to the spawned thread"
 
 # Wrong:
Index: src/gdb/linux-nat.c
===================================================================
--- src.orig/gdb/linux-nat.c	2008-03-18 20:25:45.000000000 +0000
+++ src/gdb/linux-nat.c	2008-03-18 20:26:04.000000000 +0000
@@ -104,6 +104,8 @@ static LONGEST (*super_xfer_partial) (st
 				      const gdb_byte *,
 				      ULONGEST, LONGEST);
 
+static int find_thread_from_lwp (struct thread_info *thr, void *dummy);
+
 static int debug_linux_nat;
 static void
 show_debug_linux_nat (struct ui_file *file, int from_tty,
@@ -460,6 +462,7 @@ linux_child_follow_fork (struct target_o
   else
     {
       char child_pid_spelling[40];
+      struct thread_info *thr;
 
       /* Needed to keep the breakpoint lists in sync.  */
       if (! has_vforked)
@@ -519,6 +522,12 @@ linux_child_follow_fork (struct target_o
       linux_nat_switch_fork (inferior_ptid);
       check_for_thread_db ();
 
+      /* Update inferior_ptid to include the thread id, so updating
+	 step-resume breakpoints in the child works.  */
+      thr = iterate_over_threads (find_thread_from_lwp, &inferior_ptid);
+      if (thr)
+	inferior_ptid = thr->ptid;
+
       /* Reset breakpoints in the child as appropriate.  */
       follow_inferior_reset_breakpoints ();
     }

             reply	other threads:[~2008-03-18 20:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-18 20:47 Pedro Alves [this message]
2008-03-18 23:48 ` Daniel Jacobowitz
     [not found]   ` <frqh16$7rk$1@ger.gmane.org>
2008-03-19 12:49     ` Daniel Jacobowitz
2008-03-19 16:03   ` Daniel Jacobowitz
2008-03-19 19:22     ` Joel Brobecker
2008-03-19 19:27       ` Daniel Jacobowitz
2008-03-19 22:19     ` Nick Roberts
2008-03-19 22:47       ` Daniel Jacobowitz
2008-03-21 15:45         ` Daniel Jacobowitz

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=200803182046.46420.pedro@codesourcery.com \
    --to=pedro@codesourcery.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