go-delve/delve · error

internal debugger error: depth check error at instruction %d

Error message

internal debugger error: depth check error at instruction %d: expected at least %d have %d
%s

What it means

An internal stack-depth validation error in the expression compiler (depthCheck, pkg/proc/evalop/evalcompile.go): opcode i pops `npop` values but only `depth[i]` values are on the simulated operand stack, so the compiled program is malformed. Delve raises this as an internal debugger error because a valid compile should never underflow the stack.

Source

Thrown at pkg/proc/evalop/evalcompile.go:268

	}
	depth[0] = 0

	var err error
	checkAndSet := func(j, d int) { // sets depth[j] to d after checking that we can
		if depth[j] < 0 {
			depth[j] = d
		}
		if d != depth[j] {
			err = fmt.Errorf("internal debugger error: depth check error at instruction %d: expected depth %d have %d (jump target)\n%s", j, d, depth[j], Listing(depth, ctx.ops))
		}
	}

	debugPinnerSeen := false

	for i, op := range ctx.ops {
		npop, npush := op.depthCheck()
		if depth[i] < npop {
			return fmt.Errorf("internal debugger error: depth check error at instruction %d: expected at least %d have %d\n%s", i, npop, depth[i], Listing(depth, ctx.ops))
		}
		d := depth[i] - npop + npush
		checkAndSet(i+1, d)
		switch op := op.(type) {
		case *Jump:
			checkAndSet(op.Target, d)
		case *CallInjectionStartSpecial:
			debugPinnerSeen = true
		case *CallInjectionComplete:
			if op.DoPinning && !debugPinnerSeen {
				err = fmt.Errorf("internal debugger error: pinning call injection seen before call to %s at instruction %d", DebugPinnerFunctionName, i)
			}
		}
		if err != nil {
			return err
		}
	}

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Upgrade delve to the latest version where the compile bug may already be fixed
  2. Rewrite the expression in a simpler equivalent form (split into multiple print statements) to unblock debugging
  3. Report the bug to go-delve/delve with the full error including the instruction Listing
Defensive patterns

Strategy: try-catch

Try / catch

if err != nil && strings.Contains(err.Error(), "depth check error") {
    // internal compiler bug: fall back to simpler expression and report
    return fallbackEval(expr)
}

Prevention

When it happens

Trigger: CompileAST/CompileSet generating an opcode sequence where some op (produced by compiling a sub-expression) consumes more operands than its subtree pushed — always a delve compiler bug or an opcode/driver mismatch, not a user syntax error.

Common situations: Encountered when testing new evalop instructions without a correct depthCheck() implementation, after delve upgrades with expression-VM changes, or with exotic expressions (unusual casts, call injection in sub-expressions) that hit untested compile paths.

Related errors


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