Skip to content

Instantly share code, notes, and snippets.

@rais38
Last active December 12, 2015 10:19
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 rais38/4758465 to your computer and use it in GitHub Desktop.
Save rais38/4758465 to your computer and use it in GitHub Desktop.
Detect If Your Application Is Running In The Debugger
static bool debuggerRunning(void) {
int junk;
int mib[4];
struct kinfo_proc info;
size_t size;
info.kp_proc.p_flag = 0;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();
size = sizeof(info);
junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
assert(junk == 0);
// If P_TRACED flag set, debugger running
return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
}
// @see http://iosdevelopertips.com/debugging/detect-if-your-application-is-running-in-the-debugger.html
if (debuggerRunning())
NSLog(@"Debugger running");
else
NSLog(@"Debugger not running");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment