go-delve/delve · error
could not read string len %s
Error message
could not read string len %s
What it means
While reading a Go string header (the `stringStructDWARF` layout), Delve could not read the `len` field from target memory via `readIntRaw`. The underlying memory-read error is embedded in the message. Without the length, the string value cannot be loaded.
Source
Thrown at pkg/proc/variables.go:1539
return dstv.writeEmptyInterface(typeAddr, srcv)
}
func readStringInfo(mem MemoryReadWriter, arch *Arch, addr uint64, typ *godwarf.StringType) (uint64, int64, error) {
// string data structure is always two ptrs in size. Addr, followed by len
// https://research.swtch.com/godata
mem = cacheMemory(mem, addr, arch.PtrSize()*2)
var strlen int64
var outaddr uint64
var err error
for _, field := range typ.StructType.Field {
switch field.Name {
case "len":
strlen, err = readIntRaw(mem, addr+uint64(field.ByteOffset), int64(arch.PtrSize()))
if err != nil {
return 0, 0, fmt.Errorf("could not read string len %s", err)
}
if strlen < 0 {
return 0, 0, fmt.Errorf("invalid length: %d", strlen)
}
case "str":
outaddr, err = readUintRaw(mem, addr+uint64(field.ByteOffset), int64(arch.PtrSize()))
if err != nil {
return 0, 0, fmt.Errorf("could not read string pointer %s", err)
}
if addr == 0 {
return 0, 0, nil
}
}
}
return outaddr, strlen, nil
}
View on GitHub (pinned to a23773e6c3)
Solutions
- Read the embedded cause (%s) to see the actual memory error.
- Re-evaluate the variable once the target is fully stopped and live.
- For core dumps, ensure the memory containing the string header was dumped.
- Verify the variable address is valid by printing the enclosing struct.
Defensive patterns
Strategy: retry
Validate before calling
// (dlv) print str // see if the header itself is readable // (dlv) print uintptr(str.str) // verify data pointer
Try / catch
// Client-side: retry evaluation once the target is fully stopped
if strings.Contains(err.Error(), "could not read string len") {
time.Sleep(50 * time.Millisecond)
return evalVariable(expr) // retry after state settles
} Prevention
- Ensure the target is stopped before evaluating string variables.
- Use core dumps that capture the memory holding the string headers.
- Verify enclosing structs print correctly before drilling into string fields.
When it happens
Trigger: Evaluating any string variable or string field when the read of the `len` word at `addr+ByteOffset` fails; e.g. the string header address is invalid or the memory region is inaccessible.
Common situations: Inspecting strings in core dumps where the containing page was not captured; reading strings through a partially-connected remote session; evaluating variables whose addresses come from stale/unreadable stack frames.
Related errors
- could not read string pointer %s
- could not read string at %#v due to %s
- parent pointer unreadable: %w
- invalid length: %d
- short read
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/4a72a1a734ea4898.
Report an issue: GitHub.