go-delve/delve · error

could not retrieve CFA for current PC

Error message

could not retrieve CFA for current PC

What it means

Raised by the callframecfa opcode handler when DW_OP_call_frame_cfa is evaluated but the context's CFA (Canonical Frame Address) is zero, meaning no frame information was provided. The evaluator cannot push a meaningful CFA value.

Source

Thrown at pkg/dwarf/op/op.go:209

	switch opcode {
	case DW_OP_piece:
		sz, _ := leb128.DecodeUnsigned(ctxt.buf)
		piece.Size = int(sz)
		ctxt.pieces = append(ctxt.pieces, piece)
		return nil

	case DW_OP_bit_piece:
		// not supported
		return fmt.Errorf("invalid instruction %#v", opcode)
	default:
		return fmt.Errorf("invalid instruction %#v after %#v", opcode, opcode0)
	}
}

func callframecfa(opcode Opcode, ctxt *context) error {
	if ctxt.CFA == 0 {
		return errors.New("could not retrieve CFA for current PC")
	}
	ctxt.stack = append(ctxt.stack, ctxt.CFA)
	return nil
}

func addr(opcode Opcode, ctxt *context) error {
	buf := ctxt.buf.Next(ctxt.ptrSize)
	stack, err := dwarf.ReadUintRaw(bytes.NewReader(buf), binary.LittleEndian, ctxt.ptrSize)
	if err != nil {
		return err
	}
	ctxt.stack = append(ctxt.stack, int64(stack+ctxt.StaticBase))
	return nil
}

func plusuconsts(opcode Opcode, ctxt *context) error {
	slen := len(ctxt.stack)
	num, _ := leb128.DecodeUnsigned(ctxt.buf)

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Populate ctxt.CFA from frame descriptors (via frame entry / FDE lookup) before executing the expression
  2. If evaluating in a non-frame context, use a path that supplies the current goroutine's registers including CFA
  3. Catch the error and report the variable as not available at this PC

Example fix

// before
regs := op.DwarfRegisters{StaticBase: staticBase}
// after
regs := op.DwarfRegisters{StaticBase: staticBase, CFA: cfaFromFrame(thread, pc)}
Defensive patterns

Strategy: validation

Validate before calling

if regs.CFA == 0 { return errors.New("CFA required for this expression") }

Try / catch

if errors.Is(err, errors.New("could not retrieve CFA for current PC")) || err.Error() == "could not retrieve CFA for current PC" { /* supply frame context */ }

Prevention

When it happens

Trigger: Executing a DWARF expression containing OP_call_frame_cfa via op.ExecuteStackProgram while passing a DwarfRegisters/context whose CFA field is 0 (unset).

Common situations: Evaluating variable location expressions without thread/frame context (e.g., for globals where CFA is irrelevant but the expression still references it), or calling ExecuteStackProgram with default/zero DwarfRegisters.

Related errors


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