{"record":{"id":"7b6d6a77cef24b90","repo":"go-delve/delve","slug":"no-match-found-using-regexp-s-in-proc-d-stat","errorCode":null,"errorMessage":"no match found using regexp '%s' in /proc/%d/stat","messagePattern":"no match found using regexp '(.+?)' in /proc/(.+?)/stat","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/native/proc_linux.go","lineNumber":288,"sourceCode":"\tcomm, err := os.ReadFile(fmt.Sprintf(\"/proc/%d/comm\", dbp.pid))\n\tif err == nil {\n\t\t// removes newline character\n\t\tcomm = bytes.TrimSuffix(comm, []byte(\"\\n\"))\n\t}\n\n\tif len(comm) <= 0 {\n\t\tstat, err := os.ReadFile(fmt.Sprintf(\"/proc/%d/stat\", dbp.pid))\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"could not read proc stat: %v\", err)\n\t\t}\n\t\texpr := fmt.Sprintf(\"%d\\\\s*\\\\((.*)\\\\)\", dbp.pid)\n\t\trexp, err := regexp.Compile(expr)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"regexp compile error: %v\", err)\n\t\t}\n\t\tmatch := rexp.FindSubmatch(stat)\n\t\tif match == nil {\n\t\t\treturn \"\", fmt.Errorf(\"no match found using regexp '%s' in /proc/%d/stat\", expr, dbp.pid)\n\t\t}\n\t\tcomm = match[1]\n\t}\n\tdbp.os.comm = strings.ReplaceAll(string(comm), \"%\", \"%%\")\n\n\treturn getCmdLine(dbp.pid), nil\n}\n\nfunc (dbp *nativeProcess) GetBufferedTracepoints() []ebpf.RawUProbeParams {\n\tif dbp.os.ebpf == nil {\n\t\treturn nil\n\t}\n\treturn dbp.os.ebpf.GetBufferedTracepoints()\n}\n\n// kill kills the target process.\nfunc (procgrp *processGroup) kill(dbp *nativeProcess) error {\n\tif ok, _ := dbp.Valid(); !ok {","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/native/proc_linux.go#L270-L306","documentation":"After reading /proc/<pid>/stat, delve applies the regexp \"<pid>\\\\s*\\\\((.*)\\\\)\" to extract the command name. If FindSubmatch finds no match, it returns this error including the full expression and pid. This means the stat file's first field is not the expected pid or the file is malformed/truncated.","triggerScenarios":"initialize's comm fallback parses a stat file whose contents do not start with the traced pid — typically because the process exited and the pid was reused, or a race left a truncated read, or the kernel is not Linux-standard procfs (LXC/gVisor variants).","commonSituations":"Attaching in containers/sandboxes (gVisor, LXC) with non-conforming procfs; pid churn in busy CI environments; reading /proc for a zombie or being-reaped process whose stat layout differs.","solutions":["Re-run the attach; a race with process exit is the most common cause.","Inspect /proc/<pid>/stat manually to confirm the first field equals the pid.","If running under gVisor/LXC or other sandboxed procfs, test on a standard kernel or use a newer sandbox runtime with conformant procfs.","Run delve as root so it reads the correct process's stat rather than failing on visibility tricks."],"exampleFix":"// before\n_ = debugger.Attach(pid, nil) // no match found using regexp '1234\\s*\\((.*)\\)' in /proc/1234/stat\n\n// after\nstat, _ := os.ReadFile(fmt.Sprintf(\"/proc/%d/stat\", pid))\nif !strings.HasPrefix(string(stat), strconv.Itoa(pid)+\" \") {\n    return fmt.Errorf(\"pid %d vanished or was reused before attach\", pid)\n}\n_ = debugger.Attach(pid, nil)","handlingStrategy":"retry","validationCode":"// confirm stat file shape matches the pid before attach\nfunc statLooksSane(pid int) bool {\n    b, err := os.ReadFile(fmt.Sprintf(\"/proc/%d/stat\", pid))\n    return err == nil && strings.HasPrefix(string(b), strconv.Itoa(pid)+\" \")\n}","typeGuard":null,"tryCatchPattern":"err := debugger.Attach(pid, nil)\nif err != nil && strings.Contains(err.Error(), \"no match found using regexp\") {\n    // likely exit/pid-reuse race or non-standard procfs; retry once\n    err = debugger.Attach(pid, nil)\n}","preventionTips":["Retry attach once — the dominant cause is an exit/pid-reuse race.","Check /proc/<pid>/stat manually when failures repeat.","Beware sandboxed procfs (gVisor/LXC) with non-standard stat layout.","Run as root to rule out visibility-induced misreads."],"tags":["linux","procfs","regexp","attach"],"backgroundTag":"proc-stat-malformed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}