diff options
author | Tristan Gingold <gingold@adacore.com> | 2011-09-22 10:22:26 +0000 |
---|---|---|
committer | Tristan Gingold <gingold@adacore.com> | 2011-09-22 10:22:26 +0000 |
commit | 04b16148d032c27c7c01ba41ee21a125b008e806 (patch) | |
tree | 3dffda0bed77e42ed7fdc959efd3db62bbffb87d /gdb/darwin-nat.c | |
parent | 60d38c725cfd9c9bc8a557d8a1aa7bf4afabcab0 (diff) | |
download | gdb-04b16148d032c27c7c01ba41ee21a125b008e806.tar.gz |
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 06a15585648..7c0ff5b8757 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)) |