*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / linux-fork.c
index f024490d1f96dd701f266d1c1020cb7f07407d34..bb4468268c29dba615d1aa2d5c9aa7ad974c1d36 100644 (file)
 #include "regcache.h"
 #include "gdbcmd.h"
 #include "infcall.h"
+#include "gdb_assert.h"
 #include "gdb_string.h"
 #include "linux-fork.h"
+#include "linux-nat.h"
 
 #include <sys/ptrace.h>
 #include <sys/wait.h>
@@ -83,7 +85,7 @@ add_fork (pid_t pid)
     }
 
   fp = XZALLOC (struct fork_info);
-  fp->ptid = pid_to_ptid (pid);
+  fp->ptid = ptid_build (pid, pid, 0);
   fp->num = ++highest_fork_num;
   fp->next = fork_list;
   fork_list = fp;
@@ -238,9 +240,21 @@ fork_load_infrun_state (struct fork_info *fp)
   extern void nullify_last_target_wait_ptid ();
   int i;
 
+  inferior_ptid = fp->ptid;
+
+  linux_nat_switch_fork (inferior_ptid);
+
   if (fp->savedregs && fp->clobber_regs)
     regcache_cpy (current_regcache, fp->savedregs);
 
+  registers_changed ();
+  reinit_frame_cache ();
+
+  /* We must select a new frame before making any inferior calls to
+     avoid warnings.  */
+  select_frame (get_current_frame ());
+
+  stop_pc = read_pc ();
   nullify_last_target_wait_ptid ();
 
   /* Now restore the file positions of open file descriptors.  */
@@ -358,12 +372,19 @@ linux_fork_mourn_inferior (void)
      We need to delete that one from the fork_list, and switch
      to the next available fork.  */
   delete_fork (inferior_ptid);
-  if (fork_list)       /* Paranoia, shouldn't happen.  */
-    {
-      inferior_ptid = fork_list[0].ptid;
-      printf_filtered (_("[Switching to %s]\n"), 
-                      target_pid_to_str (inferior_ptid));
-    }
+
+  /* There should still be a fork - if there's only one left,
+     delete_fork won't remove it, because we haven't updated
+     inferior_ptid yet.  */
+  gdb_assert (fork_list);
+
+  fork_load_infrun_state (fork_list);
+  printf_filtered (_("[Switching to %s]\n"),
+                  target_pid_to_str (inferior_ptid));
+
+  /* If there's only one fork, switch back to non-fork mode.  */
+  if (fork_list->next == NULL)
+    delete_fork (inferior_ptid);
 }
 
 /* Fork list <-> user interface.  */
@@ -559,17 +580,10 @@ linux_fork_context (struct fork_info *newfp, int from_tty)
     error (_("No such fork/process"));
 
   if (!oldfp)
-    {
-      oldfp = add_fork (ptid_get_pid (inferior_ptid));
-    }
+    oldfp = add_fork (ptid_get_pid (inferior_ptid));
 
   fork_save_infrun_state (oldfp, 1);
-  inferior_ptid = newfp->ptid;
   fork_load_infrun_state (newfp);
-  registers_changed ();
-  reinit_frame_cache ();
-  stop_pc = read_pc ();
-  select_frame (get_current_frame ());
 
   printf_filtered (_("Switching to %s\n"), 
                   target_pid_to_str (inferior_ptid));
This page took 0.025964 seconds and 4 git commands to generate.