Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [linux] fix stepping over fork in follow-child mode.
@ 2008-03-18 20:47 Pedro Alves
  2008-03-18 23:48 ` Daniel Jacobowitz
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2008-03-18 20:47 UTC (permalink / raw)
  To: GDB Patches

[-- 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 ();
     }

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-03-21 15:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-18 20:47 [linux] fix stepping over fork in follow-child mode Pedro Alves
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox