go-delve/delve · error

can not call optimized function %s when regabi is in use

Error message

can not call optimized function %s when regabi is in use

What it means

With Go's register-based ABI (regabi, Go 1.17+), Delve cannot manually encode calling conventions for optimized functions because the compiler omits complete argument info. Only whitelisted runtime functions (like mallocgc with a patched DIE) are supported, so calling any other optimized function is rejected.

Source

Thrown at pkg/proc/fncall.go:627

func funcCallArgs(fn *Function, bi *BinaryInfo, includeRet bool) (argFrameSize int64, formalArgs []funcCallArg, err error) {
	dwarfTree, err := fn.cu.image.getDwarfTree(fn.offset)
	if err != nil {
		return 0, nil, fmt.Errorf("DWARF read error: %v", err)
	}

	if bi.regabi && fn.Optimized() {
		if runtimeWhitelist[fn.Name] {
			runtimeOptimizedWorkaround(bi, fn.cu.image, dwarfTree)
		} else {
			// Debug info for function arguments on optimized functions is currently
			// too incomplete to attempt injecting calls to arbitrary optimized
			// functions.
			// Prior to regabi we could do this because the ABI was simple enough to
			// manually encode it in Delve.
			// Runtime.mallocgc is an exception, we specifically patch it's DIE to be
			// correct for call injection purposes.
			return 0, nil, fmt.Errorf("can not call optimized function %s when regabi is in use", fn.Name)
		}
	}

	varEntries := reader.Variables(dwarfTree, fn.Entry, int(^uint(0)>>1), reader.VariablesSkipInlinedSubroutines)

	// typechecks arguments, calculates argument frame size
	for _, entry := range varEntries {
		if entry.Tag != dwarf.TagFormalParameter {
			continue
		}
		argname, typ, err := readVarEntry(entry.Tree, fn.cu.image)
		if err != nil {
			return 0, nil, err
		}
		typ = godwarf.ResolveTypedef(typ)

		var formalArg *funcCallArg
		if bi.regabi {

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Rebuild with optimizations disabled: go build -gcflags=all="-N -l"
  2. Step past the function and reason about its return value manually instead of calling it
  3. Only call whitelisted runtime functions in optimized builds

Example fix

// before
go build -o app . && dlv exec ./app
call compute(x) // can not call optimized function
// after
go build -gcflags="all=-N -l" -o app . && dlv exec ./app
call compute(x)
Defensive patterns

Strategy: validation

Validate before calling

// build unoptimized for call-injection sessions:
// go build -gcflags="all=-N -l" -o app .

Try / catch

if err != nil && strings.Contains(err.Error(), "optimized function") {
    // step over the function and read the return value instead
}

Prevention

When it happens

Trigger: Using 'call' on a function compiled with optimizations (no -N -l) on Go >= 1.17 where bi.regabi is true and the function is not in runtimeWhitelist.

Common situations: Debugging production-style builds built without '-gcflags=all="-N -l"' and trying to inject calls into user functions; Go version upgrade to 1.17+ silently changing the ABI.

Related errors


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