* remote-sim.c (init_gdbsim_ops): Remove
[deliverable/binutils-gdb.git] / gdb / linux-fork.c
index bb4468268c29dba615d1aa2d5c9aa7ad974c1d36..fcc8a29e7ad999c6362fa9df46775e9b1b3f2f7c 100644 (file)
@@ -1,12 +1,12 @@
 /* GNU/Linux native-dependent code for debugging multiple forks.
 
-   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    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
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -15,9 +15,7 @@
    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., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 #include "inferior.h"
@@ -30,9 +28,9 @@
 #include "linux-nat.h"
 
 #include <sys/ptrace.h>
-#include <sys/wait.h>
+#include "gdb_wait.h"
 #include <sys/param.h>
-#include <dirent.h>
+#include "gdb_dirent.h"
 #include <ctype.h>
 
 struct fork_info *fork_list;
@@ -245,15 +243,11 @@ fork_load_infrun_state (struct fork_info *fp)
   linux_nat_switch_fork (inferior_ptid);
 
   if (fp->savedregs && fp->clobber_regs)
-    regcache_cpy (current_regcache, fp->savedregs);
+    regcache_cpy (get_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 ();
 
@@ -282,7 +276,7 @@ fork_save_infrun_state (struct fork_info *fp, int clobber_regs)
   if (fp->savedregs)
     regcache_xfree (fp->savedregs);
 
-  fp->savedregs = regcache_dup (current_regcache);
+  fp->savedregs = regcache_dup (get_current_regcache ());
   fp->clobber_regs = clobber_regs;
   fp->pc = read_pc ();
 
@@ -343,7 +337,9 @@ linux_fork_killall (void)
     {
       pid = PIDGET (fp->ptid);
       do {
-       ptrace (PT_KILL, pid, 0, 0);
+       /* Use SIGKILL instead of PTRACE_KILL because the former works even
+          if the thread is running, while the later doesn't.  */
+       kill (pid, SIGKILL);
        ret = waitpid (pid, &status, 0);
        /* We might get a SIGCHLD instead of an exit status.  This is
         aggravated by the first kill above - a child has just
@@ -448,9 +444,18 @@ info_forks_command (char *arg, int from_tty)
   struct fork_info *fp;
   int cur_line;
   ULONGEST pc;
+  int requested = -1;
+  struct fork_info *printed = NULL;
+
+  if (arg && *arg)
+    requested = (int) parse_and_eval_long (arg);
 
   for (fp = fork_list; fp; fp = fp->next)
     {
+      if (requested > 0 && fp->num != requested)
+       continue;
+
+      printed = fp;
       if (ptid_equal (fp->ptid, inferior_ptid))
        {
          printf_filtered ("* ");
@@ -465,7 +470,7 @@ info_forks_command (char *arg, int from_tty)
       if (fp->num == 0)
        printf_filtered (_(" (main process)"));
       printf_filtered (_(" at "));
-      deprecated_print_address_numeric (pc, 1, gdb_stdout);
+      fputs_filtered (paddress (pc), gdb_stdout);
 
       sal = find_pc_line (pc, 0);
       if (sal.symtab)
@@ -490,6 +495,13 @@ info_forks_command (char *arg, int from_tty)
 
       putchar_filtered ('\n');
     }
+  if (printed == NULL)
+    {
+      if (requested > 0)
+       printf_filtered (_("No fork number %d.\n"), requested);
+      else
+       printf_filtered (_("No forks.\n"));
+    }
 }
 
 /* Save/restore mode variable 'detach_fork':
@@ -526,6 +538,10 @@ checkpoint_command (char *args, int from_tty)
   /* Make this temp var static, 'cause it's used in the error context.  */
   static int temp_detach_fork;
 
+  /* Remove breakpoints, so that they are not inserted
+     in the forked process.  */
+  remove_breakpoints ();
+
   /* Make the inferior fork, record its (and gdb's) state.  */
 
   if (lookup_minimal_symbol ("fork", NULL, NULL) != NULL)
@@ -566,6 +582,7 @@ checkpoint_command (char *args, int from_tty)
   if (!fp)
     error (_("Failed to find new fork"));
   fork_save_infrun_state (fp, 1);
+  insert_breakpoints ();
 }
 
 static void
@@ -583,7 +600,9 @@ linux_fork_context (struct fork_info *newfp, int from_tty)
     oldfp = add_fork (ptid_get_pid (inferior_ptid));
 
   fork_save_infrun_state (oldfp, 1);
+  remove_breakpoints ();
   fork_load_infrun_state (newfp);
+  insert_breakpoints ();
 
   printf_filtered (_("Switching to %s\n"), 
                   target_pid_to_str (inferior_ptid));
@@ -670,17 +689,19 @@ Fork a duplicate process (experimental)."));
 restart <n>: restore program context from a checkpoint.\n\
 Argument 'n' is checkpoint ID, as displayed by 'info checkpoints'."));
 
-  /* Delete-checkpoint command: kill the process and remove it from
+  /* Delete checkpoint command: kill the process and remove it from
      fork list.  */
 
-  add_com ("delete-checkpoint", class_obscure, delete_fork_command, _("\
-Delete a fork/checkpoint (experimental)."));
+  add_cmd ("checkpoint", class_obscure, delete_fork_command, _("\
+Delete a fork/checkpoint (experimental)."),
+          &deletelist);
 
-  /* Detach-checkpoint command: release the process to run independantly, 
+  /* Detach checkpoint command: release the process to run independently, 
      and remove it from the fork list.  */
 
-  add_com ("detach-checkpoint", class_obscure, detach_fork_command, _("\
-Detach from a fork/checkpoint (experimental)."));
+  add_cmd ("checkpoint", class_obscure, detach_fork_command, _("\
+Detach from a fork/checkpoint (experimental)."),
+          &detachlist);
 
   /* Info checkpoints command: list all forks/checkpoints 
      currently under gdb's control.  */
@@ -691,8 +712,8 @@ Detach from a fork/checkpoint (experimental)."));
   /* Command aliases (let "fork" and "checkpoint" be used 
      interchangeably).  */
 
-  add_com_alias ("delete-fork", "delete-checkpoint", class_obscure, 1);
-  add_com_alias ("detach-fork", "detach-checkpoint", class_obscure, 1);
+  add_alias_cmd ("fork", "checkpoint", class_obscure, 1, &deletelist);
+  add_alias_cmd ("fork", "checkpoint", class_obscure, 1, &detachlist);
   add_info_alias ("forks", "checkpoints", 0);
 
   /* "fork <n>" (by analogy to "thread <n>").  */
This page took 0.025769 seconds and 4 git commands to generate.