4b94240
--- ./gdb/linux-nat.c	9 Feb 2007 20:52:16 -0000	1.56
4b94240
+++ ./gdb/linux-nat.c	22 Apr 2007 17:20:25 -0000
4b94240
@@ -378,9 +378,17 @@ child_follow_fork (struct target_ops *op
4b94240
       /* Detach new forked process?  */
4b94240
       if (detach_fork)
4b94240
 	{
4b94240
+	  static int advice_printed = 0;
4b94240
+
4b94240
+	  target_terminal_ours ();
4b94240
+	  fprintf_filtered (gdb_stdlog,
4b94240
+			 _("[Detaching after fork from child process %d.%s]\n"),
4b94240
+			    child_pid, (advice_printed ? "" :
4b94240
+					_(" (Try `set detach-on-fork off'.)")));
4b94240
+	  advice_printed = 1;
4b94240
+
4b94240
 	  if (debug_linux_nat)
4b94240
 	    {
4b94240
-	      target_terminal_ours ();
4b94240
 	      fprintf_filtered (gdb_stdlog,
4b94240
 				"Detaching after fork from child process %d.\n",
4b94240
 				child_pid);
4b94240
--- /dev/null	1 Jan 1970 00:00:00 -0000
4b94240
+++ ./gdb/testsuite/gdb.base/fork-detach.c	22 Apr 2007 17:20:25 -0000
4b94240
@@ -0,0 +1,57 @@
4b94240
+/* This testcase is part of GDB, the GNU debugger.
4b94240
+
4b94240
+   Copyright 2007 Free Software Foundation, Inc.
4b94240
+
4b94240
+   This program is free software; you can redistribute it and/or modify
4b94240
+   it under the terms of the GNU General Public License as published by
4b94240
+   the Free Software Foundation; either version 2 of the License, or
4b94240
+   (at your option) any later version.
4b94240
+
4b94240
+   This program is distributed in the hope that it will be useful,
4b94240
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
4b94240
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4b94240
+   GNU General Public License for more details.
4b94240
+ 
4b94240
+   You should have received a copy of the GNU General Public License
4b94240
+   along with this program; if not, write to the Free Software
4b94240
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4b94240
+
4b94240
+   Please email any bugs, comments, and/or additions to this file to:
4b94240
+   bug-gdb@prep.ai.mit.edu  */
4b94240
+
4b94240
+#include <sys/types.h>
4b94240
+#include <sys/wait.h>
4b94240
+#include <unistd.h>
4b94240
+#include <assert.h>
4b94240
+#include <stdlib.h>
4b94240
+
4b94240
+static void func (void)
4b94240
+{
4b94240
+}
4b94240
+
4b94240
+int main (void)
4b94240
+{
4b94240
+  pid_t child;
4b94240
+
4b94240
+  child = fork ();
4b94240
+  switch (child)
4b94240
+    {
4b94240
+      case -1:
4b94240
+	abort ();
4b94240
+      case 0:
4b94240
+	func ();
4b94240
+	break;
4b94240
+      default:
4b94240
+        {
4b94240
+/* We do not test the switching to the other fork by GDB `fork 1'.  */
4b94240
+#if 0
4b94240
+	  pid_t got;
4b94240
+
4b94240
+	  got = waitpid (child, NULL, 0);
4b94240
+	  assert (got == child);
4b94240
+#endif
4b94240
+	  break;
4b94240
+	}
4b94240
+    }
4b94240
+  return 0;
4b94240
+}
4b94240
--- /dev/null	1 Jan 1970 00:00:00 -0000
4b94240
+++ ./gdb/testsuite/gdb.base/fork-detach.exp	22 Apr 2007 17:20:25 -0000
4b94240
@@ -0,0 +1,43 @@
4b94240
+# Copyright 2007 Free Software Foundation, Inc.
4b94240
+
4b94240
+# This program is free software; you can redistribute it and/or modify
4b94240
+# it under the terms of the GNU General Public License as published by
4b94240
+# the Free Software Foundation; either version 2 of the License, or
4b94240
+# (at your option) any later version.
4b94240
+# 
4b94240
+# This program is distributed in the hope that it will be useful,
4b94240
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
4b94240
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4b94240
+# GNU General Public License for more details.
4b94240
+# 
4b94240
+# You should have received a copy of the GNU General Public License
4b94240
+# along with this program; if not, write to the Free Software
4b94240
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
4b94240
+
4b94240
+if $tracelevel then {
4b94240
+    strace $tracelevel
4b94240
+}
4b94240
+
4b94240
+set prms_id 0
4b94240
+set bug_id 0
4b94240
+
4b94240
+set testfile fork-detach
4b94240
+set srcfile ${testfile}.c
4b94240
+set binfile ${objdir}/${subdir}/${testfile}
4b94240
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
4b94240
+    untested "Couldn't compile test program"
4b94240
+    return -1
4b94240
+}
4b94240
+
4b94240
+# Get things started.
4b94240
+
4b94240
+gdb_exit
4b94240
+gdb_start
4b94240
+gdb_reinitialize_dir $srcdir/$subdir
4b94240
+gdb_load ${binfile}
4b94240
+
4b94240
+gdb_run_cmd
4b94240
+# `Starting program: .*' prefix is available since gdb-6.7.
4b94240
+gdb_test "" \
4b94240
+         "\\\[Detaching after fork from child process.*Program exited normally\\..*" \
4b94240
+         "Info message caught"