llvm-project
f4043dbc - [lldb] Survive ptrace(PT_DENY_ATTACH) when attaching (#204688)

Commit
154 days ago
[lldb] Survive ptrace(PT_DENY_ATTACH) when attaching (#204688) A process can opt out of being debugged with ptrace(PT_DENY_ATTACH). The XNU kernel enforces this by delivering SIGSEGV to the *attaching* process while it is still inside the ptrace(PT_ATTACHEXC) syscall. This means debugserver gets killed before it can inspect the result. LLDB only sees the dropped connection ("error: attach failed: lost connection"). The condition can't be detected up front: the target's P_LNOATTACH flag is not exposed to userspace. To work around this, install a temporary SIGSEGV handler around the ptrace(PT_ATTACHEXC) call in AttachForDebug and siglongjmp back out if it fires, turning the fatal signal into an EPERM that propagates to lldb as a clear message: ``` error: attach failed: cannot attach to process N because it has disabled debugging via ptrace(PT_DENY_ATTACH) ``` The handler only acts on a SIGSEGV that arrives on the attaching thread while the guard is armed. Any other SIGSEGV restores the default handler and re-raises. Genuine, unrelated, crashes still report normally. rdar://44542907 Assisted-by: Claude
Author
Parents
Loading