{"record":{"id":"66c1500686b4d268","repo":"go-delve/delve","slug":"could-not-retrieve-cfa-for-current-pc","errorCode":null,"errorMessage":"could not retrieve CFA for current PC","messagePattern":"could not retrieve CFA for current PC","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dwarf/op/op.go","lineNumber":209,"sourceCode":"\n\tswitch opcode {\n\tcase DW_OP_piece:\n\t\tsz, _ := leb128.DecodeUnsigned(ctxt.buf)\n\t\tpiece.Size = int(sz)\n\t\tctxt.pieces = append(ctxt.pieces, piece)\n\t\treturn nil\n\n\tcase DW_OP_bit_piece:\n\t\t// not supported\n\t\treturn fmt.Errorf(\"invalid instruction %#v\", opcode)\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid instruction %#v after %#v\", opcode, opcode0)\n\t}\n}\n\nfunc callframecfa(opcode Opcode, ctxt *context) error {\n\tif ctxt.CFA == 0 {\n\t\treturn errors.New(\"could not retrieve CFA for current PC\")\n\t}\n\tctxt.stack = append(ctxt.stack, ctxt.CFA)\n\treturn nil\n}\n\nfunc addr(opcode Opcode, ctxt *context) error {\n\tbuf := ctxt.buf.Next(ctxt.ptrSize)\n\tstack, err := dwarf.ReadUintRaw(bytes.NewReader(buf), binary.LittleEndian, ctxt.ptrSize)\n\tif err != nil {\n\t\treturn err\n\t}\n\tctxt.stack = append(ctxt.stack, int64(stack+ctxt.StaticBase))\n\treturn nil\n}\n\nfunc plusuconsts(opcode Opcode, ctxt *context) error {\n\tslen := len(ctxt.stack)\n\tnum, _ := leb128.DecodeUnsigned(ctxt.buf)","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/dwarf/op/op.go#L191-L227","documentation":"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.","triggerScenarios":"Executing a DWARF expression containing OP_call_frame_cfa via op.ExecuteStackProgram while passing a DwarfRegisters/context whose CFA field is 0 (unset).","commonSituations":"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.","solutions":["Populate ctxt.CFA from frame descriptors (via frame entry / FDE lookup) before executing the expression","If evaluating in a non-frame context, use a path that supplies the current goroutine's registers including CFA","Catch the error and report the variable as not available at this PC"],"exampleFix":"// before\nregs := op.DwarfRegisters{StaticBase: staticBase}\n// after\nregs := op.DwarfRegisters{StaticBase: staticBase, CFA: cfaFromFrame(thread, pc)}","handlingStrategy":"validation","validationCode":"if regs.CFA == 0 { return errors.New(\"CFA required for this expression\") }","typeGuard":null,"tryCatchPattern":"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 */ }","preventionTips":["Populate CFA from FDE/frame data before executing expressions that use DW_OP_call_frame_cfa","Use the proc layer's register setup rather than hand-built DwarfRegisters"],"tags":["dwarf","cfa","frame-info"],"backgroundTag":"missing-cfa","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}