go-delve/delve · error
could not find target %d
Error message
could not find target %d
What it means
'target switch <pid>' searches the current target group for a live target with the given PID. If no valid target matches, Delve returns 'could not find target %d'. The PID must belong to a currently debugged (followed or attached) process that is still valid.
Source
Thrown at service/dap/command.go:322
return "", fmt.Errorf("unknown argument %q to 'target follow-exec'", argv[0])
}
case "switch": // TODO: This may cause inconsistency between debugger and frontend.
tgrp, unlock := s.debugger.LockTargetGroup()
defer unlock()
pid, err := strconv.Atoi(argv[1])
if err != nil {
return "", err
}
found := false
for _, tgt := range tgrp.Targets() {
if _, err = tgt.Valid(); err == nil && tgt.Pid() == pid {
found = true
tgrp.Selected = tgt
tgt.SwitchThread(pid)
}
}
if !found {
return "", fmt.Errorf("could not find target %d", pid)
}
return fmt.Sprintf("Switched to process %d", pid), err
default:
return "", fmt.Errorf("unknown target command")
}
}
View on GitHub (pinned to a23773e6c3)
Solutions
- Run 'target list' to see valid target PIDs and pick one from that output.
- Verify the child process is still alive; if it exited, re-launch or re-enable follow-exec before the exec occurs.
- Check you are not confusing the dlv process PID or a shell PID with the debuggee PID.
- If the target should exist but does not, check follow-exec is enabled with a regex matching the child's cmdline.
Example fix
// before (guessed pid) target switch 99999 // after (use pid from target list) target list target switch 4242
Defensive patterns
Strategy: validation
Validate before calling
// query valid targets first via the evaluate command:
out := runEval("target list")
validPids := parsePidsFromList(out) // column 2 of each line
if !validPids[pid] {
return fmt.Errorf("pid %d not debugged; pick from target list", pid)
} Prevention
- Always source PIDs from 'target list' output
- Re-check liveness after child processes exit during follow-exec
- Do not confuse dlv's or a shell's PID with the debuggee PID
When it happens
Trigger: Running 'target switch 1234' where 1234 was never debugged, has exited (tgt.Valid() != nil), or belongs to an unrelated process on the system.
Common situations: Trying to switch to a child process that already exited during follow-exec debugging; using the parent shell PID instead of the debuggee PID; stale PID from a previous session; switching while only one target exists and mistyping the PID.
Related errors
- count/len must be a positive integer
- expected argument after -size
- size must be a positive integer (<=8)
- no address specified
- command not available
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/d643e1aa1d6c14e2.
Report an issue: GitHub.