go-delve/delve · error

Frame %d does not exist in goroutine %d

Error message

Frame %d does not exist in goroutine %d

What it means

In Delve's terminal client, the `frame`/`scope`-dependent command calls the RPC Stacktrace for the current goroutine and frame. If the returned stack is empty, the requested frame index does not exist (frames are 0-indexed and bounded by the actual call depth), so the command fails with this message.

Source

Thrown at pkg/terminal/command.go:2548

		state, err := t.client.GetState()
		if err != nil {
			return "", 0, false, err
		}
		if showContext {
			printcontext(t, state)
		}
		if state.SelectedGoroutine != nil {
			return state.SelectedGoroutine.CurrentLoc.File, state.SelectedGoroutine.CurrentLoc.Line, true, nil
		}
		return state.CurrentThread.File, state.CurrentThread.Line, true, nil

	case len(args) == 0 && ctx.scoped():
		locs, err := t.client.Stacktrace(ctx.Scope.GoroutineID, ctx.Scope.Frame, ctx.Scope.Frame, 0, nil)
		if err != nil {
			return "", 0, false, err
		}
		if len(locs) == 0 {
			return "", 0, false, fmt.Errorf("Frame %d does not exist in goroutine %d", ctx.Scope.Frame, ctx.Scope.GoroutineID)
		}
		loc := locs[0]
		gid := ctx.Scope.GoroutineID
		if gid < 0 {
			state, err := t.client.GetState()
			if err != nil {
				return "", 0, false, err
			}
			if state.SelectedGoroutine != nil {
				gid = state.SelectedGoroutine.ID
			}
		}
		if showContext {
			fmt.Fprintf(t.stdout, "Goroutine %d frame %d at %s:%d (PC: %#x)\n", gid, ctx.Scope.Frame, loc.File, loc.Line, loc.PC)
		}
		return loc.File, loc.Line, true, nil

	default:

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Run `frames` (or `stack`) to see how many frames exist and pick a valid index
  2. Use `frame 0` to reset to the topmost frame
  3. Re-run `continue`/`step` so the scope refreshes, then retry the command

Example fix

// before (in a script against dlv)
frame 12
print x
// after
frames
frame 3
print x
Defensive patterns

Strategy: try-catch

Try / catch

locs, err := client.Stacktrace(gid, 0, 100, 0, nil)
if err != nil { return err }
if ctx.Frame >= len(locs) {
    return fmt.Errorf("frame %d out of range: goroutine %d has %d frames", ctx.Frame, gid, len(locs))
}

Prevention

When it happens

Trigger: Running a terminal command that resolves the current scope (e.g. printing/disassembly helpers) when ctx.Scope.Frame points beyond the goroutine's stack depth — typically after selecting a frame number larger than the stack, or after the stack shrank (unwound/deeper frames gone) while the frame index was still set.

Common situations: Typing `frame 20` or `up` repeatedly past the top of the stack, then running a command like `print` or `disass` that uses the scoped location; resuming execution in one terminal while another command still references an old deep frame.

Related errors


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