bd518c3
[base]
bd518c3
bd518c3
2007-10-13  Jan Kratochvil  <jan.kratochvil@redhat.com>
bd518c3
bd518c3
	* linux-nat.c (iterate_over_lwps): Fixed missing LWP initialization for
bd518c3
	current INFERIOR_PTID.
bd518c3
bd518c3
2007-10-13  Jan Kratochvil  <jan.kratochvil@redhat.com>
bd518c3
bd518c3
	* gdb.base/follow-child.exp, gdb.base/follow-child.c: New files.
bd518c3
eb9d945
2007-10-16  Jan Kratochvil  <jan.kratochvil@redhat.com>
eb9d945
eb9d945
	Port to GDB-6.7.
eb9d945
25ff8a1
2008-02-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
25ff8a1
25ff8a1
	Port to GDB-6.8pre.
25ff8a1
25ff8a1
Index: gdb-6.8cvs20080219/gdb/doc/observer.texi
9231e41
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/doc/observer.texi	2007-10-09 13:06:07.000000000 +0200
25ff8a1
+++ gdb-6.8cvs20080219/gdb/doc/observer.texi	2008-02-21 17:45:46.000000000 +0100
9231e41
@@ -119,6 +119,10 @@ when @value{GDBN} calls this observer, t
9231e41
 haven't been loaded yet.
0e6ea41
 @end deftypefun
0e6ea41
 
0e6ea41
+@deftypefun void mourn_inferior (struct target_ops *@var{target})
0e6ea41
+@value{GDBN} has just detached from an inferior.
0e6ea41
+@end deftypefun
0e6ea41
+
0e6ea41
 @deftypefun void solib_unloaded (struct so_list *@var{solib})
9231e41
 The shared library specified by @var{solib} has been unloaded.
0e6ea41
 @end deftypefun
25ff8a1
Index: gdb-6.8cvs20080219/gdb/linux-nat.c
9231e41
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/linux-nat.c	2008-02-21 17:45:45.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/linux-nat.c	2008-02-22 08:12:57.000000000 +0100
25ff8a1
@@ -37,6 +37,7 @@
25ff8a1
 #include "regset.h"
25ff8a1
 #include "inf-ptrace.h"
25ff8a1
 #include "auxv.h"
25ff8a1
+#include "observer.h"
25ff8a1
 #include <sys/param.h>		/* for MAXPATHLEN */
25ff8a1
 #include <sys/procfs.h>		/* for elf_gregset etc. */
25ff8a1
 #include "elf-bfd.h"		/* for elfcore_write_* */
25ff8a1
@@ -751,11 +752,26 @@ iterate_over_lwps (int (*callback) (stru
bc60002
 {
bc60002
   struct lwp_info *lp, *lpnext;
bc60002
 
bc60002
-  for (lp = lwp_list; lp; lp = lpnext)
bc60002
+  if (lwp_list != NULL)
bc60002
     {
bc60002
-      lpnext = lp->next;
bc60002
+      for (lp = lwp_list; lp; lp = lpnext)
bc60002
+        {
bc60002
+          lpnext = lp->next;
bc60002
+          if ((*callback) (lp, data))
bc60002
+	    return lp;
bc60002
+        }
bc60002
+    }
bc60002
+  else
bc60002
+    {
bc60002
+      /* We are calling iterate_over_lwps for a non-threaded program.
bc60002
+         Initialize the lwp list to the inferior's ptid.  */
bd518c3
+      gdb_assert (!is_lwp (inferior_ptid));
bd518c3
+
bd518c3
+      inferior_ptid = BUILD_LWP (GET_PID (inferior_ptid),
bd518c3
+				 GET_PID (inferior_ptid));
bd518c3
+      lp = add_lwp (inferior_ptid);
bc60002
       if ((*callback) (lp, data))
bc60002
-	return lp;
bc60002
+        return lp;
bc60002
     }
bc60002
 
bc60002
   return NULL;
25ff8a1
@@ -3319,6 +3335,18 @@ linux_nat_get_siginfo (ptid_t ptid)
25ff8a1
   return &lp->siginfo;
bc60002
 }
bc60002
 
0e6ea41
+/* Observer function for a mourn inferior event.  This is needed
bc60002
+   because if iterate_over_lwps is called for a non-threaded program
bc60002
+   to handle watchpoints, the lwp list gets initialized but there is
0e6ea41
+   no corresponding clean-up when the inferior is detached.  In
0e6ea41
+   a threaded program, the observer is simply redundant as the
0e6ea41
+   same clean-up gets done in linux_nat_mourn_inferior.  */
bc60002
+static void
0e6ea41
+linux_nat_mourn_inferior_observer (struct target_ops *objfile)
bc60002
+{
bc60002
+  init_lwp_list ();
bc60002
+}
bc60002
+
bc60002
 void
bc60002
 _initialize_linux_nat (void)
bc60002
 {
25ff8a1
@@ -3333,6 +3361,8 @@ Specify any of the following keywords fo
bc60002
   status   -- list a different bunch of random process info.\n\
9231e41
   all      -- list all available /proc info."));
0e6ea41
 
9231e41
+  observer_attach_mourn_inferior (linux_nat_mourn_inferior_observer);
9231e41
+
9231e41
   /* Save the original signal mask.  */
9231e41
   sigprocmask (SIG_SETMASK, NULL, &normal_mask);
9231e41
 
25ff8a1
Index: gdb-6.8cvs20080219/gdb/target.c
9231e41
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/target.c	2008-02-14 23:04:00.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/target.c	2008-02-22 08:10:37.000000000 +0100
eb9d945
@@ -39,6 +39,7 @@
0e6ea41
 #include "gdbcore.h"
aefb0e1
 #include "exceptions.h"
eb9d945
 #include "target-descriptions.h"
0e6ea41
+#include "observer.h"
0e6ea41
 
0e6ea41
 static void target_info (char *, int);
0e6ea41
 
eb9d945
@@ -275,6 +276,13 @@ target_load (char *arg, int from_tty)
0e6ea41
   (*current_target.to_load) (arg, from_tty);
0e6ea41
 }
0e6ea41
 
0e6ea41
+void
0e6ea41
+target_mourn_inferior (void)
0e6ea41
+{
0e6ea41
+  (*current_target.to_mourn_inferior) ();
0e6ea41
+  observer_notify_mourn_inferior (&current_target);
0e6ea41
+}
0e6ea41
+
0e6ea41
 static int
0e6ea41
 nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
0e6ea41
 	  struct target_ops *t)
25ff8a1
Index: gdb-6.8cvs20080219/gdb/target.h
9231e41
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/target.h	2008-01-02 00:04:05.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/target.h	2008-02-22 08:10:37.000000000 +0100
25ff8a1
@@ -861,8 +861,7 @@ int target_follow_fork (int follow_child
0e6ea41
 
0e6ea41
 /* The inferior process has died.  Do what is right.  */
0e6ea41
 
0e6ea41
-#define	target_mourn_inferior()	\
0e6ea41
-     (*current_target.to_mourn_inferior) ()
0e6ea41
+extern void target_mourn_inferior (void);
0e6ea41
 
0e6ea41
 /* Does target have enough data to do a run or attach command? */
0e6ea41
 
25ff8a1
Index: gdb-6.8cvs20080219/gdb/testsuite/gdb.base/follow-child.c
25ff8a1
===================================================================
25ff8a1
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
25ff8a1
+++ gdb-6.8cvs20080219/gdb/testsuite/gdb.base/follow-child.c	2008-02-22 08:14:04.000000000 +0100
bd518c3
@@ -0,0 +1,29 @@
bd518c3
+/* This testcase is part of GDB, the GNU debugger.
bd518c3
+
bd518c3
+   Copyright 2007 Free Software Foundation, Inc.
bd518c3
+
bd518c3
+   This program is free software; you can redistribute it and/or modify
bd518c3
+   it under the terms of the GNU General Public License as published by
bd518c3
+   the Free Software Foundation; either version 2 of the License, or
bd518c3
+   (at your option) any later version.
bd518c3
+
bd518c3
+   This program is distributed in the hope that it will be useful,
bd518c3
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bd518c3
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
bd518c3
+   GNU General Public License for more details.
25ff8a1
+
bd518c3
+   You should have received a copy of the GNU General Public License
bd518c3
+   along with this program; if not, write to the Free Software
bd518c3
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
bd518c3
+
bd518c3
+   Please email any bugs, comments, and/or additions to this file to:
bd518c3
+   bug-gdb@prep.ai.mit.edu  */
bd518c3
+
bd518c3
+#include <unistd.h>
bd518c3
+
bd518c3
+int main()
bd518c3
+{
bd518c3
+  fork ();
bd518c3
+  sleep (60);
bd518c3
+  return 0;
bd518c3
+}
25ff8a1
Index: gdb-6.8cvs20080219/gdb/testsuite/gdb.base/follow-child.exp
25ff8a1
===================================================================
25ff8a1
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
25ff8a1
+++ gdb-6.8cvs20080219/gdb/testsuite/gdb.base/follow-child.exp	2008-02-22 08:14:17.000000000 +0100
bd518c3
@@ -0,0 +1,55 @@
bd518c3
+# Copyright 2007 Free Software Foundation, Inc.
bd518c3
+
bd518c3
+# This program is free software; you can redistribute it and/or modify
bd518c3
+# it under the terms of the GNU General Public License as published by
bd518c3
+# the Free Software Foundation; either version 2 of the License, or
bd518c3
+# (at your option) any later version.
bd518c3
+# 
bd518c3
+# This program is distributed in the hope that it will be useful,
bd518c3
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
bd518c3
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
bd518c3
+# GNU General Public License for more details.
bd518c3
+# 
bd518c3
+# You should have received a copy of the GNU General Public License
bd518c3
+# along with this program; if not, write to the Free Software
25ff8a1
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
bd518c3
+
bd518c3
+if $tracelevel then {
bd518c3
+    strace $tracelevel
bd518c3
+}
bd518c3
+
bd518c3
+set prms_id 0
bd518c3
+set bug_id 0
bd518c3
+
bd518c3
+set testfile follow-child
bd518c3
+set srcfile ${testfile}.c
bd518c3
+set binfile ${objdir}/${subdir}/${testfile}
bd518c3
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
bd518c3
+    untested "Couldn't compile test program"
bd518c3
+    return -1
bd518c3
+}
bd518c3
+
bd518c3
+# Get things started.
bd518c3
+
bd518c3
+gdb_exit
bd518c3
+gdb_start
bd518c3
+gdb_reinitialize_dir $srcdir/$subdir
bd518c3
+gdb_load ${binfile}
bd518c3
+
bd518c3
+# For C programs, "start" should stop in main().
bd518c3
+
bd518c3
+gdb_test "set follow-fork-mode child" ""
bd518c3
+set test "started"
bd518c3
+# GDB_RUN_CMD already checks for `Starting program:'.
bd518c3
+gdb_run_cmd
bd518c3
+sleep 5
bd518c3
+send_gdb "\003"
bd518c3
+set test "break"
bd518c3
+gdb_test_multiple "" $test {
bd518c3
+    -re "Program received signal SIGINT.*$gdb_prompt $" {
bd518c3
+	pass $test
bd518c3
+    }
bd518c3
+    -re "\\\[New process \[0-9\]+\\\]" {
bd518c3
+	fail $test
bd518c3
+    }
bd518c3
+}
25ff8a1
Index: gdb-6.8cvs20080219/gdb/Makefile.in
25ff8a1
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/Makefile.in	2008-02-22 08:10:38.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/Makefile.in	2008-02-22 08:13:31.000000000 +0100
25ff8a1
@@ -2377,7 +2377,7 @@ linux-nat.o: linux-nat.c $(defs_h) $(inf
25ff8a1
 	$(gdb_wait_h) $(gdb_assert_h) $(linux_nat_h) $(gdbthread_h) \
25ff8a1
 	$(gdbcmd_h) $(regcache_h) $(regset_h) $(inf_ptrace_h) $(auxv_h) \
25ff8a1
 	$(elf_bfd_h) $(gregset_h) $(gdbcore_h) $(gdbthread_h) $(gdb_stat_h) \
25ff8a1
-	$(linux_fork_h)
25ff8a1
+	$(linux_fork_h) $(observer_h)
25ff8a1
 linux-thread-db.o: linux-thread-db.c $(defs_h) $(gdb_assert_h) \
25ff8a1
 	$(gdb_proc_service_h) $(gdb_thread_db_h) $(bfd_h) $(exceptions_h) \
25ff8a1
 	$(gdbthread_h) $(inferior_h) $(symfile_h) $(objfiles_h) $(target_h) \