{"record":{"id":"b839fd1ed5b01eba","repo":"go-delve/delve","slug":"invalid-size-d-for-complex-type","errorCode":null,"errorMessage":"invalid size (%d) for complex type","messagePattern":"invalid size \\((.+?)\\) for complex type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/variables.go","lineNumber":1780,"sourceCode":"\t\t\terrcount++\n\t\t}\n\n\t\tv.Children = append(v.Children, *fieldvar)\n\t\tif errcount > maxErrCount {\n\t\t\tbreak\n\t\t}\n\t}\n}\n\nfunc (v *Variable) readComplex(size int64) {\n\tvar fs int64\n\tswitch size {\n\tcase 8:\n\t\tfs = 4\n\tcase 16:\n\t\tfs = 8\n\tdefault:\n\t\tv.Unreadable = fmt.Errorf(\"invalid size (%d) for complex type\", size)\n\t\treturn\n\t}\n\n\tftyp := godwarf.FakeBasicType(\"float\", int(fs*8))\n\n\trealvar := v.newVariable(\"real\", v.Addr, ftyp, v.mem)\n\timagvar := v.newVariable(\"imaginary\", v.Addr+uint64(fs), ftyp, v.mem)\n\trealvar.loadValue(loadSingleValue)\n\timagvar.loadValue(loadSingleValue)\n\tv.Value = constant.BinaryOp(realvar.Value, token.ADD, constant.MakeImag(imagvar.Value))\n}\n\nfunc (v *Variable) writeComplex(real, imag float64, size int64) error {\n\terr := v.writeFloatRaw(real, size/2)\n\tif err != nil {\n\t\treturn err\n\t}\n\timagaddr := *v","sourceCodeStart":1762,"sourceCodeEnd":1798,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/variables.go#L1762-L1798","documentation":"Loading a complex-typed variable, Delve only supports DWARF complex types of byte size 8 (two float32) or 16 (two float64). Any other size (e.g. DWARF from a non-Go compiler or corrupted type entries) makes the value unreadable.","triggerScenarios":"Evaluating a variable whose DWARF base type is DW_TAG_complex_type with a size other than 8 or 16 bytes, such as complex from cgo/C code (e.g. long double complex) or a corrupted type entry.","commonSituations":"Debugging cgo programs that expose C99 _Complex types (especially long double complex = 32 bytes on x86-64); inspecting values through mixed-language DWARF; malformed debug info in core dumps.","solutions":["Avoid printing the C complex value directly; re-declare/extract it in Go as struct{re, im float64} fields and print those","If it's a long double complex, read the raw bytes and decode manually (e.g. via an expression on its memory)","Rebuild the cgo portion to expose real/imag parts as separate float64 fields","Verify DWARF info integrity with readelf/objdump if the type should be complex128"],"exampleFix":"// before (C header via cgo)\ntypedef long double complex cldc;\nprint myCldc            // invalid size (32) for complex type\n// after\ntypedef struct { double re, im; } cldc_parts;\nprint myCldc.re; print myCldc.im\n","handlingStrategy":"type-guard","validationCode":"// Only evaluate complex values of supported sizes\nswitch ct.Size() {\ncase 8, 16: // supported\ndefault: // skip or decode manually\n}","typeGuard":"func isSupportedComplex(t godwarf.Type) bool {\n    ct, ok := t.(*godwarf.ComplexType)\n    return ok && (ct.Size() == 8 || ct.Size() == 16)\n}","tryCatchPattern":null,"preventionTips":["Avoid exposing C99 _Complex (especially long double) to Go via cgo","Expose real/imag parts as separate float64 fields instead","Check DWARF type sizes with readelf before debugging mixed-language values"],"tags":["delve","complex","dwarf","cgo"],"backgroundTag":"unsupported-dwarf-type","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}