go-delve/delve · error
nil pointer dereference
Error message
nil pointer dereference
What it means
Delve throws this when the expression of a call evaluates to a nil function pointer: the function variable loaded fine, but its base address is 0, so there is no code to jump to for the injection. Since calling a nil function in Go would crash the target, Delve aborts injection up front.
Source
Thrown at pkg/proc/fncall.go:519
panic("not implemented")
}
}
// funcCallEvalFuncExpr evaluates expr.Fun and returns the function that we're trying to call.
// If allowCalls is false function calls will be disabled even if scope.callCtx != nil
func funcCallEvalFuncExpr(scope *EvalScope, stack *evalStack, fncall *functionCallState) error {
bi := scope.BinInfo
fnvar := stack.peek()
if fnvar.Kind != reflect.Func {
return fmt.Errorf("expression %q is not a function", astutil.ExprToString(fncall.expr.Fun))
}
fnvar.loadValue(LoadConfig{false, 0, 0, 0, 0, 0})
if fnvar.Unreadable != nil {
return fnvar.Unreadable
}
if fnvar.Base == 0 {
return errors.New("nil pointer dereference")
}
fncall.fn = bi.PCToFunc(fnvar.Base)
if fncall.fn == nil {
return fmt.Errorf("could not find DIE for function %q", astutil.ExprToString(fncall.expr.Fun))
}
if !fncall.fn.cu.isgo {
return errNotAGoFunction
}
fncall.closureAddr = fnvar.closureAddr
var err error
fncall.argFrameSize, fncall.formalArgs, err = funcCallArgs(fncall.fn, bi, false)
if err != nil {
return err
}
argnum := len(fncall.expr.Args)
View on GitHub (pinned to a23773e6c3)
Solutions
- Initialize the function variable before the call site in the target code
- Guard the call in target code (if f != nil) and re-run
- Inspect the variable with `print f` to see why it is nil
- Call the concrete function by name instead of through the variable
Example fix
// before (target code) var handler func(int) dlv> call handler(1) // nil // after cfg.Handler = realHandler (dlv) call cfg.Handler(1)
Defensive patterns
Strategy: validation
Validate before calling
// before injecting, ensure the callee is non-nil
// (dlv) print f
func nilFuncGuard(f interface{}) bool {
if f == nil { return false }
v := reflect.ValueOf(f)
return v.Kind() == reflect.Func && !v.IsNil()
} Type guard
func isCallableFunc(v reflect.Value) bool {
return v.IsValid() && v.Kind() == reflect.Func && !v.IsNil()
} Try / catch
if err := scope.CallFunction(expr); err != nil && err.Error() == "nil pointer dereference" {
// the func variable is nil; initialize it in target code and retry
} Prevention
- Initialize function variables before breakpoints where you call them
- Check `print f` for nil before call injection
- Guard calls through struct fields/maps of funcs in target code
- Call concrete named functions instead of nil-able func values
When it happens
Trigger: `call f()` where f is a nil func variable (declared but never assigned); calling a struct/interface field holding a nil function value; calling through a map of funcs with missing entry.
Common situations: Function variable assigned conditionally; nil func field in a struct at breakpoint; map lookups returning zero-value nil funcs.
Related errors
- nil can not be dereferenced
- nil pointer dereference
- not enough stack space
- too many arguments
- not enough arguments
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/1c0334cab21f22ae.
Report an issue: GitHub.