go-delve/delve · error

could not read string at %#v due to %s

Error message

could not read string at %#v due to %s

What it means

Delve read the string header successfully but the subsequent `ReadMemory` of the string's `min(strlen, MaxStringLen)` bytes at the data address failed. The address and the underlying error are both included in the message.

Source

Thrown at pkg/proc/variables.go:1568

				return 0, 0, nil
			}
		}
	}

	return outaddr, strlen, nil
}

func readStringValue(mem MemoryReadWriter, addr uint64, strlen int64, cfg LoadConfig) (string, error) {
	if strlen == 0 {
		return "", nil
	}

	count := min(strlen, int64(cfg.MaxStringLen))

	val := make([]byte, int(count))
	_, err := mem.ReadMemory(val, addr)
	if err != nil {
		return "", fmt.Errorf("could not read string at %#v due to %s", addr, err)
	}

	return string(val), nil
}

func readCStringValue(mem MemoryReadWriter, addr uint64, cfg LoadConfig) (string, bool, error) {
	buf := make([]byte, cfg.MaxStringLen) //
	val := buf[:0]                        // part of the string we've already read

	for len(buf) > 0 {
		// Reads some memory for the string but (a) never more than we would
		// need (considering cfg.MaxStringLen), and (b) never cross a page boundary
		// until we're sure we have to.
		// The page check is needed to avoid getting an I/O error for reading
		// memory we don't even need.
		// We don't know how big a page is but 1024 is a reasonable minimum common
		// divisor for all architectures.
		curaddr := addr + uint64(len(val))

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Check the data address in the message and verify it is mapped (inspect memory maps).
  2. Re-evaluate after the goroutine/stack state is stable; heap may have moved if the target was running.
  3. For core dumps, ensure the heap pages were captured.
  4. If MaxStringLen truncation is involved, still verify the base address separately; truncation does not cause this error.
Defensive patterns

Strategy: fallback

Validate before calling

// (dlv) print uintptr(str)  // validate the data pointer is non-nil and plausible
// (dlv) print str.len       // sanity-check the length

Try / catch

// In delve CLI, inspect the raw address instead:
// (dlv) print (*[64]byte)(unsafe.Pointer(uintptr(str)))
// to see whether the region is readable at all.

Prevention

When it happens

Trigger: Evaluating a string whose data pointer targets unmapped/freed memory; occurs in `readStringValue` after a successful header read when `mem.ReadMemory(val, addr)` fails.

Common situations: Dangling string pointers to freed heap (memory returned to the OS); core dumps missing the data pages; remote debugging where the target region is not accessible; nil or corrupted data pointer that survived the `addr == 0` check due to reads racing with the target.

Related errors


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