📜  如何检查是否没有在调试器 swift 代码示例中运行

📅  最后修改于: 2022-03-11 15:00:59.659000             🧑  作者: Mango

代码示例1
func amIBeingDebugged() -> Bool {

    var info = kinfo_proc()
    var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
    var size = strideofValue(info)
    let junk = sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0)
    assert(junk == 0, "sysctl failed")
    return (info.kp_proc.p_flag & P_TRACED) != 0
}