/* 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.
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
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;
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. */
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;
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;
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:
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;
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);
break;
/* Just make it go on. */
- target_resume (resume_ptid, 0, TARGET_SIGNAL_0);
+ target_resume (resume_ptid, 0, GDB_SIGNAL_0);
}
}