go-delve/delve · error

kinfo_getproc failed: %v

Error message

kinfo_getproc failed: %v

What it means

During initialization on FreeBSD, Delve fetches the process's kinfo_proc via C.kinfo_getproc to learn the command name (ki_comm). If that C call errors — typically because the process no longer exists — initialize returns "kinfo_getproc failed: %v". Without this info the target cannot be fully initialized.

Source

Thrown at pkg/proc/native/proc_freebsd.go:196

		pid := int(proc.ki_pid)
		if _, isseen := seen[pid]; isseen {
			continue
		}
		seen[pid] = struct{}{}

		argv := strings.Join(getCmdLineInternal(ps, proc), " ")
		log.Debugf("waitfor: new process %q", argv)
		if strings.HasPrefix(argv, pfx) {
			return pid, nil
		}
	}
	return 0, nil
}

func initialize(dbp *nativeProcess) (string, error) {
	kp, err := C.kinfo_getproc(C.int(dbp.pid))
	if err != nil {
		return "", fmt.Errorf("kinfo_getproc failed: %v", err)
	}
	defer C.free(unsafe.Pointer(kp))

	comm := C.GoString(&kp.ki_comm[0])
	dbp.os.comm = strings.ReplaceAll(string(comm), "%", "%%")

	return getCmdLine(dbp.pid), nil
}

// kill kills the target process.
func (procgrp *processGroup) kill(dbp *nativeProcess) (err error) {
	if ok, _ := dbp.Valid(); !ok {
		return nil
	}
	dbp.execPtraceFunc(func() {
		for _, th := range dbp.threads {
			ptraceResume(th.ID)
		}

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Verify the pid exists: `ps -p <pid>` — if gone, find the new pid and reattach.
  2. Run dlv as the process owner (or root) if permission is the issue.
  3. Attach quickly after obtaining the pid to avoid the exit race.
  4. Check `sysctl kern.ptrace` restrictions if ps shows the process but attach still fails.

Example fix

// before
dlv attach 4242   // pid already exited
// after
ps aux | grep myapp        # get live pid
dlv attach $(pgrep myapp)
Defensive patterns

Strategy: validation

Validate before calling

out, err := exec.Command("ps", "-o", "pid=,user=", "-p", strconv.Itoa(pid)).Output()
if err != nil {
    return fmt.Errorf("pid %d does not exist or is not visible", pid)
}
owner := strings.TrimSpace(strings.Fields(string(out))[1])
if owner != currentUser() {
    return fmt.Errorf("pid %d owned by %s; insufficient permission", pid, owner)
}

Try / catch

comm, err := initialize(dbp)
if err != nil && strings.Contains(err.Error(), "kinfo_getproc failed") {
    // re-resolve the pid; the process likely exited between discovery and attach
}

Prevention

When it happens

Trigger: proc.Attach/initialize on FreeBSD when kinfo_getproc(C.int(dbp.pid)) fails: the pid is gone or never existed, or the caller lacks permission to query it.

Common situations: Attaching to a pid that exited between discovery and attach; typo in the pid; attaching to another user's process without privileges; FreeBSD kern.terminating processes not yet reaped.

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/3f9de69f6c9060c2. Report an issue: GitHub.