[all-commits] [llvm/llvm-project] 38df8c: [lldb] Survive ptrace(PT_DENY_ATTACH) when attachi...

Jonas Devlieghere via All-commits all-commits at lists.llvm.org
Mon Jun 22 17:24:52 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 38df8cbd328efd43326ef18fc26a9a881f76cec1
      https://github.com/llvm/llvm-project/commit/38df8cbd328efd43326ef18fc26a9a881f76cec1
  Author: Jonas Devlieghere <jonas at devlieghere.com>
  Date:   2026-06-22 (Mon, 22 Jun 2026)

  Changed paths:
    A lldb/test/API/macosx/deny-attach/Makefile
    A lldb/test/API/macosx/deny-attach/TestDenyAttach.py
    A lldb/test/API/macosx/deny-attach/main.c
    M lldb/tools/debugserver/source/MacOSX/MachProcess.mm

  Log Message:
  -----------
  [lldb] Survive ptrace(PT_DENY_ATTACH) when attaching (#204688) (#205198)

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



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list