Skip to content

Instantly share code, notes, and snippets.

@evianzhow
Forked from onevcat/debugger.m
Created September 24, 2015 04:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evianzhow/1bc6935a816182fa3498 to your computer and use it in GitHub Desktop.
Save evianzhow/1bc6935a816182fa3498 to your computer and use it in GitHub Desktop.
Check if a debugger attached.
- (BOOL)Debugger{
static BOOL debuggerIsAttached = NO;
static dispatch_once_t debuggerPredicate;
dispatch_once(&debuggerPredicate, ^{
struct kinfo_proc info;
size_t info_size = sizeof(info);
int name[4];
name[0] = CTL_KERN;
name[1] = KERN_PROC;
name[2] = KERN_PROC_PID;
name[3] = getpid();
if (sysctl(name, 4, &info, &info_size, NULL, 0) == -1) {
debuggerIsAttached = false;
}
if (!debuggerIsAttached && (info.kp_proc.p_flag & P_TRACED) != 0)
debuggerIsAttached = true;
});
return debuggerIsAttached;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment