Skip to content

Instantly share code, notes, and snippets.

@caldofran
Created June 30, 2015 09:30
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 caldofran/8c0c99db8aa2c128e399 to your computer and use it in GitHub Desktop.
Save caldofran/8c0c99db8aa2c128e399 to your computer and use it in GitHub Desktop.
Avoid attach runtime processes when debugging
//
// NSObject+debugCheck.h
// Reverse Me
//
// Created by Derek Selander on a happy day.
// Copyright (c) 2013 Derek Selander. All rights reserved.
//
#import <Foundation/Foundation.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <string.h>
@interface NSObject (debugCheck)
#define SEC_IS_BEING_DEBUGGED_RETURN_VOID() size_t size = sizeof(struct kinfo_proc); \
struct kinfo_proc info; \
int ret, name[4]; \
memset(&info, 0, sizeof(struct kinfo_proc)); \
name[0] = CTL_KERN; \
name[1] = KERN_PROC; \
name[2] = KERN_PROC_PID; \
name[3] = getpid(); \
if ((ret = (sysctl(name, 4, &info, &size, NULL, 0)))) { \
if (ret) return; \
} \
if (info.kp_proc.p_flag & P_TRACED) return
#define SEC_IS_BEING_DEBUGGED_RETURN_NIL() size_t size = sizeof(struct kinfo_proc); \
struct kinfo_proc info; \
int ret, name[4]; \
memset(&info, 0, sizeof(struct kinfo_proc)); \
name[0] = CTL_KERN; \
name[1] = KERN_PROC; \
name[2] = KERN_PROC_PID; \
name[3] = getpid(); \
if ((ret = (sysctl(name, 4, &info, &size, NULL, 0)))) { \
if (ret) return nil; \
} \
if (info.kp_proc.p_flag & P_TRACED) return nil
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment