{"record":{"id":"8212cba58fb5b0da","repo":"go-delve/delve","slug":"internal-debugger-error-depth-check-error-at-inst-8212cb","errorCode":null,"errorMessage":"internal debugger error: depth check error at instruction %d: expected at least %d have %d\n%s","messagePattern":"internal debugger error: depth check error at instruction (.+?): expected at least (.+?) have (.+?)\n(.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/evalop/evalcompile.go","lineNumber":268,"sourceCode":"\t}\n\tdepth[0] = 0\n\n\tvar err error\n\tcheckAndSet := func(j, d int) { // sets depth[j] to d after checking that we can\n\t\tif depth[j] < 0 {\n\t\t\tdepth[j] = d\n\t\t}\n\t\tif d != depth[j] {\n\t\t\terr = 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))\n\t\t}\n\t}\n\n\tdebugPinnerSeen := false\n\n\tfor i, op := range ctx.ops {\n\t\tnpop, npush := op.depthCheck()\n\t\tif depth[i] < npop {\n\t\t\treturn 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))\n\t\t}\n\t\td := depth[i] - npop + npush\n\t\tcheckAndSet(i+1, d)\n\t\tswitch op := op.(type) {\n\t\tcase *Jump:\n\t\t\tcheckAndSet(op.Target, d)\n\t\tcase *CallInjectionStartSpecial:\n\t\t\tdebugPinnerSeen = true\n\t\tcase *CallInjectionComplete:\n\t\t\tif op.DoPinning && !debugPinnerSeen {\n\t\t\t\terr = fmt.Errorf(\"internal debugger error: pinning call injection seen before call to %s at instruction %d\", DebugPinnerFunctionName, i)\n\t\t\t}\n\t\t}\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/evalop/evalcompile.go#L250-L286","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Upgrade delve to the latest version where the compile bug may already be fixed","Rewrite the expression in a simpler equivalent form (split into multiple print statements) to unblock debugging","Report the bug to go-delve/delve with the full error including the instruction Listing"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"depth check error\") {\n    // internal compiler bug: fall back to simpler expression and report\n    return fallbackEval(expr)\n}","preventionTips":["Test new breakpoint conditions interactively before installing them","Upgrade delve before assuming expression syntax is broken","Simplify nested casts/calls if an internal error appears"],"tags":["debugger","internal","compiler","stack-depth","evalop"],"backgroundTag":"internal-invariant-violation","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}