{"record":{"id":"5d05a3e9d5d102ee","repo":"go-delve/delve","slug":"unable-to-find-function-context","errorCode":null,"errorMessage":"unable to find function context","messagePattern":"unable to find function context","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":421,"sourceCode":"\tscope.rangeFrames, err = rangeFuncStackTrace(scope.target, scope.g)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(scope.rangeFrames) > 0 {\n\t\tscope.rangeFrames = scope.rangeFrames[2:] // skip the first frame and its return frame\n\t}\n\tscope.enclosingRangeScopes = make([]*EvalScope, len(scope.rangeFrames)/2)\n\treturn nil\n}\n\n// simpleLocals returns all local variables in 'scope'.\n// This function does not try to merge the scopes of range-over-func closure\n// bodies with their enclosing function, for that use (*EvalScope).Locals or\n// (*EvalScope).FindLocal instead.\n// If wantedName is specified only variables called wantedName or \"&\"+wantedName are returned.\nfunc (scope *EvalScope) simpleLocals(flags localsFlags, wantedName string) ([]*Variable, error) {\n\tif scope.Fn == nil {\n\t\treturn nil, errors.New(\"unable to find function context\")\n\t}\n\n\tif scope.image().Stripped() {\n\t\treturn nil, errors.New(\"unable to find locals: no debug information present in binary\")\n\t}\n\n\ttrustArgOrder := (flags&localsTrustArgOrder != 0) && scope.BinInfo.Producer() != \"\" && goversion.ProducerAfterOrEqual(scope.BinInfo.Producer(), 1, 12) && scope.Fn != nil && (scope.PC == scope.Fn.Entry)\n\n\tdwarfTree, err := scope.image().getDwarfTree(scope.Fn.offset)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvariablesFlags := reader.VariablesOnlyVisible | reader.VariablesSkipInlinedSubroutines\n\tif flags&localsNoDeclLineCheck != 0 {\n\t\tvariablesFlags = reader.VariablesNoDeclLineCheck\n\t}\n\tif scope.BinInfo.Producer() != \"\" && goversion.ProducerAfterOrEqual(scope.BinInfo.Producer(), 1, 15) {","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L403-L439","documentation":"simpleLocals enumerates local variables using DWARF debug info for scope.Fn. If the EvalScope has no function (Fn == nil) there is no function context whose DIE can be searched, so this error is thrown. It surfaces through (*EvalScope).Locals.","triggerScenarios":"Calling Locals() on a scope created with Fn unset: scope built from a frame whose function could not be resolved, scope where the PC is outside any known function (e.g., in runtime asm or a stripped region), or a manually constructed EvalScope without Fn.","commonSituations":"Evaluating locals while stopped in code compiled without symbols for that function, in a signal handler/trampoline, or in a shared library without DWARF; scripting the API and constructing an EvalScope manually without setting Fn.","solutions":["Stop at a location inside a known Go function (breakpoint at FirstPCAfterPrologue) before calling Locals().","Check scope.Fn before calling: if nil, report 'no function context' to the user instead of attempting locals.","Verify the binary includes debug info so functions resolve to DWARF DIEs.","Use a scope from a valid frame (FrameToScope on a frame from ThreadStacktrace/Stacktrace) rather than a hand-built scope."],"exampleFix":"// before\nvars, err := scope.Locals(0)\n// after\nif scope.Fn == nil {\n    return fmt.Errorf(\"cannot list locals: no function context at PC %#x\", scope.PC)\n}\nvars, err := scope.Locals(0)","handlingStrategy":"validation","validationCode":"if scope.Fn == nil {\n    return fmt.Errorf(\"no function context at PC %#x; cannot list locals\", scope.PC)\n}","typeGuard":"func hasFunctionContext(scope *proc.EvalScope) bool {\n    return scope != nil && scope.Fn != nil\n}","tryCatchPattern":"vars, err := scope.Locals(0)\nif err != nil && strings.Contains(err.Error(), \"unable to find function context\") {\n    return nil // no locals available here\n}","preventionTips":["Create scopes via FrameToScope/GoroutineScope from real stack frames","Only list locals when stopped inside a known Go function","Avoid hand-constructed EvalScopes without Fn","Keep debug info present so functions resolve"],"tags":["go","debugger","locals","dwarf"],"backgroundTag":"missing-function-context","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}