2010-06-01 Sergio Durigan Junior <sergiodj@redhat.com>
[deliverable/binutils-gdb.git] / gdb / fork-child.c
index a1726bd543958b19b949bf10a4d319a0517594f4..2b085ffe6aef8b9ed275c54ad1044f0b21b00d72 100644 (file)
@@ -1,7 +1,8 @@
 /* Fork a Unix child process, and set up to debug it, for GDB.
 
    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
-   2001, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+   2001, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.
 
@@ -22,8 +23,8 @@
 
 #include "defs.h"
 #include "gdb_string.h"
-#include "frame.h"             /* required by inferior.h */
 #include "inferior.h"
+#include "terminal.h"
 #include "target.h"
 #include "gdb_wait.h"
 #include "gdb_vfork.h"
@@ -138,6 +139,7 @@ fork_inferior (char *exec_file_arg, char *allargs, char **env,
   int shell = 0;
   static char **argv;
   const char *inferior_io_terminal = get_inferior_io_terminal ();
+  struct inferior *inf;
 
   /* If no exec file handed to us, get it from the exec-file command
      -- with a good, common error message if none is specified.  */
@@ -176,6 +178,7 @@ fork_inferior (char *exec_file_arg, char *allargs, char **env,
         assuming that every other character is a separate
         argument.  */
       int argc = (strlen (allargs) + 1) / 2 + 2;
+
       argv = (char **) xmalloc (argc * sizeof (*argv));
       argv[0] = exec_file;
       breakup_args (allargs, &argv[1]);
@@ -392,13 +395,18 @@ fork_inferior (char *exec_file_arg, char *allargs, char **env,
   /* Restore our environment in case a vforked child clob'd it.  */
   environ = save_our_env;
 
-  init_thread_list ();
+  if (!have_inferiors ())
+    init_thread_list ();
+
+  inf = current_inferior ();
 
-  add_inferior (pid);
+  inferior_appeared (inf, pid);
 
   /* Needed for wait_for_inferior stuff below.  */
   inferior_ptid = pid_to_ptid (pid);
 
+  new_tty_postfork ();
+
   /* We have something that executes now.  We'll be running through
      the shell at this point, but the pid shouldn't change.  Targets
      supporting MT should fill this task's ptid with more data as soon
@@ -424,6 +432,12 @@ startup_inferior (int ntraps)
 {
   int pending_execs = ntraps;
   int terminal_initted = 0;
+  ptid_t resume_ptid;
+
+  if (target_supports_multi_process ())
+    resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
+  else
+    resume_ptid = minus_one_ptid;
 
   /* The process was started by the fork that created it, but it will
      have stopped one instruction after execing the shell.  Here we
@@ -435,12 +449,11 @@ startup_inferior (int ntraps)
   while (1)
     {
       int resume_signal = TARGET_SIGNAL_0;
-      ptid_t resume_ptid;
       ptid_t event_ptid;
 
       struct target_waitstatus ws;
       memset (&ws, 0, sizeof (ws));
-      event_ptid = target_wait (pid_to_ptid (-1), &ws);
+      event_ptid = target_wait (resume_ptid, &ws, 0);
 
       if (ws.kind == TARGET_WAITKIND_IGNORE)
        /* The inferior didn't really stop, keep waiting.  */
@@ -489,12 +502,6 @@ startup_inferior (int ntraps)
            break;
        }
 
-      /* In all-stop mode, resume all threads.  */
-      if (!non_stop)
-       resume_ptid = pid_to_ptid (-1);
-      else
-       resume_ptid = event_ptid;
-
       if (resume_signal != TARGET_SIGNAL_TRAP)
        {
          /* Let shell child handle its own signals in its own way.  */
@@ -529,9 +536,7 @@ startup_inferior (int ntraps)
     }
 
   /* Mark all threads non-executing.  */
-  set_executing (pid_to_ptid (-1), 0);
-
-  stop_pc = read_pc ();
+  set_executing (resume_ptid, 0);
 }
 
 /* Implement the "unset exec-wrapper" command.  */
This page took 0.025665 seconds and 4 git commands to generate.