Blob Blame History Raw
[base]

2007-10-13  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* linux-nat.c (iterate_over_lwps): Fixed missing LWP initialization for
	current INFERIOR_PTID.

2007-10-13  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.base/follow-child.exp, gdb.base/follow-child.c: New files.

2007-10-16  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Port to GDB-6.7.

Index: gdb-6.7/gdb/doc/observer.texi
===================================================================
--- gdb-6.7.orig/gdb/doc/observer.texi	2007-10-13 05:09:50.000000000 +0200
+++ gdb-6.7/gdb/doc/observer.texi	2007-10-14 23:24:52.000000000 +0200
@@ -119,6 +119,10 @@ when @value{GDBN} calls this observer, t
 haven't been loaded yet.
 @end deftypefun
 
+@deftypefun void mourn_inferior (struct target_ops *@var{target})
+@value{GDBN} has just detached from an inferior.
+@end deftypefun
+
 @deftypefun void solib_unloaded (struct so_list *@var{solib})
 The shared library specified by @var{solib} has been unloaded.
 @end deftypefun
Index: gdb-6.7/gdb/linux-nat.c
===================================================================
--- gdb-6.7.orig/gdb/linux-nat.c	2007-10-13 05:09:50.000000000 +0200
+++ gdb-6.7/gdb/linux-nat.c	2007-10-14 23:24:52.000000000 +0200
@@ -742,11 +742,26 @@ iterate_over_lwps (int (*callback) (stru
 {
   struct lwp_info *lp, *lpnext;
 
-  for (lp = lwp_list; lp; lp = lpnext)
+  if (lwp_list != NULL)
     {
-      lpnext = lp->next;
+      for (lp = lwp_list; lp; lp = lpnext)
+        {
+          lpnext = lp->next;
+          if ((*callback) (lp, data))
+	    return lp;
+        }
+    }
+  else
+    {
+      /* We are calling iterate_over_lwps for a non-threaded program.
+         Initialize the lwp list to the inferior's ptid.  */
+      gdb_assert (!is_lwp (inferior_ptid));
+
+      inferior_ptid = BUILD_LWP (GET_PID (inferior_ptid),
+				 GET_PID (inferior_ptid));
+      lp = add_lwp (inferior_ptid);
       if ((*callback) (lp, data))
-	return lp;
+        return lp;
     }
 
   return NULL;
@@ -3272,6 +3284,18 @@ linux_nat_add_target (struct target_ops 
   thread_db_init (t);
 }
 
+/* Observer function for a mourn inferior event.  This is needed
+   because if iterate_over_lwps is called for a non-threaded program
+   to handle watchpoints, the lwp list gets initialized but there is
+   no corresponding clean-up when the inferior is detached.  In
+   a threaded program, the observer is simply redundant as the
+   same clean-up gets done in linux_nat_mourn_inferior.  */
+static void
+linux_nat_mourn_inferior_observer (struct target_ops *objfile)
+{
+  init_lwp_list ();
+}
+
 void
 _initialize_linux_nat (void)
 {
@@ -3286,6 +3310,8 @@ Specify any of the following keywords fo
   status   -- list a different bunch of random process info.\n\
   all      -- list all available /proc info."));
 
+  observer_attach_mourn_inferior (linux_nat_mourn_inferior_observer);
+
   /* Save the original signal mask.  */
   sigprocmask (SIG_SETMASK, NULL, &normal_mask);
 
Index: gdb-6.7/gdb/target.c
===================================================================
--- gdb-6.7.orig/gdb/target.c	2007-08-23 20:08:45.000000000 +0200
+++ gdb-6.7/gdb/target.c	2007-10-14 23:25:13.000000000 +0200
@@ -39,6 +39,7 @@
 #include "gdbcore.h"
 #include "exceptions.h"
 #include "target-descriptions.h"
+#include "observer.h"
 
 static void target_info (char *, int);
 
@@ -275,6 +276,13 @@ target_load (char *arg, int from_tty)
   (*current_target.to_load) (arg, from_tty);
 }
 
+void
+target_mourn_inferior (void)
+{
+  (*current_target.to_mourn_inferior) ();
+  observer_notify_mourn_inferior (&current_target);
+}
+
 static int
 nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
 	  struct target_ops *t)
Index: gdb-6.7/gdb/target.h
===================================================================
--- gdb-6.7.orig/gdb/target.h	2007-08-23 20:08:46.000000000 +0200
+++ gdb-6.7/gdb/target.h	2007-10-14 23:24:52.000000000 +0200
@@ -864,8 +864,7 @@ int target_follow_fork (int follow_child
 
 /* The inferior process has died.  Do what is right.  */
 
-#define	target_mourn_inferior()	\
-     (*current_target.to_mourn_inferior) ()
+extern void target_mourn_inferior (void);
 
 /* Does target have enough data to do a run or attach command? */
 
diff -u -u -X /home/jkratoch/.diffi.list -rup gdb-6.6-orig/gdb/testsuite/gdb.base/follow-child.c gdb-6.6/gdb/testsuite/gdb.base/follow-child.c
--- gdb-6.6-orig/gdb/testsuite/gdb.base/follow-child.c	2007-10-13 19:24:58.000000000 +0200
+++ gdb-6.6/gdb/testsuite/gdb.base/follow-child.c	2007-10-13 19:11:08.000000000 +0200
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2007 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+ 
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+   Please email any bugs, comments, and/or additions to this file to:
+   bug-gdb@prep.ai.mit.edu  */
+
+#include <unistd.h>
+
+int main()
+{
+  fork ();
+  sleep (60);
+  return 0;
+}
diff -u -u -X /home/jkratoch/.diffi.list -rup gdb-6.6-orig/gdb/testsuite/gdb.base/follow-child.exp gdb-6.6/gdb/testsuite/gdb.base/follow-child.exp
--- gdb-6.6-orig/gdb/testsuite/gdb.base/follow-child.exp	2007-10-13 19:24:58.000000000 +0200
+++ gdb-6.6/gdb/testsuite/gdb.base/follow-child.exp	2007-10-13 19:24:21.000000000 +0200
@@ -0,0 +1,55 @@
+# Copyright 2007 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+set testfile follow-child
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+    untested "Couldn't compile test program"
+    return -1
+}
+
+# Get things started.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+# For C programs, "start" should stop in main().
+
+gdb_test "set follow-fork-mode child" ""
+set test "started"
+# GDB_RUN_CMD already checks for `Starting program:'.
+gdb_run_cmd
+sleep 5
+send_gdb "\003"
+set test "break"
+gdb_test_multiple "" $test {
+    -re "Program received signal SIGINT.*$gdb_prompt $" {
+	pass $test
+    }
+    -re "\\\[New process \[0-9\]+\\\]" {
+	fail $test
+    }
+}