{"record":{"id":"11fb4110345653d8","repo":"go-delve/delve","slug":"ptrace","errorCode":null,"errorMessage":"ptrace","messagePattern":"ptrace","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/native/exec_darwin.c","lineNumber":79,"sourceCode":"\tchar sig;\n\n\tclose(fd[1]);\n\tread(fd[0], &sig, 1);\n\tclose(fd[0]);\n\n\t// Create a new process group.\n\tif (setpgid(0, 0) < 0) {\n\t\tperror(\"setpgid\");\n\t\texit(1);\n\t}\n\n\t// Set errno to zero before a call to ptrace.\n\t// It is documented that ptrace can return -1 even\n\t// for successful calls.\n\terrno = 0;\n\tpret = ptrace(PT_TRACE_ME, 0, 0, 0);\n\tif (pret != 0 && errno != 0) {\n\t\tperror(\"ptrace\");\n\t\texit(1);\n\t}\n\n\t// Change working directory if wd is not empty.\n\tif (wd && wd[0]) {\n\t\terrno = 0;\n\t\tcret = chdir(wd);\n\t\tif (cret != 0 && errno != 0) {\n\t\t\tchar *error_msg;\n\t\t\tasprintf(&error_msg, \"%s '%s'\", \"chdir\", wd);\n\t\t\tperror(error_msg);\n\t\t\texit(1);\n\t\t}\n\t}\n\n\terrno = 0;\n\tpret = ptrace(PT_SIGEXC, 0, 0, 0);\n\tif (pret != 0 && errno != 0) {","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/native/exec_darwin.c#L61-L97","documentation":"In fork_exec, the child calls ptrace(PT_TRACE_ME, ...) so the parent debugger can trace it. Delve zeroes errno first because ptrace may legitimately return -1 on success; the perror/exit path only runs when the call actually failed. Seeing \"ptrace\" here means PT_TRACE_ME failed and the debuggee aborted before exec, so the launch fails.","triggerScenarios":"Launching a binary with the native backend on macOS when PT_TRACE_ME is rejected — most commonly a debugger-entitlement/macOS hardening issue, or when the process is already being traced.","commonSituations":"macOS 10.14+ requiring developer-mode entitlements and codesigning for debugging; dlv binary lacking get-task-allow entitlement; running under another debugger or hardened runtime; corporate security tools blocking ptrace.","solutions":["Re-sign the dlv binary with a debugging entitlement (get-task-allow) or run `sudo DevToolsSecurity -enable` / `security authorizationdb` steps per delve docs.","Confirm no other tracer is attached to the child; PT_TRACE_ME fails if the process is already traced.","Rebuild/upgrade delve with the current Xcode toolchain so it matches your macOS version's ptrace semantics.","On macOS, make sure you are on a developer build environment (codesign certificate installed; Developer Mode enabled) and that security software isn't denying ptrace."],"exampleFix":"// before\npret = ptrace(PT_TRACE_ME, 0, 0, 0);\nif (pret != 0 && errno != 0) { perror(\"ptrace\"); exit(1); }\n// after (diagnosis aid)\npret = ptrace(PT_TRACE_ME, 0, 0, 0);\nif (pret != 0 && errno != 0) { fprintf(stderr, \"ptrace PT_TRACE_ME: %s (errno=%d)\\n\", strerror(errno), errno); exit(1); }","handlingStrategy":"validation","validationCode":"// Pre-flight on macOS: verify the dlv binary is entitled and codesigned for debugging\ncmd := exec.Command(\"codesign\", \"-d\", \"--entitlements\", \"-\", dlvPath)\nout, err := cmd.Output()\nif err != nil || !strings.Contains(string(out), \"get-task-allow\") {\n\treturn fmt.Errorf(\"dlv binary lacks get-task-allow debugging entitlement; re-sign it\")\n}","typeGuard":"func isPtraceDenied(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"ptrace\")\n}","tryCatchPattern":"err := dlvClient.Launch(ctx, prog, args)\nif err != nil && strings.Contains(err.Error(), \"ptrace\") {\n\treturn fmt.Errorf(\"launch denied: re-sign dlv with get-task-allow / enable Developer Mode: %w\", err)\n}","preventionTips":["Codesign dlv with the get-task-allow entitlement on macOS (Darwin hardening requires it).","Run `sudo DevToolsSecurity -enable` and install a valid developer certificate.","Ensure no other tracer/EDR is attached to processes at launch time.","Keep delve and the Xcode toolchain current for your macOS version."],"tags":["macos","ptrace","entitlements","process-launch","native-backend"],"backgroundTag":"ptrace-trace-me-denied","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}