{"record":{"id":"2364df5a050d0581","repo":"go-delve/delve","slug":"no-address-for-escaped-variable","errorCode":null,"errorMessage":"no address for escaped variable","messagePattern":"no address for escaped variable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/proc/eval.go","lineNumber":553,"sourceCode":"\t\t}\n\t\tdepths = append(depths, depth)\n\t}\n\n\tif len(vars) == 0 {\n\t\treturn vars, nil\n\t}\n\n\tsort.Stable(&variablesByDepthAndDeclLine{vars, depths})\n\n\tlvn := map[string]*Variable{} // lvn[n] is the last variable we saw named n\n\n\tfor i, v := range vars {\n\t\tif name := v.Name; len(name) > 1 && name[0] == '&' {\n\t\t\tlocationExpr := v.LocationExpr\n\t\t\tdeclLine := v.DeclLine\n\t\t\tv = v.maybeDereference()\n\t\t\tif v.Addr == 0 && v.Unreadable == nil {\n\t\t\t\tv.Unreadable = errors.New(\"no address for escaped variable\")\n\t\t\t}\n\t\t\tv.Name = name[1:]\n\t\t\tv.Flags |= VariableEscaped\n\t\t\t// See https://github.com/go-delve/delve/issues/2049 for details\n\t\t\tif locationExpr != nil {\n\t\t\t\tlocationExpr.isEscaped = true\n\t\t\t\tv.LocationExpr = locationExpr\n\t\t\t}\n\t\t\tv.DeclLine = declLine\n\t\t\tvars[i] = v\n\t\t}\n\t\tif otherv := lvn[v.Name]; otherv != nil {\n\t\t\totherv.Flags |= VariableShadowed\n\t\t}\n\t\tlvn[v.Name] = v\n\t}\n\n\treturn vars, nil","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L535-L571","documentation":"When simpleLocals post-processes '&var' entries (variables that were optimized to escapes and exposed via a pointer pseudo-variable), it dereferences the pointer. If the resulting variable has Addr == 0 and no other unreadable reason, delve cannot locate the escaped variable's storage and marks the variable Unreadable with this error.","triggerScenarios":"Listing locals where the compiler (register ABI / escape analysis) replaced a variable with &var pointing to heap/stack slots, but the pointer value read as 0 — e.g., variable moved to registers, dead at the current PC, or memory read failed silently.","commonSituations":"Inspecting variables heavily optimized by newer Go compilers (Go 1.15+ register ABI); inspecting a variable outside its live range; debugging optimized (non -N -l) builds where a local only exists as a dead pointer slot.","solutions":["Rebuild with optimizations disabled: go build -gcflags=\"all=-N -l\" so locals stay addressable.","Step to a line where the variable is live (check DeclLine) and re-run locals.","Read the variable via print &var or print var at a stop point where the compiler kept it addressable; check v.Unreadable in tooling and degrade gracefully.","If scripting the API, treat Addr==0/Unreadable entries as unavailable and continue rather than aborting the whole locals list."],"exampleFix":"// before\nvars, err := scope.Locals(0)\nfor _, v := range vars { use(v) }\n// after\nvars, err := scope.Locals(0)\nfor _, v := range vars {\n    if v.Unreadable != nil {\n        continue // e.g. \"no address for escaped variable\": optimized out\n    }\n    use(v)\n}","handlingStrategy":"type-guard","validationCode":"vars, _ := scope.Locals(0)\nusable := []*proc.Variable{}\nfor _, v := range vars {\n    if v.Unreadable == nil { usable = append(usable, v) }\n}","typeGuard":"func isReadable(v *proc.Variable) bool {\n    return v != nil && v.Unreadable == nil && !(v.Addr == 0 && v.Kind == reflect.Ptr)\n}","tryCatchPattern":"vars, err := scope.Locals(0)\nfor _, v := range vars {\n    if v.Unreadable != nil && strings.Contains(v.Unreadable.Error(), \"no address for escaped variable\") {\n        render(v.Name, \"<optimized out>\")\n        continue\n    }\n    render(v.Name, v.ValueString())\n}","preventionTips":["Debug with -gcflags=\"all=-N -l\" to keep locals addressable","Inspect variables at lines where they are live (respect DeclLine)","Treat Unreadable variables as '<optimized out>' in tooling","Prefer newer delve versions with improved register-ABI variable tracking"],"tags":["go","debugger","compiler-optimization","locals"],"backgroundTag":"variable-optimized-out","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}