go-delve/delve · error

malformed map type

Error message

malformed map type

What it means

During classic map iteration, nextBucket loads the tophash, keys, values and overflow fields of a bucket and sanity-checks them. If any is nil the variable is marked Unreadable with a generic 'malformed map type' error, and if any of tophash/keys/values is not a reflect.Array the more specific errMapBucketContentsNotArray is used. It means Delve could not reconstruct a valid bucket from the process memory/DWARF type.

Source

Thrown at pkg/proc/mapiter.go:218

			it.v.Unreadable = field.Unreadable
			return false
		}

		switch f.Name {
		case "tophash": // +rtype -fieldof bmap [8]uint8
			it.tophashes = field
		case "keys":
			it.keys = field
		case "values":
			it.values = field
		case "overflow":
			it.overflow = field.maybeDereference()
		}
	}

	// sanity checks
	if it.tophashes == nil || it.keys == nil || it.values == nil || it.overflow == nil {
		it.v.Unreadable = errors.New("malformed map type")
		return false
	}

	if it.tophashes.Kind != reflect.Array || it.keys.Kind != reflect.Array || it.values.Kind != reflect.Array {
		it.v.Unreadable = errMapBucketContentsNotArray
		return false
	}

	if it.tophashes.Len != it.keys.Len {
		it.v.Unreadable = errMapBucketContentsInconsistentLen
		return false
	}

	if it.values.fieldType.Size() > 0 && it.tophashes.Len != it.values.Len {
		// if the type of the value is zero-sized (i.e. struct{}) then the values
		// array's length is zero.
		it.v.Unreadable = errMapBucketContentsInconsistentLen
		return false

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Upgrade Delve to match the Go version of the target binary
  2. Re-check target memory readability (for core dumps verify the file is complete and matches the binary)
  3. Rebuild the binary with full debug info and retry the map evaluation
Defensive patterns

Strategy: fallback

Try / catch

// Evaluate the map defensively and surface the Unreadable flag instead of panicking:
v, err := evalMap(expr)
if err != nil { return err }
if v.Unreadable != nil {
    log.Printf("map unreadable: %v (Go/Delve version mismatch likely)", v.Unreadable)
    return fallbackPrintHeaderOnly(v)
}

Prevention

When it happens

Trigger: Calling next() on a mapIterator (i.e. printing or ranging a map) when a bucket's tophash, keys, values or overflow field loads as nil from target memory — e.g. unreadable memory, an all-zero bucket pointer, or a type layout mismatch.

Common situations: Printing a map in a core dump or a process with partially unreadable memory; Go runtime version whose bucket struct differs from Delve's expectation; corrupted or truncated DWARF for the runtime map types.

Understand the failure class

Related errors


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