go-delve/delve · error

wrong number of arguments for runtime.frame

Error message

wrong number of arguments for runtime.frame

What it means

`runtime.frame(N)` is a Delve expression construct (not a real Go function) that selects a stack frame for subsequent member lookups in an eval expression, e.g. `runtime.frame(-1).x`. It requires exactly one argument; the compiler rejects any other arity at compile time.

Source

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

				ctx.pushOp(&PushThreadID{})

			case x.Name == "runtime" && node.Sel.Name == "rangeParentOffset":
				ctx.pushOp(&PushRangeParentOffset{})

			case x.Name == DelvePackage && node.Sel.Name == BreakpointHitCountVarName:
				ctx.pushOp(&PushBreakpointHitCount{})

			default:
				ctx.pushOp(&PushPackageVarOrSelect{Name: x.Name, Sel: node.Sel.Name})
			}

		case *ast.CallExpr:
			ident, ok := x.Fun.(*ast.SelectorExpr)
			if ok {
				f, ok := ident.X.(*ast.Ident)
				if ok && f.Name == "runtime" && ident.Sel.Name == "frame" {
					if len(x.Args) != 1 {
						return fmt.Errorf("wrong number of arguments for runtime.frame")
					}
					switch arg := x.Args[0].(type) {
					case *ast.BasicLit:
						fr, err := strconv.ParseInt(arg.Value, 10, 8)
						if err != nil {
							return err
						}
						// Push local onto the stack to be evaluated in the new frame context.
						ctx.pushOp(&PushLocal{Name: node.Sel.Name, Frame: fr})
						return nil
					default:
						return fmt.Errorf("expected integer value for frame, got %v", arg)
					}
				}
			}
			return ctx.compileUnary(node.X, &Select{node.Sel.Name})

		case *ast.BasicLit: // try to accept "package/path".varname syntax for package variables

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Supply exactly one integer frame argument: `runtime.frame(-2).varname` (0 = current frame, negative = callers)
  2. Split multi-frame access into separate evaluations, one per frame
  3. Correct the expression in the breakpoint condition or watch entry

Example fix

// before
(dlv) print runtime.frame().x
// error: wrong number of arguments for runtime.frame
// after
(dlv) print runtime.frame(-1).x
Defensive patterns

Strategy: validation

Validate before calling

func validateFrameCall(cond string) error {
    expr, err := parser.ParseExpr(cond)
    if err != nil { return err }
    ast.Inspect(expr, func(n ast.Node) bool {
        if call, ok := n.(*ast.CallExpr); ok {
            if sel, ok := call.Fun.(*ast.SelectorExpr); ok {
                if id, ok := sel.X.(*ast.Ident); ok && id.Name == "runtime" && sel.Sel.Name == "frame" && len(call.Args) != 1 {
                    err = fmt.Errorf("runtime.frame needs exactly 1 arg")
                }
            }
        }
        return true
    })
    return err
}

Try / catch

if err != nil && strings.Contains(err.Error(), "wrong number of arguments for runtime.frame") {
    return setCondition(bp, "runtime.frame(-1).x") // fix arity
}

Prevention

When it happens

Trigger: Compiling an expression containing `runtime.frame` with zero or more than one argument, e.g. `runtime.frame().x`, `runtime.frame(1, 2).x`, or a leftover empty call after editing.

Common situations: Users pattern-match ordinary Go function-call syntax and omit or add arguments; templates with placeholders left unedited in breakpoint conditions.

Related errors


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