go-delve/delve · error
could not read float
Error message
could not read float
What it means
This error is returned by float reading code in Delve's variable loader when a float value of an unexpected size is encountered. The reader handles specific sizes (e.g. 4 and 8 bytes via binary.Read); any other size falls through to this error. It means Delve could not decode the raw target bytes into a Go float.
Source
Thrown at pkg/proc/variables.go:1886
val := make([]byte, int(size))
_, err := v.mem.ReadMemory(val, v.Addr)
if err != nil {
return 0.0, err
}
buf := bytes.NewBuffer(val)
switch size {
case 4:
n := float32(0)
binary.Read(buf, binary.LittleEndian, &n)
return float64(n), nil
case 8:
n := float64(0)
binary.Read(buf, binary.LittleEndian, &n)
return n, nil
}
return 0.0, errors.New("could not read float")
}
func (v *Variable) writeFloatRaw(f float64, size int64) error {
buf := bytes.NewBuffer(make([]byte, 0, size))
switch size {
case 4:
n := float32(f)
binary.Write(buf, binary.LittleEndian, n)
case 8:
n := f
binary.Write(buf, binary.LittleEndian, n)
}
_, err := v.mem.WriteMemory(v.Addr, buf.Bytes())
return err
}
View on GitHub (pinned to a23773e6c3)
Solutions
- Check the DWARF type of the variable (dlv: 'whatis <expr>') to see its declared byte size
- Cast or re-declare the value as float32/float64 in the debugged program so it maps to a supported 4/8-byte float
- If you maintain Delve, add a case for the missing size in the readSizeFloat switch
- File/inspect a Delve issue for the unsupported float size on your architecture
Example fix
// before: debugging a 16-byte float debuggee: var x long double = 1.0 // C interop, 16 bytes // after: use a supported width debuggee: var x float64 = 1.0
Defensive patterns
Strategy: validation
Validate before calling
// Only evaluate floats of supported widths
t := Whatis(expr)
if t.Size != 4 && t.Size != 8 {
// skip float evaluation or cast in the debuggee
return fmt.Errorf("unsupported float size %d for %s", t.Size, expr)
} Type guard
func isSupportedFloat(typ godwarf.Type) bool {
bt, ok := typ.(*godwarf.FloatType)
return ok && (bt.Size == 4 || bt.Size == 8)
} Try / catch
val, err := evalFloat(expr)
if err != nil && strings.Contains(err.Error(), "could not read float") {
// fall back to raw memory display
val = readRawBytes(expr)
} Prevention
- Declare floats as float32/float64 in debugged code
- Check 'whatis' before evaluating unusual numeric types
- Keep Delve version aligned with the compiler/toolchain producing the binary
- Avoid inspecting C long double / _Float128 via variable evaluation
When it happens
Trigger: Evaluating a variable whose DWARF type declares a floating-point base type with a byte size other than 4 or 8 (e.g. a 16-byte soft-float or an unusual compiler-emitted size), so the size switch has no matching case.
Common situations: Debugging binaries compiled with exotic float widths, cross-compiled targets, or non-standard C interop types (long double, _Float16/128) inspected through Delve.
Related errors
- unable to find function context
- unable to find locals: no debug information present in binar
- malformed map type: buckets, oldbuckets or overflow field no
- ctx variable not found
- ep variable not found
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/5fbd9dfc327baedf.
Report an issue: GitHub.