From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10664 invoked by alias); 18 Mar 2008 20:47:07 -0000 Received: (qmail 10652 invoked by uid 22791); 18 Mar 2008 20:47:05 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 18 Mar 2008 20:46:47 +0000 Received: (qmail 22863 invoked from network); 18 Mar 2008 20:46:45 -0000 Received: from unknown (HELO orlando) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 18 Mar 2008 20:46:45 -0000 From: Pedro Alves To: GDB Patches Subject: [linux] fix stepping over fork in follow-child mode. Date: Tue, 18 Mar 2008 20:47:00 -0000 User-Agent: KMail/1.9.6 (enterprise 0.20070907.709405) MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_2oC4Hlkm2gOzV0p" Message-Id: <200803182046.46420.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-03/txt/msg00260.txt.bz2 --Boundary-00=_2oC4Hlkm2gOzV0p Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 971 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 --Boundary-00=_2oC4Hlkm2gOzV0p Content-Type: text/x-diff; charset="us-ascii"; name="follow_fork_child_step_resume.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="follow_fork_child_step_resume.diff" Content-length: 2224 2008-03-18 Pedro Alves 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 (); } --Boundary-00=_2oC4Hlkm2gOzV0p--