go-delve/delve · error
invalid size (%d) for complex type
Error message
invalid size (%d) for complex type
What it means
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.
Source
Thrown at pkg/proc/variables.go:1780
errcount++
}
v.Children = append(v.Children, *fieldvar)
if errcount > maxErrCount {
break
}
}
}
func (v *Variable) readComplex(size int64) {
var fs int64
switch size {
case 8:
fs = 4
case 16:
fs = 8
default:
v.Unreadable = fmt.Errorf("invalid size (%d) for complex type", size)
return
}
ftyp := godwarf.FakeBasicType("float", int(fs*8))
realvar := v.newVariable("real", v.Addr, ftyp, v.mem)
imagvar := v.newVariable("imaginary", v.Addr+uint64(fs), ftyp, v.mem)
realvar.loadValue(loadSingleValue)
imagvar.loadValue(loadSingleValue)
v.Value = constant.BinaryOp(realvar.Value, token.ADD, constant.MakeImag(imagvar.Value))
}
func (v *Variable) writeComplex(real, imag float64, size int64) error {
err := v.writeFloatRaw(real, size/2)
if err != nil {
return err
}
imagaddr := *vView on GitHub (pinned to a23773e6c3)
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
Example fix
// before (C header via cgo)
typedef long double complex cldc;
print myCldc // invalid size (32) for complex type
// after
typedef struct { double re, im; } cldc_parts;
print myCldc.re; print myCldc.im
Defensive patterns
Strategy: type-guard
Validate before calling
// Only evaluate complex values of supported sizes
switch ct.Size() {
case 8, 16: // supported
default: // skip or decode manually
} Type guard
func isSupportedComplex(t godwarf.Type) bool {
ct, ok := t.(*godwarf.ComplexType)
return ok && (ct.Size() == 8 || ct.Size() == 16)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- could not read %d bytes from register %d (size: %d), also er
- could not read %d bytes from register %d (size: %d)
- could not read %d bytes from address %#x: %v
- could not dereference %s (no children?)
- Invalid type %s in slice array
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/b839fd1ed5b01eba.
Report an issue: GitHub.