go-delve/delve · error · errMapBucketContentsNotArray

malformed map type: keys, values or tophash of a bucket is n

Error message

malformed map type: keys, values or tophash of a bucket is not an array

What it means

errMapBucketContentsNotArray is returned by the map iterator when the DWARF type of a bucket's keys, values, or tophash field is not an array type as the Go runtime defines it. Delve relies on the fixed layout of runtime hmap/bucket structs; any deviation makes bucket iteration impossible and the map is treated as malformed.

Source

Thrown at pkg/proc/mapiter.go:126

	bidx       uint64

	keyTypeIsPtr, elemTypeIsPtr bool

	tophashes *Variable
	keys      *Variable
	values    *Variable
	overflow  *Variable

	maxNumBuckets uint64 // maximum number of buckets to scan

	idx int64

	hashTophashEmptyOne uint64 // Go 1.12 and later has two sentinel tophash values for an empty cell, this is the second one (the first one hashTophashEmptyZero, the same as Go 1.11 and earlier)
	hashMinTopHash      uint64 // minimum value of tophash for a cell that isn't either evacuated or empty
}

var (
	errMapBucketContentsNotArray        = errors.New("malformed map type: keys, values or tophash of a bucket is not an array")
	errMapBucketContentsInconsistentLen = errors.New("malformed map type: inconsistent array length in bucket")
	errMapBucketsNotStruct              = errors.New("malformed map type: buckets, oldbuckets or overflow field not a struct")
)

func (it *mapIteratorClassic) nextBucket() bool {
	if it.overflow != nil && it.overflow.Addr > 0 {
		it.b = it.overflow
	} else {
		it.b = nil

		if it.maxNumBuckets > 0 && it.bidx >= it.maxNumBuckets {
			return false
		}

		for it.bidx < it.numbuckets {
			it.b = it.buckets.clone()
			it.b.Addr += uint64(it.buckets.DwarfType.Size()) * it.bidx

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Upgrade delve to a version supporting your Go version
  2. Rebuild the program with the same Go toolchain delve supports and restart debugging
  3. Check that the variable is a healthy, non-corrupted map (read memory of buckets succeeded)
  4. If the map is known-good, file an issue with delve version + Go version
Defensive patterns

Strategy: type-guard

Validate before calling

// check delve/Go compatibility before debugging
// delve release notes list max supported Go version
if goVersionAfter(delveMaxSupportedGo) { warn("map iteration may fail; update delve") }

Try / catch

m, err := loadMap(v)
if err != nil {
    if errors.Is(err, proc.ErrMapBucketContentsNotArray) || strings.Contains(err.Error(), "not an array") {
        return fmt.Errorf("cannot iterate map (Go/delve version mismatch?): %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Iterating a map whose bucket struct fields were parsed as non-array types (unexpected Go runtime version, incorrect DWARF from the compiler, or corrupted type resolution); calling loadMap/mapAccess on a map from a binary compiled by a very new or very old Go toolchain.

Common situations: Go version newer than the delve release (map internals layout changed); mismatched debug info; debugging optimized or transformed code where types were rewritten.

Understand the failure class

Related errors


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