{"record":{"id":"1cc6007eb6d2cd1f","repo":"go-delve/delve","slug":"could-not-get-scope-v","errorCode":null,"errorMessage":"could not get scope: %v","messagePattern":"could not get scope: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/stack.go","lineNumber":1049,"sourceCode":"\t\td.link.Unreadable = errSPDecreased\n\t}\n\treturn d.link\n}\n\nfunc (d *Defer) topdefer() *Defer {\n\tif len(d.rangefunc) > 0 {\n\t\treturn d.rangefunc[0]\n\t}\n\treturn d\n}\n\n// EvalScope returns an EvalScope relative to the argument frame of this deferred call.\n// The argument frame of a deferred call is stored in memory immediately\n// after the deferred header.\nfunc (d *Defer) EvalScope(t *Target, thread Thread) (*EvalScope, error) {\n\tscope, err := GoroutineScope(t, thread)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"could not get scope: %v\", err)\n\t}\n\n\tbi := thread.BinInfo()\n\tscope.PC = d.DwrapPC\n\tscope.File, scope.Line, scope.Fn = bi.PCToLine(d.DwrapPC)\n\n\tif scope.Fn == nil {\n\t\treturn nil, fmt.Errorf(\"could not find function at %#x\", d.DwrapPC)\n\t}\n\n\t// The arguments are stored immediately after the defer header struct, i.e.\n\t// addr+sizeof(_defer).\n\n\tif !bi.Arch.usesLR {\n\t\t// On architectures that don't have a link register CFA is always the address of the first\n\t\t// argument, that's what we use for the value of CFA.\n\t\t// For SP we use CFA minus the size of one pointer because that would be\n\t\t// the space occupied by pushing the return address on the stack during the","sourceCodeStart":1031,"sourceCodeEnd":1067,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/stack.go#L1031-L1067","documentation":"Defer.EvalScope builds an evaluation scope at the deferred call's argument frame. First it obtains a goroutine scope for the thread; if that underlying operation (thread registers, GetG, or stack access) fails, the error is wrapped with this prefix. The root cause is the inner error, not the defer itself.","triggerScenarios":"Calling Defer.EvalScope on a thread whose goroutine cannot be resolved or whose registers/stack can't be read — e.g. thread exited, target detached, or the goroutine is on the systemstack.","commonSituations":"Evaluating variables inside a deferred function while the debuggee is in an inconsistent state; inspecting a goroutine mid-panic where runtime state is torn down; races where the thread's goroutine changed between stop and evaluation.","solutions":["Inspect the wrapped inner error (%v) for the real cause and address that","Re-stop the process and re-fetch the goroutine before evaluating","Avoid evaluating defer scopes while the goroutine is in runtime/systemstack code","Update Delve if the inner error indicates a GetG or register-read bug"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"g, err := proc.GetG(thread); if err != nil || g == nil { return errors.New(\"cannot build defer scope: goroutine unavailable\") }","typeGuard":null,"tryCatchPattern":"scope, err := deferVar.EvalScope(t, thread); if err != nil { var inner error; fmt.Sscanf(err.Error(), \"could not get scope: %v\", &inner); /* handle inner cause: re-stop, re-acquire goroutine */ }","preventionTips":["Evaluate defer scopes only while the target is consistently stopped","Re-acquire goroutine state right before evaluation","Avoid defer-scope evaluation during panics/runtime teardown","Check the wrapped inner error before retrying"],"tags":["go","defer","evalscope","goroutine"],"backgroundTag":"scope-acquisition-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}