go-delve/delve · error

cannot use %s as argument %s in function %s: stack object pa

Error message

cannot use %s as argument %s in function %s: stack object passed to escaping pointer: %s

What it means

During call injection Delve can run an escape check on each actual argument when scope.callCtx.checkEscape is enabled. If any pointer inside the argument points to an object on the goroutine's own stack that does not escape into any of the recorded stacks, passing it to the callee would be unsafe (the callee may retain it past the frame), so this error aborts the call.

Source

Thrown at pkg/proc/fncall.go:576

	}

	return nil
}

type funcCallArg struct {
	name       string
	typ        godwarf.Type
	off        int64
	dwarfEntry *godwarf.Tree // non-nil if Go 1.17+
	isret      bool
}

func funcCallCopyOneArg(scope *EvalScope, fncall *functionCallState, actualArg *Variable, formalArg *funcCallArg, thread Thread) error {
	if scope.callCtx.checkEscape {
		//TODO(aarzilli): only apply the escapeCheck to leaking parameters.
		err := allPointers(actualArg, formalArg.name, func(addr uint64, name string) error {
			if !pointerEscapes(addr, scope.g.stack, scope.callCtx.stacks) {
				return fmt.Errorf("cannot use %s as argument %s in function %s: stack object passed to escaping pointer: %s", actualArg.Name, formalArg.name, fncall.fn.Name, name)
			}
			return nil
		})
		if err != nil {
			return err
		}
	}

	//TODO(aarzilli): automatic wrapping in interfaces for cases not handled
	// by convertToEface.

	formalScope, err := GoroutineScope(scope.target, thread)
	if err != nil {
		return err
	}

	var formalArgVar *Variable
	if formalArg.dwarfEntry != nil {

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Heap-allocate the value explicitly before the call, e.g. x := new(T) or a global
  2. Assign the local to an interface/global so the compiler escapes it
  3. Disable the escape check if you understand the aliasing risk (checkEscape in callCtx)

Example fix

// before
local := MyStruct{}
call Process(&local) // stack object passed to escaping pointer
// after
local := new(MyStruct)
call Process(local)
Defensive patterns

Strategy: validation

Validate before calling

// allocate arguments on the heap before the call
arg := new(MyStruct)
*arg = value
// then: call Process(arg)

Try / catch

if err != nil && strings.Contains(err.Error(), "stack object passed to escaping pointer") {
    // redo the call with a heap-allocated argument
}

Prevention

When it happens

Trigger: Calling a function with an argument containing a pointer to a stack-allocated local while checkEscape is on, and pointerEscapes finds the address only in the current goroutine stack, not in scope.callCtx.stacks.

Common situations: Calling helper functions with &local variables or structs containing pointers to stack temporaries; common when the callee actually leaks the pointer (Go compiler would normally heap-allocate it).

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/7c06a04d76759fb5. Report an issue: GitHub.