{"record":{"id":"5fbd9dfc327baedf","repo":"go-delve/delve","slug":"could-not-read-float","errorCode":null,"errorMessage":"could not read float","messagePattern":"could not read float","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/variables.go","lineNumber":1886,"sourceCode":"\tval := make([]byte, int(size))\n\t_, err := v.mem.ReadMemory(val, v.Addr)\n\tif err != nil {\n\t\treturn 0.0, err\n\t}\n\tbuf := bytes.NewBuffer(val)\n\n\tswitch size {\n\tcase 4:\n\t\tn := float32(0)\n\t\tbinary.Read(buf, binary.LittleEndian, &n)\n\t\treturn float64(n), nil\n\tcase 8:\n\t\tn := float64(0)\n\t\tbinary.Read(buf, binary.LittleEndian, &n)\n\t\treturn n, nil\n\t}\n\n\treturn 0.0, errors.New(\"could not read float\")\n}\n\nfunc (v *Variable) writeFloatRaw(f float64, size int64) error {\n\tbuf := bytes.NewBuffer(make([]byte, 0, size))\n\n\tswitch size {\n\tcase 4:\n\t\tn := float32(f)\n\t\tbinary.Write(buf, binary.LittleEndian, n)\n\tcase 8:\n\t\tn := f\n\t\tbinary.Write(buf, binary.LittleEndian, n)\n\t}\n\n\t_, err := v.mem.WriteMemory(v.Addr, buf.Bytes())\n\treturn err\n}\n","sourceCodeStart":1868,"sourceCodeEnd":1904,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/variables.go#L1868-L1904","documentation":"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.","triggerScenarios":"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.","commonSituations":"Debugging binaries compiled with exotic float widths, cross-compiled targets, or non-standard C interop types (long double, _Float16/128) inspected through Delve.","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"],"exampleFix":"// before: debugging a 16-byte float\ndebuggee: var x long double = 1.0 // C interop, 16 bytes\n// after: use a supported width\ndebuggee: var x float64 = 1.0","handlingStrategy":"validation","validationCode":"// Only evaluate floats of supported widths\nt := Whatis(expr)\nif t.Size != 4 && t.Size != 8 {\n    // skip float evaluation or cast in the debuggee\n    return fmt.Errorf(\"unsupported float size %d for %s\", t.Size, expr)\n}","typeGuard":"func isSupportedFloat(typ godwarf.Type) bool {\n    bt, ok := typ.(*godwarf.FloatType)\n    return ok && (bt.Size == 4 || bt.Size == 8)\n}","tryCatchPattern":"val, err := evalFloat(expr)\nif err != nil && strings.Contains(err.Error(), \"could not read float\") {\n    // fall back to raw memory display\n    val = readRawBytes(expr)\n}","preventionTips":["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"],"tags":["debugger","go","dwarf","float"],"backgroundTag":"unsupported-type-size","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}