From 97b83a49864fb80604979ae9160e758bbce21dea Mon Sep 17 00:00:00 2001 From: Bastian Buck <59334447+bstnbuck@users.noreply.github.com> Date: Tue, 29 Jun 2021 14:00:48 +0200 Subject: [PATCH] os: add debugger_present() for linux (#10257) --- vlib/os/os_nix.c.v | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index f70cf623c8..07762358bb 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -6,6 +6,8 @@ import strings #include #include #include +#include +#include pub const ( path_separator = '/' @@ -64,6 +66,8 @@ fn C.getgid() int fn C.getegid() int +fn C.ptrace(u32, u32, voidptr, int) u64 + pub fn uname() Uname { mut u := Uname{} utsize := sizeof(C.utsname) @@ -317,7 +321,15 @@ 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 }