title: Xcode lldb can't attach to MacOS system program /bin/cp - "Not allowed to attach to process."
body: <p>When I try to use LLDB included with Xcode 12.4 to run the Unix <code>cp</code> command on either macOS Catalina 10.15.7 and Big Sur 11.2.2, LLDB freezes for several seconds when I start the process, then fails with the following error:</p>
  <blockquote>
  <p>error: process exited with status -1 (attach failed (Not allowed to attach to process.  Look in the console messages (Console.app), near the debugserver entries when the attached failed.  The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.))</p>
  </blockquote>
  <p>In Console, I see 10 copies of the same error from the LLDB <code>debugserver</code> engine server process just as promised, of form:</p>
  <blockquote>
  <p>error: MachTask::TaskPortForProcessID task_for_pid failed: ::task_for_pid ( target_tport = 0x0103, pid = 44753, &amp;task ) =&gt; err = 0x00000005 ((os/kern) failure)</p>
  </blockquote>
  <p>Attaching to the process while it's running, either from the <code>lldb</code> command line or from the Xcode IDE, produces the same error message, as does trying to run the debugger and debugged process using <code>sudo lldb</code>.</p>
  <p>What can I do to fix this issue?</p>
  <hr />
  <p>Full transcript of the terminal session:</p>
  <pre><code>$ lldb --version
  lldb-1200.0.44.2
  Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
  
  $ lldb cp /etc/profile ~/scratchfile.txt
  (lldb) target create &quot;cp&quot;
  Current executable set to 'cp' (x86_64).
  (lldb) settings set -- target.run-args  &quot;/etc/profile&quot; &quot;/Users/me/scratchfile.txt&quot;
  (lldb) run
  error: process exited with status -1 (attach failed (Not allowed to attach to process.  Look in the console messages (Console.app), near the debugserver entries when the attached failed.  The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.))
  </code></pre>