{"record":{"id":"1c0334cab21f22ae","repo":"go-delve/delve","slug":"nil-pointer-dereference-1c0334","errorCode":null,"errorMessage":"nil pointer dereference","messagePattern":"nil pointer dereference","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/fncall.go","lineNumber":519,"sourceCode":"\t\tpanic(\"not implemented\")\n\t}\n}\n\n// funcCallEvalFuncExpr evaluates expr.Fun and returns the function that we're trying to call.\n// If allowCalls is false function calls will be disabled even if scope.callCtx != nil\nfunc funcCallEvalFuncExpr(scope *EvalScope, stack *evalStack, fncall *functionCallState) error {\n\tbi := scope.BinInfo\n\n\tfnvar := stack.peek()\n\tif fnvar.Kind != reflect.Func {\n\t\treturn fmt.Errorf(\"expression %q is not a function\", astutil.ExprToString(fncall.expr.Fun))\n\t}\n\tfnvar.loadValue(LoadConfig{false, 0, 0, 0, 0, 0})\n\tif fnvar.Unreadable != nil {\n\t\treturn fnvar.Unreadable\n\t}\n\tif fnvar.Base == 0 {\n\t\treturn errors.New(\"nil pointer dereference\")\n\t}\n\tfncall.fn = bi.PCToFunc(fnvar.Base)\n\tif fncall.fn == nil {\n\t\treturn fmt.Errorf(\"could not find DIE for function %q\", astutil.ExprToString(fncall.expr.Fun))\n\t}\n\tif !fncall.fn.cu.isgo {\n\t\treturn errNotAGoFunction\n\t}\n\tfncall.closureAddr = fnvar.closureAddr\n\n\tvar err error\n\tfncall.argFrameSize, fncall.formalArgs, err = funcCallArgs(fncall.fn, bi, false)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\targnum := len(fncall.expr.Args)\n","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/fncall.go#L501-L537","documentation":"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.","triggerScenarios":"`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.","commonSituations":"Function variable assigned conditionally; nil func field in a struct at breakpoint; map lookups returning zero-value nil funcs.","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"],"exampleFix":"// before (target code)\nvar handler func(int)\ndlv> call handler(1) // nil\n// after\ncfg.Handler = realHandler\n(dlv) call cfg.Handler(1)","handlingStrategy":"validation","validationCode":"// before injecting, ensure the callee is non-nil\n// (dlv) print f\nfunc nilFuncGuard(f interface{}) bool {\n    if f == nil { return false }\n    v := reflect.ValueOf(f)\n    return v.Kind() == reflect.Func && !v.IsNil()\n}","typeGuard":"func isCallableFunc(v reflect.Value) bool {\n    return v.IsValid() && v.Kind() == reflect.Func && !v.IsNil()\n}","tryCatchPattern":"if err := scope.CallFunction(expr); err != nil && err.Error() == \"nil pointer dereference\" {\n    // the func variable is nil; initialize it in target code and retry\n}","preventionTips":["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"],"tags":["debugger","function-call-injection","nil-pointer"],"backgroundTag":"nil-function-pointer","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}