Make "checkpoint" not rely on inferior_ptid
[deliverable/binutils-gdb.git] / gdb / linux-fork.c
index b1b390c5c6e0dc52e9b516bf22f59e219667ea46..a748deaa3a2084921ac60148a81e2aed80d3e372 100644 (file)
@@ -76,29 +76,30 @@ find_last_fork (void)
   return last;
 }
 
-/* Add a fork to the internal fork list.  */
+/* Allocate a new fork.  */
 
-struct fork_info *
-add_fork (pid_t pid)
+static struct fork_info *
+new_fork (pid_t pid)
 {
   struct fork_info *fp;
 
-  if (fork_list == NULL && pid != inferior_ptid.pid ())
-    {
-      /* Special case -- if this is the first fork in the list
-        (the list is hitherto empty), and if this new fork is
-        NOT the current inferior_ptid, then add inferior_ptid
-        first, as a special zeroeth fork id.  */
-      highest_fork_num = -1;
-      add_fork (inferior_ptid.pid ()); /* safe recursion */
-    }
-
   fp = XCNEW (struct fork_info);
   fp->ptid = ptid_t (pid, pid, 0);
-  fp->num = ++highest_fork_num;
+  return fp;
+}
+
+/* Add a new fork to the internal fork list.  */
+
+void
+add_fork (pid_t pid)
+{
+  struct fork_info *fp = new_fork (pid);
 
   if (fork_list == NULL)
-    fork_list = fp;
+    {
+      fork_list = fp;
+      highest_fork_num = 0;
+    }
   else
     {
       struct fork_info *last = find_last_fork ();
@@ -106,7 +107,7 @@ add_fork (pid_t pid)
       last->next = fp;
     }
 
-  return fp;
+  fp->num = ++highest_fork_num;
 }
 
 static void
@@ -760,6 +761,17 @@ checkpoint_command (const char *args, int from_tty)
 
   if (!fp)
     error (_("Failed to find new fork"));
+
+  if (fork_list->next == NULL)
+    {
+      /* Special case -- if this is the first fork in the list (the
+        list was hitherto empty), then add inferior_ptid first, as a
+        special zeroeth fork id.  */
+      fork_info *first = new_fork (inferior_ptid.pid ());
+      first->next = fork_list;
+      fork_list = first;
+    }
+
   fork_save_infrun_state (fp, 1);
   fp->parent_ptid = last_target_ptid;
 }
This page took 0.037661 seconds and 4 git commands to generate.