This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[linux] fix stepping over fork in follow-child mode.
- From: Pedro Alves <pedro at codesourcery dot com>
- To: GDB Patches <gdb-patches at sourceware dot org>
- Date: Tue, 18 Mar 2008 20:46:46 +0000
- Subject: [linux] fix stepping over fork in follow-child mode.
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
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 ();
}