go-delve/delve · error

could not read %d bytes from register %d (size: %d)

Error message

could not read %d bytes from register %d (size: %d)

What it means

The plain variant of the composite-memory register read failure: a DWARF piece asks for piece.Size bytes from register piece.Val but the register buffer only has len(reg) bytes. Unlike error 550, FloatLoadError is nil, so the mismatch is in the DWARF expression vs. the actual register width, not a failed FP load.

Source

Thrown at pkg/proc/mem.go:146

	}
	return cm, err
}

func newCompositeMemory(mem MemoryReadWriter, arch *Arch, regs op.DwarfRegisters, pieces []op.Piece, size int64) (*compositeMemory, error) {
	cmem := &compositeMemory{realmem: mem, arch: arch, regs: regs, pieces: pieces, data: []byte{}}
	for i := range pieces {
		piece := &pieces[i]
		switch piece.Kind {
		case op.RegPiece:
			reg := regs.Bytes(piece.Val)
			if piece.Size == 0 && i == len(pieces)-1 {
				piece.Size = len(reg)
			}
			if piece.Size > len(reg) {
				if regs.FloatLoadError != nil {
					return 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)
				}
				return nil, fmt.Errorf("could not read %d bytes from register %d (size: %d)", piece.Size, piece.Val, len(reg))
			}
			cmem.data = append(cmem.data, reg[:piece.Size]...)
		case op.AddrPiece:
			buf := make([]byte, piece.Size)
			if _, err := mem.ReadMemory(buf, piece.Val); err != nil {
				return nil, fmt.Errorf("could not read %d bytes from address %#x: %v", piece.Size, piece.Val, err)
			}
			cmem.data = append(cmem.data, buf...)
		case op.ImmPiece:
			buf := piece.Bytes
			if buf == nil {
				sz := max(piece.Size, 8)
				if piece.Size == 0 && i == len(pieces)-1 {
					piece.Size = arch.PtrSize() // DWARF doesn't say what this should be
				}
				buf = make([]byte, sz)
				binary.LittleEndian.PutUint64(buf, piece.Val)
			}

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Verify the debugged binary architecture matches the debugger/arch tags; rebuild with the correct GOARCH.
  2. Check whether the DWARF producer emitted a piece size larger than the register width (e.g. DW_OP_piece 16 on a GPR) — recompile with a current toolchain.
  3. Update Delve so regs.Bytes maps vector registers (SSE/NEON) to their full width.
  4. If the variable lives in a vector register unsupported by this backend, inspect its memory location instead (force it to spill, e.g. print via pointer).

Example fix

// before: mismatched arch
GOARCH=arm64 dlv exec ./amd64-binary   // register widths disagree with DWARF
// after
GOARCH=amd64 dlv exec ./amd64-binary
Defensive patterns

Strategy: validation

Validate before calling

// Verify arch match and piece sizes before evaluating DWARF register pieces
if runtime.GOARCH != binaryArch { return errors.New("debugger arch mismatch with binary") }
for _, p := range pieces {
    if p.Size > len(regs.Bytes(p.Val)) { return fmt.Errorf("piece on reg %d requests %d > %d bytes", p.Val, p.Size, len(regs.Bytes(p.Val))) }
}

Type guard

func registerPieceReadable(regs proc.Registers, regnum, size int) bool {
    return size >= 0 && size <= len(regs.Bytes(uint64(regnum)))
}

Try / catch

if err := tryEval(v); err != nil {
    var re *RegisterReadError // or string match
    if strings.Contains(err.Error(), "could not read ") {
        v.Unreadable = err.Error(); return nil
    }
    return err
}

Prevention

When it happens

Trigger: CreateCompositeMemory on a location expression where a RegisterPiece's declared size (piece.Size, explicitly set in the DWARF or by the caller) is larger than the width of the register as reported by regs.Bytes — e.g. size overridden to a value that assumes a wider vector register, or reading a 128-bit piece from a 64-bit GPR.

Common situations: DWARF produced by compilers targeting vector types in registers on architectures Delve maps to narrower register buffers; stale binary vs. different-architecture debugger host; hand-crafted or mismatched core dump register sets.

Related errors


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