Skip to content

Commit

Permalink
Addressed review comments from @derekparker
Browse files Browse the repository at this point in the history
Added .clang-format
  • Loading branch information
oxisto committed Dec 14, 2020
1 parent d4508a6 commit 484b495
Show file tree
Hide file tree
Showing 23 changed files with 179 additions and 154 deletions.
11 changes: 11 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
BasedOnStyle: LLVM
UseTab: Always
IndentWidth: 4
TabWidth: 4
AllowShortIfStatementsOnASingleLine: true
AlwaysBreakAfterReturnType: All
IndentCaseLabels: true
ColumnLimit: 0
AccessModifierOffset: -4
NamespaceIndentation: All
DerivePointerAlignment: true
2 changes: 1 addition & 1 deletion Documentation/usage/dlv.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Pass flags to the program you are debugging using `--`, for example:
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_attach.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dlv attach pid [executable]
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ are:
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dlv connect addr
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_core.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dlv core <executable> <core>
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_dap.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dlv dap
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dlv debug [package]
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dlv exec <path/to/binary>
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_log.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ and dap modes.
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_redirect.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ File redirects can also be changed using the 'restart' command.
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_replay.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dlv replay [trace directory]
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dlv run
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dlv test [package]
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dlv trace [package] regexp
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
2 changes: 1 addition & 1 deletion Documentation/usage/dlv_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dlv version
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler.
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--disable-aslr Disables address space randomization. This option is forced to true on darwin/arm64
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
Expand Down
1 change: 0 additions & 1 deletion _scripts/testsign
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash
scripts_folder=$(dirname $0)
CERT=-
codesign -v -v $1
codesign -v --force -s $CERT --entitlements ${scripts_folder}/entitlements.plist $1
exec "$@"
3 changes: 2 additions & 1 deletion cmd/dlv/cmds/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func New(docCall bool) *cobra.Command {
// Config setup and load.
conf = config.LoadConfig()
buildFlagsDefault := ""

if runtime.GOOS == "windows" {
ver, _ := goversion.Installed()
if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}) {
Expand Down Expand Up @@ -133,7 +134,7 @@ func New(docCall bool) *cobra.Command {
rootCommand.PersistentFlags().StringVar(&backend, "backend", "default", `Backend selection (see 'dlv help backend').`)
rootCommand.PersistentFlags().StringArrayVarP(&redirects, "redirect", "r", []string{}, "Specifies redirect rules for target process (see 'dlv help redirect')")
rootCommand.PersistentFlags().BoolVar(&allowNonTerminalInteractive, "allow-non-terminal-interactive", false, "Allows interactive sessions of Delve that don't have a terminal as stdin, stdout and stderr")
rootCommand.PersistentFlags().BoolVar(&disableASLR, "disable-aslr", false, "Disables address space randomization")
rootCommand.PersistentFlags().BoolVar(&disableASLR, "disable-aslr", false, "Disables address space randomization. This option is forced to true on darwin/arm64")

// 'attach' subcommand.
attachCommand := &cobra.Command{
Expand Down
94 changes: 46 additions & 48 deletions pkg/proc/native/exec_darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,74 @@
#include "exec_darwin.h"
#include "stdio.h"

extern char** environ;
extern char **environ;

#ifndef POSIX_SPAWN_DISABLE_ASLR
#define POSIX_SPAWN_DISABLE_ASLR 0x0100
#endif

int
spawn(char *argv0, char **argv, int size,
char *wd,
task_t *task,
mach_port_t *port_set,
mach_port_t *exception_port,
mach_port_t *notification_port)
{
char *wd,
task_t *task,
mach_port_t *port_set,
mach_port_t *exception_port,
mach_port_t *notification_port,
int disable_aslr) {
kern_return_t kret = 0;

posix_spawn_file_actions_t file_actions;
posix_spawnattr_t attributes;
posix_spawn_file_actions_t file_actions;
posix_spawnattr_t attributes;

// TODO: check error
posix_spawnattr_init(&attributes);

sigset_t no_signals;
sigset_t all_signals;
sigemptyset(&no_signals);
sigfillset(&all_signals);

posix_spawnattr_setsigmask(&attributes, &no_signals);
posix_spawnattr_setsigdefault(&attributes, &all_signals);

// Change working directory if wd is not empty.
if (wd && wd[0]) {
errno = 0;
int ret = chdir(wd);

if (ret != 0 && errno != 0) {
char *error_msg;
asprintf(&error_msg, "%s '%s'", "chdir", wd);
perror(error_msg);
exit(1);
}
}

short flags = POSIX_SPAWN_START_SUSPENDED | POSIX_SPAWN_SETSIGDEF |
POSIX_SPAWN_SETSIGMASK;

#if defined(__arm64__)
// Force ASLR disable on arm64. This might not be needed if a non-PIE
// executable is built, but this in turn seems to be imposssible on darwin arm64
flags |= POSIX_SPAWN_DISABLE_ASLR;
#endif
posix_spawnattr_init(&attributes);

sigset_t no_signals;
sigset_t all_signals;
sigemptyset(&no_signals);
sigfillset(&all_signals);

posix_spawnattr_setsigmask(&attributes, &no_signals);
posix_spawnattr_setsigdefault(&attributes, &all_signals);

// Change working directory if wd is not empty.
if (wd && wd[0]) {
errno = 0;
int ret = chdir(wd);

if (ret != 0 && errno != 0) {
char *error_msg;
asprintf(&error_msg, "%s '%s'", "chdir", wd);
perror(error_msg);
exit(1);
}
}

posix_spawnattr_setflags(&attributes, flags);
short flags = POSIX_SPAWN_START_SUSPENDED | POSIX_SPAWN_SETSIGDEF |
POSIX_SPAWN_SETSIGMASK;

if (disable_aslr) {
flags |= POSIX_SPAWN_DISABLE_ASLR;
}

pid_t pid;
posix_spawnattr_setflags(&attributes, flags);

pid_t pid;

posix_spawnp(&pid, argv0, NULL, &attributes,
argv,
environ);
argv,
environ);

kret = acquire_mach_task(pid, task, port_set, exception_port, notification_port);
if (kret != KERN_SUCCESS) {
return -1;
}

int err = ptrace(PT_ATTACHEXC, pid, 0, 0);
if (err != 0) {
perror("ptrace");
return -1;
}
if (err != 0) {
perror("ptrace");
return -1;
}

posix_spawnattr_destroy(&attributes);

Expand Down
2 changes: 1 addition & 1 deletion pkg/proc/native/exec_darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#include <signal.h>

int
spawn(char *, char **, int, char *, task_t*, mach_port_t*, mach_port_t*, mach_port_t*);
spawn(char *, char **, int, char *, task_t*, mach_port_t*, mach_port_t*, mach_port_t*, int);
Loading

0 comments on commit 484b495

Please sign in to comment.