{"record":{"id":"0f80070064e6f66d","repo":"go-delve/delve","slug":"could-not-read-d-bytes-from-register-d-size-d","errorCode":null,"errorMessage":"could not read %d bytes from register %d (size: %d), also error loading floating point registers: %v","messagePattern":"could not read (.+?) bytes from register (.+?) \\(size: (.+?)\\), also error loading floating point registers: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/mem.go","lineNumber":144,"sourceCode":"\tif cm != nil {\n\t\tcm.base = fakeAddressUnresolv\n\t}\n\treturn cm, err\n}\n\nfunc newCompositeMemory(mem MemoryReadWriter, arch *Arch, regs op.DwarfRegisters, pieces []op.Piece, size int64) (*compositeMemory, error) {\n\tcmem := &compositeMemory{realmem: mem, arch: arch, regs: regs, pieces: pieces, data: []byte{}}\n\tfor i := range pieces {\n\t\tpiece := &pieces[i]\n\t\tswitch piece.Kind {\n\t\tcase op.RegPiece:\n\t\t\treg := regs.Bytes(piece.Val)\n\t\t\tif piece.Size == 0 && i == len(pieces)-1 {\n\t\t\t\tpiece.Size = len(reg)\n\t\t\t}\n\t\t\tif piece.Size > len(reg) {\n\t\t\t\tif regs.FloatLoadError != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"could not read %d bytes from register %d (size: %d), also error loading floating point registers: %v\", piece.Size, piece.Val, len(reg), regs.FloatLoadError)\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"could not read %d bytes from register %d (size: %d)\", piece.Size, piece.Val, len(reg))\n\t\t\t}\n\t\t\tcmem.data = append(cmem.data, reg[:piece.Size]...)\n\t\tcase op.AddrPiece:\n\t\t\tbuf := make([]byte, piece.Size)\n\t\t\tif _, err := mem.ReadMemory(buf, piece.Val); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"could not read %d bytes from address %#x: %v\", piece.Size, piece.Val, err)\n\t\t\t}\n\t\t\tcmem.data = append(cmem.data, buf...)\n\t\tcase op.ImmPiece:\n\t\t\tbuf := piece.Bytes\n\t\t\tif buf == nil {\n\t\t\t\tsz := max(piece.Size, 8)\n\t\t\t\tif piece.Size == 0 && i == len(pieces)-1 {\n\t\t\t\t\tpiece.Size = arch.PtrSize() // DWARF doesn't say what this should be\n\t\t\t\t}\n\t\t\t\tbuf = make([]byte, sz)","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/mem.go#L126-L162","documentation":"This error is thrown by newCompositeMemory in pkg/proc/mem.go when evaluating a DWARF location expression whose pieces read from CPU registers. A DWARF piece requested more bytes (piece.Size) than the register returned by regs.Bytes(piece.Val) actually provides (len(reg)). If the floating-point register load also failed, the underlying FloatLoadError is appended to give the real root cause.","triggerScenarios":"Calling CreateCompositeMemory (directly or via variable evaluation) on a DWARF expression containing op.RegisterPiece entries where piece.Size exceeds the register width — typically when FP/SSE registers (regnum >= 17) could not be loaded, so regs.Bytes returns an empty/short buffer while the piece still demands e.g. 16 bytes.","commonSituations":"Debugging on targets where the OS ptrace interface fails to return XSAVE/FP registers; evaluating variables of float/complex types whose value lives in XMM registers; core dumps or remote sessions with incomplete register sets; architectures/OS combos with buggy register backends.","solutions":["Inspect regs.FloatLoadError in the returned error — fix the underlying floating point register load failure first (OS support, ptrace permissions, core dump completeness).","Re-evaluate the variable after the thread is stopped at a point where FP registers are available (stepping out of the signal/syscall context that lost them).","Avoid evaluating variables whose DWARF location places them in XMM registers when using backends that cannot read them (e.g. eBPF uprobes).","Update Delve / OS kernel to a version that supports loading FP registers for this architecture."],"exampleFix":"// before: evaluating a double living in xmm0 with FP regs unavailable\n// err: could not read 8 bytes from register 17 (size: 0), also error loading floating point registers: ...\n// after: check FloatLoadError first and degrade gracefully\nv, err := evalScope.EvalVariable(name)\nif err != nil && strings.Contains(err.Error(), \"floating point registers\") {\n    v = &proc.Variable{Name: name, Unreadable: \"FP registers unavailable\"}\n}","handlingStrategy":"try-catch","validationCode":"// Before evaluating a variable whose location is a register piece:\nif regs.FloatLoadError != nil {\n    return fmt.Errorf(\"skip evaluation: FP registers unavailable: %w\", regs.FloatLoadError)\n}\nfor _, p := range pieces {\n    if p.Size > len(regs.Bytes(p.Val)) { return fmt.Errorf(\"piece %d needs %d bytes, reg has %d\", p.Val, p.Size, len(regs.Bytes(p.Val))) }\n}","typeGuard":"func pieceFitsInRegister(regs proc.Registers, piece dwarf.RegisterPiece) bool {\n    return piece.Size <= len(regs.Bytes(piece.Val))\n}","tryCatchPattern":"v, err := scope.EvalVariable(name)\nif err != nil && strings.Contains(err.Error(), \"could not read \") && strings.Contains(err.Error(), \"register \") {\n    // degrade: mark variable unreadable instead of failing the whole session\n    v = &proc.Variable{Name: name, Unreadable: err.Error()}\n}","preventionTips":["Always inspect the FloatLoadError part of the message first — it names the root cause.","Keep Delve and the OS kernel current for your architecture's FP register support.","Avoid backends that cannot read XMM/SSE registers when evaluating float/complex variables.","Re-evaluate after stopping at a proper breakpoint so the full register set is loaded."],"tags":["dwarf","registers","debugging","delve"],"backgroundTag":"register-read-too-short","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}