Change two-pass behavior for loading mappings. Allow lazy binding of mappings by...
[enjoyable.git] / Categories / NSProcessInfo+Debugging.m
1 //
2 // NSProcessInfo+Debugging.m
3 // Enjoyable
4 //
5 // Created by Joe Wreschnig on 3/17/13.
6 //
7 //
8
9 #import "NSProcessInfo+Debugging.h"
10
11 #include <assert.h>
12 #include <stdbool.h>
13 #include <sys/types.h>
14 #include <unistd.h>
15 #include <sys/sysctl.h>
16
17 @implementation NSProcessInfo (Debugging)
18
19 - (BOOL)isBeingDebugged {
20 int mib[4];
21 struct kinfo_proc info;
22 size_t size = sizeof(info);
23
24 info.kp_proc.p_flag = 0;
25
26 mib[0] = CTL_KERN;
27 mib[1] = KERN_PROC;
28 mib[2] = KERN_PROC_PID;
29 mib[3] = self.processIdentifier;
30
31 return sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0) == 0
32 && (info.kp_proc.p_flag & P_TRACED) != 0;
33 }
34
35 @end