go-delve/delve · error
invalid length: %d
Error message
invalid length: %d
What it means
After reading a string's `len` field from target memory, the value was negative. Go strings can never have negative lengths, so Delve rejects the header as corrupt rather than reading (or clamping) the string. This is a consistency check inside string header loading.
Source
Thrown at pkg/proc/variables.go:1542
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
}
func readStringValue(mem MemoryReadWriter, addr uint64, strlen int64, cfg LoadConfig) (string, error) {
if strlen == 0 {
return "", nilView on GitHub (pinned to a23773e6c3)
Solutions
- Verify the expression actually addresses a string (print the parent struct/value).
- Inspect raw memory at the address to confirm header contents.
- If memory is corrupted, find the code that overwrote it (this is a bug in the debugged program).
Defensive patterns
Strategy: validation
Validate before calling
// Verify the expression targets a real string: // (dlv) print parent.strField // then inspect len // A negative len means the memory is not a valid string header.
Prevention
- Confirm the evaluated address actually holds a string header (print the parent).
- Treat negative len as a sign of memory corruption in the debugged program.
- Avoid evaluating through stale or miscomputed pointer arithmetic.
When it happens
Trigger: Evaluating a string whose memory-resident `len` word is negative, i.e. the high bit of the pointer-size integer is set; typically means the header bytes were misread or the memory does not actually contain a string header.
Common situations: Reading misaligned or corrupted stack memory; evaluating through an incorrect expression that lands on non-string bytes; unsafe code that overwrote a string header.
Related errors
- could not read string len %s
- could not read string pointer %s
- could not read string at %#v due to %s
- could not decode first frame
- unable to find function context
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/40820beffdf9278c.
Report an issue: GitHub.