1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: add debugger_present() for linux (#10257)

This commit is contained in:
Bastian Buck 2021-06-29 14:00:48 +02:00 committed by GitHub
parent ab5a4cf4e5
commit 97b83a4986
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,8 @@ import strings
#include <unistd.h>
#include <fcntl.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/ptrace.h>
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
}