{"record":{"id":"0ebd8484dbce40b5","repo":"go-delve/delve","slug":"could-not-fork-exec","errorCode":null,"errorMessage":"could not fork/exec","messagePattern":"could not fork/exec","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/proc/native/proc_darwin.go","lineNumber":88,"sourceCode":"\n\tdbp := newProcess(0)\n\tdefer func() {\n\t\tif err != nil && dbp.pid != 0 {\n\t\t\t_ = detachWithoutGroup(dbp, true)\n\t\t}\n\t}()\n\tvar pid int\n\tdbp.execPtraceFunc(func() {\n\t\twd := C.CString(wd)\n\t\tdefer C.free(unsafe.Pointer(wd))\n\t\tret := C.fork_exec(argv0, &argvSlice[0], C.int(len(argvSlice)),\n\t\t\twd,\n\t\t\t&dbp.os.task, &dbp.os.portSet, &dbp.os.exceptionPort,\n\t\t\t&dbp.os.notificationPort)\n\t\tpid = int(ret)\n\t})\n\tif pid <= 0 {\n\t\treturn nil, fmt.Errorf(\"could not fork/exec\")\n\t}\n\tdbp.pid = pid\n\tdbp.childProcess = true\n\tfor i := range argvSlice {\n\t\tC.free(unsafe.Pointer(argvSlice[i]))\n\t}\n\n\t// Initialize enough of the Process state so that we can use resume and\n\t// trapWait to wait until the child process calls execve.\n\n\tfor {\n\t\ttask := C.get_task_for_pid(C.int(dbp.pid))\n\t\t// The task_for_pid call races with the fork call. This can\n\t\t// result in the parent task being returned instead of the child.\n\t\tif task != dbp.os.task {\n\t\t\terr = dbp.updateThreadListForTask(task)\n\t\t\tif err == nil {\n\t\t\t\tbreak","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/native/proc_darwin.go#L70-L106","documentation":"Delve's Darwin native backend launches the debuggee via a C fork/exec helper (fork_exec) that returns the child pid. If the returned pid is <= 0 the helper failed to create or exec the child process, and Launch wraps this condition in the generic message \"could not fork/exec\". It means the inferior never started, so no debugging session exists.","triggerScenarios":"Calling dlv debug/launch on macOS when the C.fork_exec call in proc_darwin.go fails: bad executable path, missing execute permission, argv/env marshaling problems, or resource limits preventing fork. Detected by `pid <= 0` immediately after the fork/exec call.","commonSituations":"Debugging a binary path that doesn't exist or isn't executable; macOS security (SIP/hardened runtime) blocking the fork helper; running out of process descriptors; passing a command string with an empty argv slice.","solutions":["Verify the target binary path exists and is executable (ls -l, chmod +x) before launching.","Check the argv slice passed to Launch is non-empty and argv[0] is the program path.","Try building with `dlv debug` instead of `dlv exec <bin>` to rule out a stale/broken binary.","Check macOS security settings / SIP and antivirus software that may block ptrace-style helpers.","Rebuild Delve for your macOS version; older C helpers break on newer SDKs."],"exampleFix":"// before\ndlv exec ./notbuilt\n// after\ngo build -gcflags=\"all=-N -l\" -o ./app ./cmd/app\ndlv exec ./app","handlingStrategy":"validation","validationCode":"info, err := os.Stat(binPath)\nif err != nil || info.IsDir() {\n    return fmt.Errorf(\"binary %s missing: %w\", binPath, err)\n}\nif info.Mode()&0o111 == 0 {\n    return fmt.Errorf(\"binary %s is not executable\", binPath)\n}","typeGuard":null,"tryCatchPattern":"tgt, err := proc.Launch(cmd, wd, false, \"\", [], \"\", logger)\nif err != nil && strings.Contains(err.Error(), \"could not fork/exec\") {\n    // inspect cmd[0], permissions, and macOS security settings before retrying\n}","preventionTips":["Always build the target with debug flags (-gcflags=\"all=-N -l\") before launching.","Validate the executable path and mode before calling Launch.","Keep dlv rebuilt/signed for the current macOS version.","Avoid empty argv slices; argv[0] must be the program path."],"tags":["darwin","process-launch","fork-exec","native-backend"],"backgroundTag":"fork-exec-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}