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 := *v

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Avoid printing the C complex value directly; re-declare/extract it in Go as struct{re, im float64} fields and print those
  2. If it's a long double complex, read the raw bytes and decode manually (e.g. via an expression on its memory)
  3. Rebuild the cgo portion to expose real/imag parts as separate float64 fields
  4. 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

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


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