{"record":{"id":"7659a87789119d2e","repo":"go-delve/delve","slug":"could-not-set-call-receiver-v","errorCode":null,"errorMessage":"could not set call receiver: %v","messagePattern":"could not set call receiver: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/fncall.go","lineNumber":1023,"sourceCode":"\tif fncall.closureAddr != 0 {\n\t\t// When calling a function pointer we must set the DX register to the\n\t\t// address of the function pointer itself.\n\t\tsetClosureReg(thread, fncall.closureAddr)\n\t}\n\n\tundo := new(undoInjection)\n\tundo.oldpc = regs.PC()\n\tif scope.BinInfo.Arch.Name == \"arm64\" || scope.BinInfo.Arch.Name == \"ppc64le\" || scope.BinInfo.Arch.Name == \"loong64\" {\n\t\tundo.oldlr = regs.LR()\n\t}\n\tcallOP(scope.BinInfo, thread, regs, fncall.fn.Entry)\n\n\tfncall.undoInjection = undo\n\n\tif fncall.receiver != nil {\n\t\terr := funcCallCopyOneArg(scope, fncall, fncall.receiver, &fncall.formalArgs[0], thread)\n\t\tif err != nil {\n\t\t\tstack.err = fmt.Errorf(\"could not set call receiver: %v\", err)\n\t\t\treturn\n\t\t}\n\t\tfncall.formalArgs = fncall.formalArgs[1:]\n\t}\n}\n\nfunc readStackVariable(t *Target, thread Thread, regs Registers, off uint64, typename string, loadCfg LoadConfig) (*Variable, error) {\n\tbi := thread.BinInfo()\n\tscope, err := ThreadScope(t, thread)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\ttyp, err := bi.findType(typename)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tv := newVariable(\"\", regs.SP()+off, typ, scope.BinInfo, scope.Mem)\n\tv.loadValue(loadCfg)","sourceCodeStart":1005,"sourceCodeEnd":1041,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/fncall.go#L1005-L1041","documentation":"When the injected call target is a method with a value/pointer receiver, Delve copies the receiver into the formal argument slot 0 via funcCallCopyOneArg before the call is made. If copying fails — unreadable receiver variable, unsupported type conversion, or a memory write error while placing the argument — evalCallInjectionSetTarget records \"could not set call receiver: %v\" on the eval stack and aborts the call injection.","triggerScenarios":"Evaluating a method call expression (e.g. call obj.Method(x)) where the receiver obj cannot be copied into the call frame: obj is unreadable (optimized-out, nil unsafe pointer deref during load), the receiver type mismatch, or writing the argument into the target's stack fails.","commonSituations":"Calling methods on variables that were optimized away by the compiler; method calls on nil pointers/maps; injecting calls in binaries built with heavy optimization (-gcflags=\"-N -l\" missing); calling methods on interface variables whose dynamic type can't be materialized.","solutions":["Read the wrapped cause to identify whether it is a variable-load failure or a memory write failure.","Rebuild the target with -gcflags=\"all=-N -l\" so receiver variables are not optimized out.","Check the receiver is valid (non-nil pointer, initialized value) before injecting the call.","Inject a call on a plain function or use a helper function that takes the receiver as an explicit argument instead.","Update Delve if the receiver type (e.g. new Go struct layout) is unsupported."],"exampleFix":"// before: receiver optimized out\nfunc main() { u := getUser(); _ = u } // u optimized away\ndlv> call u.Name()\n// after: keep receiver alive and valid\nfunc main() { u := getUser(); println(u.Name()) } // set breakpoint here\ndlv> call u.Name()","handlingStrategy":"validation","validationCode":"// before injecting a method call, verify the receiver is readable\nrecv, err := dbg.EvalVariable(scope, \"obj\", proc.LoadConfig{FollowPointers: true, MaxVariableRecurse: 1, MaxStringLen: 256})\nif err != nil || recv.Unreadable != nil {\n    return fmt.Errorf(\"receiver not available for call injection\")\n}","typeGuard":"func isInjectableReceiver(v *proc.Variable) bool {\n    return v != nil && v.Unreadable == nil && v.Addr != 0\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"could not set call receiver:\") {\n    // receiver copy failed: rebuild unoptimized or use a free function taking the receiver as an arg\n}","preventionTips":["Build with -gcflags=\"all=-N -l\" when you plan to use 'call'.","Don't call methods on nil pointers or optimized-out variables.","Prefer calling package-level functions with explicit args over method calls.","Set the breakpoint after the receiver is fully initialized.","Check 'print obj' works before attempting 'call obj.Method()'."],"tags":["go","debugger","method-call","function-call-injection","argument-passing"],"backgroundTag":"function-call-injection-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}