* fork-child.c (fork_inferior): Add exec_fun parameter.
Call exec_fun or execvp.
* inferior.h: Adjust prototype.
* gnu-nat.c (gnu_create_inferior): Adjust fork_inferior call.
* inf-ttrace.c (inf_ttrace_create_inferior): Ditto.
* inf-ptrace.c (inf_ptrace_create_inferior): Ditto.
* procfs.c (procfs_create_inferior): Ditto.
* darwin-nat.c (darwin_execvp): New function.
(darwin_create_inferior): Use it.
+2011-09-22 Tristan Gingold <gingold@adacore.com>
+
+ * fork-child.c (fork_inferior): Add exec_fun parameter.
+ Call exec_fun or execvp.
+ * inferior.h: Adjust prototype.
+ * gnu-nat.c (gnu_create_inferior): Adjust fork_inferior call.
+ * inf-ttrace.c (inf_ttrace_create_inferior): Ditto.
+ * inf-ptrace.c (inf_ptrace_create_inferior): Ditto.
+ * procfs.c (procfs_create_inferior): Ditto.
+ * darwin-nat.c (darwin_execvp): New function.
+ (darwin_create_inferior): Use it.
+
2011-09-22 Yao Qi <yao@codesourcery.com>
* infrun.c (context_switch): Print debug message when switching to
#include <sys/proc.h>
#include <libproc.h>
#include <sys/syscall.h>
+#include <spawn.h>
#include <mach/mach_error.h>
#include <mach/mach_vm.h>
startup_inferior (START_INFERIOR_TRAPS_EXPECTED);
}
+static void
+darwin_execvp (const char *file, char * const argv[], char * const env[])
+{
+ posix_spawnattr_t attr;
+ short ps_flags = 0;
+ int retval;
+
+ retval = posix_spawnattr_init (&attr);
+ if (retval != 0)
+ {
+ fprintf_unfiltered
+ (gdb_stderr, "Cannot initialize attribute for posix_spawn\n");
+ return;
+ }
+
+ /* Do like execve: replace the image. */
+ ps_flags = POSIX_SPAWN_SETEXEC;
+
+ /* Disable ASLR. The constant doesn't look to be available outside the
+ kernel include files. */
+#ifndef _POSIX_SPAWN_DISABLE_ASLR
+#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
+#endif
+ ps_flags |= _POSIX_SPAWN_DISABLE_ASLR;
+ retval = posix_spawnattr_setflags (&attr, ps_flags);
+ if (retval != 0)
+ {
+ fprintf_unfiltered
+ (gdb_stderr, "Cannot set posix_spawn flags\n");
+ return;
+ }
+
+ posix_spawnp (NULL, argv[0], NULL, &attr, argv, env);
+}
+
static void
darwin_create_inferior (struct target_ops *ops, char *exec_file,
char *allargs, char **env, int from_tty)
{
/* Do the hard work. */
fork_inferior (exec_file, allargs, env, darwin_ptrace_me, darwin_ptrace_him,
- darwin_pre_ptrace, NULL);
+ darwin_pre_ptrace, NULL, darwin_execvp);
/* Return now in case of error. */
if (ptid_equal (inferior_ptid, null_ptid))
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;
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;
inf_debug (inf, "creating inferior");
- pid = fork_inferior (exec_file, allargs, env, trace_me, NULL, NULL, NULL);
+ pid = fork_inferior (exec_file, allargs, env, trace_me,
+ NULL, NULL, NULL, NULL);
/* Attach to the now stopped child, which is actually a shell... */
inf_debug (inf, "attaching to child: %d", pid);
}
pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL,
- NULL, NULL);
+ NULL, NULL, NULL);
if (! ops_already_pushed)
discard_cleanups (back_to);
gdb_assert (inf_ttrace_vfork_ppid == -1);
pid = fork_inferior (exec_file, allargs, env, inf_ttrace_me, NULL,
- inf_ttrace_prepare, NULL);
+ inf_ttrace_prepare, NULL, NULL);
inf_ttrace_him (ops, pid);
}
extern int fork_inferior (char *, char *, char **,
void (*)(void),
- void (*)(int), void (*)(void), char *);
+ void (*)(int), void (*)(void), char *,
+ void (*)(const char *,
+ char * const *, char * const *));
extern void startup_inferior (int);
}
pid = fork_inferior (exec_file, allargs, env, procfs_set_exec_trap,
- NULL, NULL, shell_file);
+ NULL, NULL, shell_file, NULL);
procfs_init_inferior (ops, pid);
}