go-delve/delve · error
malformed /proc/pid/maps on line %d: %q (bad first field)
Error message
malformed /proc/pid/maps on line %d: %q (bad first field)
What it means
The maps line had 6 fields but the first field could not be split on '-' into exactly two parts. The first column of /proc/pid/maps must be '<hexstart>-<hexend>'; anything else is malformed and MemoryMap cannot build the memory map.
Source
Thrown at pkg/proc/native/dump_linux.go:90
Filename: filename,
Offset: offset,
})
}
return r, nil
}
func parseSmapsHeaderLine(lineno int, in string) (start, end uint64, perm string, offset uint64, dev, filename string, err error) {
fields := strings.SplitN(in, " ", 6)
if len(fields) != 6 {
err = fmt.Errorf("malformed /proc/pid/maps on line %d: %q (wrong number of fields)", lineno, in)
return
}
v := strings.Split(fields[0], "-")
if len(v) != 2 {
err = fmt.Errorf("malformed /proc/pid/maps on line %d: %q (bad first field)", lineno, in)
return
}
start, err = strconv.ParseUint(v[0], 16, 64)
if err != nil {
err = fmt.Errorf("malformed /proc/pid/maps on line %d: %q (%v)", lineno, in, err)
return
}
end, err = strconv.ParseUint(v[1], 16, 64)
if err != nil {
err = fmt.Errorf("malformed /proc/pid/maps on line %d: %q (%v)", lineno, in, err)
return
}
perm = fields[1]
if len(perm) < 4 {
err = fmt.Errorf("malformed /proc/pid/maps on line %d: %q (permissions column too short)", lineno, in)
return
}View on GitHub (pinned to a23773e6c3)
Solutions
- Make sure the file being parsed is /proc/<pid>/maps, not smaps/smaps_rollup.
- Filter out non-header lines (lines containing ':') before calling the parser.
- Retry after re-reading the file completely — a torn read can splice lines.
- If the kernel uses a nonstandard format, normalize lines before parsing.
Example fix
// before: line fed directly from smaps
"Size: 132 kB" // fields[0] = "Size:" -> no '-'
// after: only header lines contain '-' in field 0
if !strings.HasPrefix(fields[0], "") && strings.Contains(fields[0], "-") { parseSmapsHeaderLine(...) } Defensive patterns
Strategy: validation
Validate before calling
fields0 := strings.Fields(line)[0]
parts := strings.Split(fields0, "-")
if len(parts) != 2 { return fmt.Errorf("not a maps header: %q", line) }
if _, err := strconv.ParseUint(parts[0], 16, 64); err != nil { return err } Type guard
func looksLikeMapsRange(field string) bool {
v := strings.Split(field, "-")
return len(v) == 2 && isHex(v[0]) && isHex(v[1])
} Try / catch
if err != nil && strings.Contains(err.Error(), "bad first field") {
// skip smaps-style key/value lines and continue parsing the rest
continue
} Prevention
- Filter out 'Key: value' lines (smaps output) before parsing.
- Pre-validate each line with a regex like ^[0-9a-f]+-[0-9a-f]+\s before parsing.
- Use cat /proc/<pid>/maps as the reference format for generated fixtures.
- Avoid parsing maps files captured through logging/mangling layers.
When it happens
Trigger: parseSmapsHeaderLine encountering a line whose fields[0] has no '-' or more than one '-' — e.g. an smaps 'Size: 4 kB' style key/value line fed to the header parser, or a corrupted/foreign maps format.
Common situations: Parsing /proc/pid/smaps or smaps_rollup (which contain 'Key: value' lines) instead of maps; third-party procfs shims with different formatting.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- malformed /proc/pid/maps on line %d: %q (wrong number of fie
- malformed /proc/pid/maps on line %d: %q (%v)
- malformed /proc/pid/maps on line %d: %q (permissions column
- short read
- can not continue execution of core process
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/0111ef5d6b9cee43.
Report an issue: GitHub.