Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's a function from Apple to detect whether a program is being debugged in the <em>Technical Q&amp;A 1361</em> (<a href="https://developer.apple.com/library/mac/qa/qa2004/qa1361.html" rel="noreferrer">entry in Mac library</a> and <a href="https://developer.apple.com/library/ios/qa/qa1361/_index.html" rel="noreferrer">entry in iOS library</a>; they are identical). </p> <p>Code from the Technical Q&amp;A:</p> <pre><code>#include &lt;assert.h&gt; #include &lt;stdbool.h&gt; #include &lt;sys/types.h&gt; #include &lt;unistd.h&gt; #include &lt;sys/sysctl.h&gt; static bool AmIBeingDebugged(void) // Returns true if the current process is being debugged (either // running under the debugger or has a debugger attached post facto). { int junk; int mib[4]; struct kinfo_proc info; size_t size; // Initialize the flags so that, if sysctl fails for some bizarre // reason, we get a predictable result. info.kp_proc.p_flag = 0; // Initialize mib, which tells sysctl the info we want, in this case // we're looking for information about a specific process ID. mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PID; mib[3] = getpid(); // Call sysctl. size = sizeof(info); junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &amp;info, &amp;size, NULL, 0); assert(junk == 0); // We're being debugged if the P_TRACED flag is set. return ( (info.kp_proc.p_flag &amp; P_TRACED) != 0 ); } </code></pre> <p>Also pay attention to this note at the end of the Q&amp;A:</p> <blockquote> <p><strong>Important:</strong> Because the definition of the <code>kinfo_proc</code> structure (in <code>&lt;sys/sysctl.h&gt;</code>) is conditionalized by <code>__APPLE_API_UNSTABLE</code>, you should restrict use of the above code to the debug build of your program.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload