diff options
author | Tristan Gingold <gingold@adacore.com> | 2011-09-22 10:22:28 +0000 |
---|---|---|
committer | Tristan Gingold <gingold@adacore.com> | 2011-09-22 10:22:28 +0000 |
commit | e69860f1b6d6e38cc5de31a9dc1138015182c7d5 (patch) | |
tree | 0440500af65431119a8f792b2967d84b63e5064f /gdb/darwin-nat.c | |
parent | 7cf3bbff3627f9650721a2f8c07581e75208d30d (diff) | |
download | gdb-e69860f1b6d6e38cc5de31a9dc1138015182c7d5.zip gdb-e69860f1b6d6e38cc5de31a9dc1138015182c7d5.tar.gz gdb-e69860f1b6d6e38cc5de31a9dc1138015182c7d5.tar.bz2 |
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.
Diffstat (limited to 'gdb/darwin-nat.c')
-rw-r--r-- | gdb/darwin-nat.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 06a1558..7c0ff5b 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -53,6 +53,7 @@ #include <sys/proc.h> #include <libproc.h> #include <sys/syscall.h> +#include <spawn.h> #include <mach/mach_error.h> #include <mach/mach_vm.h> @@ -1507,12 +1508,47 @@ darwin_ptrace_him (int pid) } 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)) |