go-delve/delve · error
unable to find function context
Error message
unable to find function context
What it means
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.
Source
Thrown at pkg/proc/eval.go:421
scope.rangeFrames, err = rangeFuncStackTrace(scope.target, scope.g)
if err != nil {
return err
}
if len(scope.rangeFrames) > 0 {
scope.rangeFrames = scope.rangeFrames[2:] // skip the first frame and its return frame
}
scope.enclosingRangeScopes = make([]*EvalScope, len(scope.rangeFrames)/2)
return nil
}
// simpleLocals returns all local variables in 'scope'.
// This function does not try to merge the scopes of range-over-func closure
// bodies with their enclosing function, for that use (*EvalScope).Locals or
// (*EvalScope).FindLocal instead.
// If wantedName is specified only variables called wantedName or "&"+wantedName are returned.
func (scope *EvalScope) simpleLocals(flags localsFlags, wantedName string) ([]*Variable, error) {
if scope.Fn == nil {
return nil, errors.New("unable to find function context")
}
if scope.image().Stripped() {
return nil, errors.New("unable to find locals: no debug information present in binary")
}
trustArgOrder := (flags&localsTrustArgOrder != 0) && scope.BinInfo.Producer() != "" && goversion.ProducerAfterOrEqual(scope.BinInfo.Producer(), 1, 12) && scope.Fn != nil && (scope.PC == scope.Fn.Entry)
dwarfTree, err := scope.image().getDwarfTree(scope.Fn.offset)
if err != nil {
return nil, err
}
variablesFlags := reader.VariablesOnlyVisible | reader.VariablesSkipInlinedSubroutines
if flags&localsNoDeclLineCheck != 0 {
variablesFlags = reader.VariablesNoDeclLineCheck
}
if scope.BinInfo.Producer() != "" && goversion.ProducerAfterOrEqual(scope.BinInfo.Producer(), 1, 15) {View on GitHub (pinned to a23773e6c3)
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.
Example fix
// before
vars, err := scope.Locals(0)
// after
if scope.Fn == nil {
return fmt.Errorf("cannot list locals: no function context at PC %#x", scope.PC)
}
vars, err := scope.Locals(0) Defensive patterns
Strategy: validation
Validate before calling
if scope.Fn == nil {
return fmt.Errorf("no function context at PC %#x; cannot list locals", scope.PC)
} Type guard
func hasFunctionContext(scope *proc.EvalScope) bool {
return scope != nil && scope.Fn != nil
} Try / catch
vars, err := scope.Locals(0)
if err != nil && strings.Contains(err.Error(), "unable to find function context") {
return nil // no locals available here
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- unable to find locals: no debug information present in binar
- no address for escaped variable
- malformed map type: buckets, oldbuckets or overflow field no
- ctx variable not found
- ep variable not found
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/5d05a3e9d5d102ee.
Report an issue: GitHub.