{"record":{"id":"5dedf7eabde3daec","repo":"go-delve/delve","slug":"could-not-continue-new-thread-d-s","errorCode":null,"errorMessage":"could not continue new thread %d %s","messagePattern":"could not continue new thread (.+?) (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/native/proc_freebsd.go","lineNumber":405,"sourceCode":"\t\t\t} else if pl_flags&_PL_FLAG_BORN != 0 {\n\t\t\t\tth, err = dbp.addThread(int(tid), false)\n\t\t\t\tif err != nil {\n\t\t\t\t\tif err == sys.ESRCH {\n\t\t\t\t\t\t// process died while we were adding it\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tif mode == trapWaitStepping {\n\t\t\t\t\tdbp.execPtraceFunc(func() { ptraceSuspend(tid) })\n\t\t\t\t}\n\t\t\t\tif err = dbp.ptraceCont(0); err != nil {\n\t\t\t\t\tif err == sys.ESRCH {\n\t\t\t\t\t\t// thread died while we were adding it\n\t\t\t\t\t\tdelete(dbp.threads, int(tid))\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\treturn nil, fmt.Errorf(\"could not continue new thread %d %s\", tid, err)\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\n\t\tif th == nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tif mode == trapWaitStepping {\n\t\t\treturn th, nil\n\t\t}\n\t\tif status.StopSignal() == sys.SIGTRAP || status.Continued() {\n\t\t\t// Continued in this case means we received the SIGSTOP signal\n\t\t\treturn th, nil\n\t\t}\n\n\t\t// TODO(dp) alert user about unexpected signals here.","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/native/proc_freebsd.go#L387-L423","documentation":"When trapWaitInternal sees a new thread (LWP) on FreeBSD it adds it to the thread map and issues ptrace(PT_CONTINUE) with signal 0 to let it run. If that continue fails with anything other than ESRCH (the tolerated 'thread died meanwhile' case), delve wraps the tid and error. The debugger cannot resume the newly created thread.","triggerScenarios":"ptraceCont(0) on a just-discovered tid returns an error other than ESRCH — e.g. EPERM because the tracer lost permission, or EINVAL from a bad state — while handling a new-thread stop event.","commonSituations":"Attaching to processes that spawn threads very rapidly; permission changes (target setuid, container dropping ptrace scope); FreeBSD version-specific PT_CONTINUE quirks.","solutions":["Run the debugger with sufficient privileges (same user or root) so PT_CONTINUE on every LWP is permitted.","Retry the operation; if the tid died (ESRCH) delve already tolerates it, other errno values may be transient after attach races.","Check the underlying errno in the message; EPERM points at credentials/ptrace-scope, EINVAL at kernel state.","Upgrade FreeBSD/delve if reproducible on valid tids."],"exampleFix":"// before\nif err := dbp.Continue(); err != nil { log.Fatal(err) } // could not continue new thread 4242 EPERM\n\n// after\nif err := dbp.Continue(); err != nil {\n    if strings.Contains(err.Error(), \"EPERM\") {\n        log.Fatal(\"delve lacks ptrace permission on target threads; run as same user or root\")\n    }\n    log.Fatal(err)\n}","handlingStrategy":"try-catch","validationCode":"// check ptrace scope/credentials before debugging on FreeBSD\nfunc checkPrivs() error {\n    if os.Geteuid() == 0 { return nil }\n    return fmt.Errorf(\"run as root or target owner for reliable thread continues\")\n}","typeGuard":null,"tryCatchPattern":"err := dbp.Continue()\nif err != nil && strings.Contains(err.Error(), \"could not continue new thread\") {\n    if strings.Contains(err.Error(), \"EPERM\") {\n        log.Fatal(\"insufficient ptrace privileges for new threads; run as root/same user\")\n    }\n    // otherwise retry once\n    err = dbp.Continue()\n}","preventionTips":["Run the debugger with sufficient privileges for every LWP.","Note ESRCH is tolerated internally; other errno values need privilege investigation.","Avoid setuid targets that drop traceability.","Keep FreeBSD/delve versions matched."],"tags":["freebsd","ptrace","threads","process-control"],"backgroundTag":"ptrace-continue-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}