On Darwin, we first get a process' mach task port with task_for_pid(), and then we do a ptrace(PT_ATTACHEXC). We need to complete both before we are successfully attached. There are unusual failures where we get the task port and the ptrace may not have completed entirely, so lldb is going to exit out. An error message isn't created at the layer where this failure was detected, and then at a higher layer where we try to find a reason why the attach failed, we notice that the process is being "debugged" -- by ourselves -- and emit an error message saying it's being debugged.
This patch adds an error string at all the points where we can fail to complete this two-step attach process, and also adds a refinement to the "last ditch error reporting" scheme to confirm that the process' parent process isn't already this debugserver. (we half-attached to it)
As this is the exact same code as in MachProcess.mm, is this worth factoring out? Something like