go-delve/delve · error

write out of bounds

Error message

write out of bounds

What it means

compositeMemory.WriteMemory validates that the target range, after subtracting the memory base, lies entirely within the assembled data buffer. 'write out of bounds' means the write address or address+len(data) extends past the buffer backing this composite view, so Delve refuses to write rather than corrupt adjacent data.

Source

Thrown at pkg/proc/mem.go:190

		padding := make([]byte, paddingBytes)
		cmem.data = append(cmem.data, padding...)
	}
	return cmem, nil
}

func (mem *compositeMemory) ReadMemory(data []byte, addr uint64) (int, error) {
	addr -= mem.base
	if addr >= uint64(len(mem.data)) || addr+uint64(len(data)) > uint64(len(mem.data)) {
		return 0, errors.New("read out of bounds")
	}
	copy(data, mem.data[addr:addr+uint64(len(data))])
	return len(data), nil
}

func (mem *compositeMemory) WriteMemory(addr uint64, data []byte) (int, error) {
	addr -= mem.base
	if addr >= uint64(len(mem.data)) || addr+uint64(len(data)) > uint64(len(mem.data)) {
		return 0, errors.New("write out of bounds")
	}
	if mem.regs.ChangeFunc == nil {
		for _, piece := range mem.pieces {
			if piece.Kind == op.RegPiece {
				return 0, errors.New("can not write registers")
			}
		}
	}

	copy(mem.data[addr:], data)

	curAddr := uint64(0)
	donesz := 0
	for _, piece := range mem.pieces {
		if curAddr < (addr+uint64(len(data))) && addr < (curAddr+uint64(piece.Size)) {
			// changed memory interval overlaps current piece
			pieceMem := mem.data[curAddr : curAddr+uint64(piece.Size)]

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Set variables in the live topmost frame (frame 0)
  2. Rebuild without optimizations (-gcflags="all=-N -l") so variables have stable memory locations
  3. Verify the binary/core dump pairing matches; re-evaluate to refresh the memory view before writing

Example fix

// before
(dlv) frame 3
(dlv) set i = 10   // write out of bounds
// after
(dlv) frame 0
(dlv) set i = 10
Defensive patterns

Strategy: validation

Validate before calling

// Before 'set', confirm the variable has a memory (non-register) location:
//   (dlv) print &i   // a valid address in the live frame
// If &i fails or the frame is not 0, expect write failures.

Try / catch

err := setVariable("i", "10")
if err != nil && strings.Contains(err.Error(), "write out of bounds") {
    log.Printf("cannot set %s: not writable here (dead frame or register-backed)", "i")
}

Prevention

When it happens

Trigger: Calling variable-setting APIs (e.g. 'set' command, SetVariable) on a variable backed by compositeMemory when the resolved address is outside the assembled pieces' range — typically variables located in registers, optimized-away slots, or stale frames.

Common situations: Attempting to set a variable that lives partly or wholly in registers in optimized code; setting a variable in a dead/returned frame; address computation from a mismatched DWARF version.

Related errors


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