{"record":{"id":"d643e1aa1d6c14e2","repo":"go-delve/delve","slug":"could-not-find-target-d-d643e1","errorCode":null,"errorMessage":"could not find target %d","messagePattern":"could not find target (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/dap/command.go","lineNumber":322,"sourceCode":"\t\t\treturn \"\", fmt.Errorf(\"unknown argument %q to 'target follow-exec'\", argv[0])\n\t\t}\n\tcase \"switch\": // TODO: This may cause inconsistency between debugger and frontend.\n\t\ttgrp, unlock := s.debugger.LockTargetGroup()\n\t\tdefer unlock()\n\t\tpid, err := strconv.Atoi(argv[1])\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\tfound := false\n\t\tfor _, tgt := range tgrp.Targets() {\n\t\t\tif _, err = tgt.Valid(); err == nil && tgt.Pid() == pid {\n\t\t\t\tfound = true\n\t\t\t\ttgrp.Selected = tgt\n\t\t\t\ttgt.SwitchThread(pid)\n\t\t\t}\n\t\t}\n\t\tif !found {\n\t\t\treturn \"\", fmt.Errorf(\"could not find target %d\", pid)\n\t\t}\n\t\treturn fmt.Sprintf(\"Switched to process %d\", pid), err\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"unknown target command\")\n\t}\n}\n","sourceCodeStart":304,"sourceCodeEnd":329,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/dap/command.go#L304-L329","documentation":"'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.","triggerScenarios":"Running 'target switch 1234' where 1234 was never debugged, has exited (tgt.Valid() != nil), or belongs to an unrelated process on the system.","commonSituations":"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.","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."],"exampleFix":"// before (guessed pid)\ntarget switch 99999\n// after (use pid from target list)\ntarget list\ntarget switch 4242","handlingStrategy":"validation","validationCode":"// query valid targets first via the evaluate command:\nout := runEval(\"target list\")\nvalidPids := parsePidsFromList(out) // column 2 of each line\nif !validPids[pid] {\n    return fmt.Errorf(\"pid %d not debugged; pick from target list\", pid)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["dap","multiprocess","target-switch"],"backgroundTag":"target-not-found","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}