diff --git a/src/adbg/debugger/process.d b/src/adbg/debugger/process.d index 7ab3f8b3..5f525a3a 100644 --- a/src/adbg/debugger/process.d +++ b/src/adbg/debugger/process.d @@ -26,7 +26,7 @@ import adbg.utils.strings : adbg_util_argv_flatten; import adbg.debugger.exception : adbg_exception_t, adbg_exception_translate; import adbg.debugger.breakpoint : adbg_breakpoint_t; import adbg.object.machines; -import core.stdc.string : memset; +import core.stdc.string; version (Windows) { import adbg.include.windows.wow64; @@ -37,17 +37,14 @@ version (Windows) { } else version (Posix) { import adbg.include.posix.mann; import adbg.include.posix.ptrace; - import adbg.include.posix.unistd : clone, CLONE_PTRACE; + import adbg.include.posix.unistd; import adbg.include.posix.sys.wait; import adbg.utils.math : MIN; import core.stdc.ctype : isdigit; - import core.stdc.stdlib : atoi; - import core.stdc.string : strcpy; import core.sys.posix.sys.stat; import core.sys.posix.signal; import core.sys.posix.sys.uio; import core.sys.posix.fcntl : open, O_RDONLY; - import core.sys.posix.unistd : read, close, execve; import core.sys.posix.dirent; import core.sys.posix.libgen : basename; @@ -143,7 +140,7 @@ enum AdbgSpawnOpt { /// Default: Current directory of debugger. startDir = 3, // Pass environment table to tracee. - //environment = 4, + environment = 4, // Continue after spawning process. //continue_ = 5, // Tell debugger to use the shell instead of the OS interface. @@ -175,6 +172,7 @@ int adbg_debugger_spawn(adbg_process_t *tracee, const(char) *path, ...) { const(char) *args; const(char) **argv; const(char) *dir; + const(char) **envp; LOPT: switch (va_arg!int(list)) { case 0: break; @@ -187,6 +185,9 @@ LOPT: case AdbgSpawnOpt.startDir: dir = va_arg!(const(char)*)(list); goto LOPT; + case AdbgSpawnOpt.environment: + envp = va_arg!(const(char)**)(list); + goto LOPT; default: return adbg_oops(AdbgError.invalidOption); } diff --git a/src/adbg/platform.d b/src/adbg/platform.d index 48dc5896..aa8fa06c 100644 --- a/src/adbg/platform.d +++ b/src/adbg/platform.d @@ -209,7 +209,7 @@ else private enum NoBoundsCheck = ""; enum D_FEATURES = PIC~PIE~SIMD~AVX~AVX2~NoBoundsCheck; // -// ANCHOR Functions +// ANCHOR Info functions // /// Target information structure diff --git a/src/adbg/self.d b/src/adbg/self.d index 246089d3..4dec79ab 100644 --- a/src/adbg/self.d +++ b/src/adbg/self.d @@ -35,10 +35,12 @@ version (Windows) { PVOID AddVectoredExceptionHandler(ULONG, PVECTORED_EXCEPTION_HANDLER); } } else version (Posix) { + import adbg.include.posix.unistd; + import adbg.include.posix.ptrace; + import core.stdc.string : strstr; import core.sys.posix.signal; import core.sys.posix.ucontext; - import core.sys.posix.unistd; - import adbg.include.posix.ptrace; + import core.sys.posix.fcntl; private enum NO_SIGACTION = cast(sigaction_t*)0; } @@ -63,8 +65,6 @@ bool adbg_self_is_debugged() { version (Windows) { return IsDebuggerPresent() == TRUE; } else version (linux) { // https://stackoverflow.com/a/24969863 - import core.stdc.string : strstr; - // Linux 5.10 example status for cat(1) is 1392 Bytes enum BUFFERSZ = 4096; @@ -146,9 +146,6 @@ __gshared int function(adbg_exception_t*) __ufunction; version (Windows) extern (Windows) uint adbg_internal_handler(_EXCEPTION_POINTERS *e) { - import core.sys.windows.winbase : - EXCEPTION_IN_PAGE_ERROR, EXCEPTION_ACCESS_VIOLATION; - adbg_exception_t ex = void; ex.oscode = e.ExceptionRecord.ExceptionCode; @@ -185,11 +182,12 @@ void adbg_internal_handler(int sig, siginfo_t *si, void *p) { ex.oscode = sig; ex.type = adbg_exception_from_os(si.si_signo, si.si_code); ex.pid = getpid(); - ex.tid = gettid(); + //TODO: gettid() definition + //ex.tid = gettid(); switch (sig) { case SIGILL, SIGSEGV, SIGFPE, SIGBUS: - ex.fault_address = cast(size_t)sig._sifields._sigfault.si_addr; + ex.fault_address = cast(size_t)si._sifields._sigfault.si_addr; break; default: ex.fault_address = 0;