go-delve/delve · error
wrong real type for map
Error message
wrong real type for map
What it means
When loading a map variable, mapIterator resolves the map's real type through typedefs and expects the result to be a godwarf.MapType; after dereferencing the header pointer it expects a struct type. If the underlying type is not the expected struct (e.g. because the value is not actually a map or DWARF info is wrong), the map is marked Unreadable with this error.
Source
Thrown at pkg/proc/mapiter.go:27
"github.com/go-delve/delve/pkg/goversion"
)
type mapIterator interface {
next() bool
key() *Variable
value() *Variable
}
func (v *Variable) mapIterator(maxNumBuckets uint64) mapIterator {
mt := v.RealType.(*godwarf.MapType)
sv := v.clone()
sv.RealType = godwarf.ResolveTypedef(&(sv.RealType.(*godwarf.MapType).TypedefType))
sv = sv.maybeDereference()
v.Base = sv.Addr
maptype, ok := sv.RealType.(*godwarf.StructType)
if !ok {
v.Unreadable = errors.New("wrong real type for map")
return nil
}
isptr := func(typ godwarf.Type) bool {
_, isptr := typ.(*godwarf.PtrType)
return isptr
}
it := &mapIteratorClassic{v: v, bidx: 0, b: nil, idx: 0, maxNumBuckets: maxNumBuckets, keyTypeIsPtr: isptr(mt.KeyType), elemTypeIsPtr: isptr(mt.ElemType)}
itswiss := &mapIteratorSwiss{v: v, maxNumGroups: maxNumBuckets, keyTypeIsPtr: isptr(mt.KeyType), elemTypeIsPtr: isptr(mt.ElemType)}
if sv.Addr == 0 {
it.numbuckets = 0
return it
}
v.mem = cacheMemory(v.mem, v.Base, int(v.RealType.Size()))
View on GitHub (pinned to a23773e6c3)
Solutions
- Rebuild the target binary and restart the debug session so DWARF matches the code
- Check the variable is actually a map at that point (not uninitialized/zeroed memory)
- Verify variable v.Base/sv.Addr reads succeeded (unreadable memory upstream)
- Update delve; older versions mishandle newer Go runtime map types
Defensive patterns
Strategy: type-guard
Validate before calling
// before iterating, confirm the resolved type is a map
if _, ok := godwarf.ResolveTypedef(v.RealType).(*godwarf.MapType); !ok {
return fmt.Errorf("variable %s is not a map", v.Name)
} Type guard
func isMapType(v *proc.Variable) bool {
_, ok := godwarf.ResolveTypedef(&(v.RealType.(*godwarf.MapType).TypedefType)).(*godwarf.MapType)
return v.Unreadable == nil && ok
} Try / catch
m, err := evalVariable(scope, expr)
if err != nil { return err }
if m.Unreadable != nil {
if strings.Contains(m.Unreadable.Error(), "wrong real type for map") {
return fmt.Errorf("%s is not a valid map in this process state", expr)
}
return m.Unreadable
} Prevention
- Keep the debugged binary and delve in sync (rebuild + restart after recompiling)
- Check v.Unreadable before consuming map contents
- Update delve when upgrading the Go toolchain
- Don't force-cast variable types to maps when the declared type differs
When it happens
Trigger: Evaluating a variable whose declared type resolves to a map but whose runtime/DWARF representation does not match (corrupted memory, bad debug info, evaluating a non-map value coerced to map type); calling loadValue/loadMap on a Variable with a wrongly-resolved RealType.
Common situations: Stale or mismatched binaries vs debug info (binary rebuilt without reattaching); reading corrupted memory from a crashed process; compiler/DWARF version quirks where the map header struct differs.
Related errors
- malformed map type: keys, values or tophash of a bucket is n
- malformed map type: inconsistent array length in bucket
- malformed map type: buckets, oldbuckets or overflow field no
- malformed map type
- swiss table type does not have some required fields
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/ef11c86a26879c6f.
Report an issue: GitHub.