diff --git a/vlib/os/debugger_default.c.v b/vlib/os/debugger_default.c.v new file mode 100644 index 0000000000..d14e26bf15 --- /dev/null +++ b/vlib/os/debugger_default.c.v @@ -0,0 +1,7 @@ +module os + +// debugger_present returns a bool indicating if the process is being debugged +[inline] +pub fn debugger_present() bool { + return false +} diff --git a/vlib/os/debugger_linux.c.v b/vlib/os/debugger_linux.c.v new file mode 100644 index 0000000000..1bf0711d0b --- /dev/null +++ b/vlib/os/debugger_linux.c.v @@ -0,0 +1,13 @@ +module os + +#include + +fn C.ptrace(u32, u32, voidptr, voidptr) u64 + +// debugger_present returns a bool indicating if the process is being debugged +[inline] +pub fn debugger_present() bool { + // check if the parent could trace its process, + // if not a debugger must be present + return C.ptrace(C.PTRACE_TRACEME, 0, 1, 0) == -1 +} diff --git a/vlib/os/debugger_macos.c.v b/vlib/os/debugger_macos.c.v new file mode 100644 index 0000000000..9d78f7af0f --- /dev/null +++ b/vlib/os/debugger_macos.c.v @@ -0,0 +1,13 @@ +module os + +#include + +fn C.ptrace(int, u32, voidptr, int) int + +// debugger_present returns a bool indicating if the process is being debugged +[inline] +pub fn debugger_present() bool { + // check if the parent could trace its process, + // if not a debugger must be present + return C.ptrace(C.PT_TRACE_ME, 0, voidptr(1), 0) == -1 +} diff --git a/vlib/os/debugger_windows.c.v b/vlib/os/debugger_windows.c.v new file mode 100644 index 0000000000..abc769ce1a --- /dev/null +++ b/vlib/os/debugger_windows.c.v @@ -0,0 +1,10 @@ +module os + +// this is defined in builtin_windows.c.v in builtin +// fn C.IsDebuggerPresent() bool + +// debugger_present returns a bool indicating if the process is being debugged +[inline] +pub fn debugger_present() bool { + return C.IsDebuggerPresent() +} diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index b4e1fb194c..f6647b99b2 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -8,9 +8,6 @@ import strings #include #include #include -$if !solaris && !haiku && !emscripten ? { - #include -} pub const ( path_separator = '/' @@ -64,8 +61,6 @@ fn C.getgid() int fn C.getegid() int -fn C.ptrace(u32, u32, voidptr, voidptr) u64 - enum GlobMatch { exact ends_with @@ -434,18 +429,6 @@ pub fn (mut f File) close() { C.fclose(f.cfile) } -[inline] -pub fn debugger_present() bool { - // check if the parent could trace its process, - // if not a debugger must be present - $if linux { - return C.ptrace(C.PTRACE_TRACEME, 0, 1, 0) == -1 - } $else $if macos { - return C.ptrace(C.PT_TRACE_ME, 0, voidptr(1), 0) == -1 - } - return false -} - fn C.mkstemp(stemplate &u8) int // ensure_folder_is_writable checks that `folder` exists, and is writable to the process diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index 739098fcb4..5647314666 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -452,12 +452,6 @@ pub fn add_vectored_exception_handler(first bool, handler VectoredExceptionHandl C.AddVectoredExceptionHandler(u32(first), C.PVECTORED_EXCEPTION_HANDLER(handler)) } -// this is defined in builtin_windows.c.v in builtin -// fn C.IsDebuggerPresent() bool -pub fn debugger_present() bool { - return C.IsDebuggerPresent() -} - // uname returns information about the platform on which the program is running. // Currently `uname` on windows is not standardized, so it just mimics current practices from other popular software/language implementations: // busybox-v1.35.0 * `busybox uname -a` => "Windows_NT HOSTNAME 10.0 19044 x86_64 MS/Windows"