* elf-m10300.c (mn10300_elf_relax_section): Allow for the
[deliverable/binutils-gdb.git] / gdb / fork-child.c
index 86c5e9116936e505fa0e68b361280e333f5f900b..9eadbc9969f8c9cca741b2f8d8dd419fe94bf92b 100644 (file)
@@ -1,7 +1,7 @@
 /* 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 Free Software Foundation, Inc.
+   2001, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.
 
@@ -22,8 +22,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"
@@ -118,7 +118,7 @@ escape_bang_in_quoted_argument (const char *shell_file)
 /* This function is NOT reentrant.  Some of the variables have been
    made static to ensure that they survive the vfork call.  */
 
-void
+int
 fork_inferior (char *exec_file_arg, char *allargs, char **env,
               void (*traceme_fun) (void), void (*init_trace_fun) (int),
               void (*pre_trace_fun) (void), char *shell_file_arg)
@@ -392,13 +392,16 @@ 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 ();
 
   add_inferior (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
@@ -408,11 +411,13 @@ fork_inferior (char *exec_file_arg, char *allargs, char **env,
   /* Now that we have a child process, make it our target, and
      initialize anything target-vector-specific that needs
      initializing.  */
-  (*init_trace_fun) (pid);
+  if (init_trace_fun)
+    (*init_trace_fun) (pid);
 
   /* We are now in the child process of interest, having exec'd the
      correct program, and are poised at the first instruction of the
      new program.  */
+  return pid;
 }
 
 /* Accept NTRAPS traps from the inferior.  */
@@ -422,6 +427,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
@@ -433,22 +444,18 @@ 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));
-      resume_ptid = target_wait (pid_to_ptid (-1), &ws);
-
-      /* Mark all threads non-executing.  */
-      set_executing (pid_to_ptid (-1), 0);
+      event_ptid = target_wait (resume_ptid, &ws, 0);
 
-      /* In all-stop mode, resume all threads.  */
-      if (!non_stop)
-       resume_ptid = pid_to_ptid (-1);
+      if (ws.kind == TARGET_WAITKIND_IGNORE)
+       /* The inferior didn't really stop, keep waiting.  */
+       continue;
 
       switch (ws.kind)
        {
-         case TARGET_WAITKIND_IGNORE:
          case TARGET_WAITKIND_SPURIOUS:
          case TARGET_WAITKIND_LOADED:
          case TARGET_WAITKIND_FORKED:
@@ -456,6 +463,7 @@ startup_inferior (int ntraps)
          case TARGET_WAITKIND_SYSCALL_ENTRY:
          case TARGET_WAITKIND_SYSCALL_RETURN:
            /* Ignore gracefully during startup of the inferior.  */
+           switch_to_thread (event_ptid);
            break;
 
          case TARGET_WAITKIND_SIGNALLED:
@@ -480,10 +488,12 @@ startup_inferior (int ntraps)
            /* Handle EXEC signals as if they were SIGTRAP signals.  */
            xfree (ws.value.execd_pathname);
            resume_signal = TARGET_SIGNAL_TRAP;
+           switch_to_thread (event_ptid);
            break;
 
          case TARGET_WAITKIND_STOPPED:
            resume_signal = ws.value.sig;
+           switch_to_thread (event_ptid);
            break;
        }
 
@@ -519,6 +529,9 @@ startup_inferior (int ntraps)
          target_resume (resume_ptid, 0, TARGET_SIGNAL_0);
        }
     }
+
+  /* Mark all threads non-executing.  */
+  set_executing (resume_ptid, 0);
 }
 
 /* Implement the "unset exec-wrapper" command.  */
@@ -530,6 +543,9 @@ unset_exec_wrapper_command (char *args, int from_tty)
   exec_wrapper = NULL;
 }
 
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+extern initialize_file_ftype _initialize_fork_child;
+
 void
 _initialize_fork_child (void)
 {
This page took 0.025726 seconds and 4 git commands to generate.