gdb/
[deliverable/binutils-gdb.git] / gdb / fork-child.c
index 5dbf1f750fbe5d167edcc162699d901030608a19..b47019dcc00cfcbb2fb5cd2594e2faaadeef4dd1 100644 (file)
@@ -1,8 +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, 2009, 2010, 2011
-   Free Software Foundation, Inc.
+   Copyright (C) 1990-1996, 1998-2001, 2004-2012 Free Software
+   Foundation, Inc.
 
    Contributed by Cygnus Support.
 
@@ -115,6 +114,7 @@ escape_bang_in_quoted_argument (const char *shell_file)
    pid.  EXEC_FILE is the file to run.  ALLARGS is a string containing
    the arguments to the program.  ENV is the environment vector to
    pass.  SHELL_FILE is the shell file, or NULL if we should pick
+   one.  EXEC_FUN is the exec(2) function to use, or NULL for the default
    one.  */
 
 /* This function is NOT reentrant.  Some of the variables have been
@@ -123,7 +123,9 @@ escape_bang_in_quoted_argument (const char *shell_file)
 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)
+              void (*pre_trace_fun) (void), char *shell_file_arg,
+               void (*exec_fun)(const char *file, char * const *argv,
+                                char * const *env))
 {
   int pid;
   static char default_shell_file[] = SHELL_FILE;
@@ -270,9 +272,6 @@ fork_inferior (char *exec_file_arg, char *allargs, char **env,
       argv[3] = (char *) 0;
     }
 
-  /* On some systems an exec will fail if the executable is open.  */
-  close_exec_file ();
-
   /* Retain a copy of our environment variables, since the child will
      replace the value of environ and if we're vforked, we have to
      restore it.  */
@@ -359,7 +358,10 @@ fork_inferior (char *exec_file_arg, char *allargs, char **env,
          path to find $SHELL.  Rich Pixley says so, and I agree.  */
       environ = env;
 
-      execvp (argv[0], argv);
+      if (exec_fun != NULL)
+        (*exec_fun) (argv[0], argv, env);
+      else
+        execvp (argv[0], argv);
 
       /* If we get here, it's an error.  */
       save_errno = errno;
@@ -429,7 +431,7 @@ startup_inferior (int ntraps)
 
   while (1)
     {
-      enum target_signal resume_signal = TARGET_SIGNAL_0;
+      enum gdb_signal resume_signal = GDB_SIGNAL_0;
       ptid_t event_ptid;
 
       struct target_waitstatus ws;
@@ -456,8 +458,8 @@ startup_inferior (int ntraps)
            target_terminal_ours ();
            target_mourn_inferior ();
            error (_("During startup program terminated with signal %s, %s."),
-                  target_signal_to_name (ws.value.sig),
-                  target_signal_to_string (ws.value.sig));
+                  gdb_signal_to_name (ws.value.sig),
+                  gdb_signal_to_string (ws.value.sig));
            return;
 
          case TARGET_WAITKIND_EXITED:
@@ -473,7 +475,7 @@ startup_inferior (int ntraps)
          case TARGET_WAITKIND_EXECD:
            /* Handle EXEC signals as if they were SIGTRAP signals.  */
            xfree (ws.value.execd_pathname);
-           resume_signal = TARGET_SIGNAL_TRAP;
+           resume_signal = GDB_SIGNAL_TRAP;
            switch_to_thread (event_ptid);
            break;
 
@@ -483,7 +485,7 @@ startup_inferior (int ntraps)
            break;
        }
 
-      if (resume_signal != TARGET_SIGNAL_TRAP)
+      if (resume_signal != GDB_SIGNAL_TRAP)
        {
          /* Let shell child handle its own signals in its own way.  */
          target_resume (resume_ptid, 0, resume_signal);
@@ -512,7 +514,7 @@ startup_inferior (int ntraps)
            break;
 
          /* Just make it go on.  */
-         target_resume (resume_ptid, 0, TARGET_SIGNAL_0);
+         target_resume (resume_ptid, 0, GDB_SIGNAL_0);
        }
     }
 
This page took 0.044811 seconds and 4 git commands to generate.