{"record":{"id":"ef11c86a26879c6f","repo":"go-delve/delve","slug":"wrong-real-type-for-map","errorCode":null,"errorMessage":"wrong real type for map","messagePattern":"wrong real type for map","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/mapiter.go","lineNumber":27,"sourceCode":"\t\"github.com/go-delve/delve/pkg/goversion\"\n)\n\ntype mapIterator interface {\n\tnext() bool\n\tkey() *Variable\n\tvalue() *Variable\n}\n\nfunc (v *Variable) mapIterator(maxNumBuckets uint64) mapIterator {\n\tmt := v.RealType.(*godwarf.MapType)\n\tsv := v.clone()\n\tsv.RealType = godwarf.ResolveTypedef(&(sv.RealType.(*godwarf.MapType).TypedefType))\n\tsv = sv.maybeDereference()\n\tv.Base = sv.Addr\n\n\tmaptype, ok := sv.RealType.(*godwarf.StructType)\n\tif !ok {\n\t\tv.Unreadable = errors.New(\"wrong real type for map\")\n\t\treturn nil\n\t}\n\n\tisptr := func(typ godwarf.Type) bool {\n\t\t_, isptr := typ.(*godwarf.PtrType)\n\t\treturn isptr\n\t}\n\n\tit := &mapIteratorClassic{v: v, bidx: 0, b: nil, idx: 0, maxNumBuckets: maxNumBuckets, keyTypeIsPtr: isptr(mt.KeyType), elemTypeIsPtr: isptr(mt.ElemType)}\n\titswiss := &mapIteratorSwiss{v: v, maxNumGroups: maxNumBuckets, keyTypeIsPtr: isptr(mt.KeyType), elemTypeIsPtr: isptr(mt.ElemType)}\n\n\tif sv.Addr == 0 {\n\t\tit.numbuckets = 0\n\t\treturn it\n\t}\n\n\tv.mem = cacheMemory(v.mem, v.Base, int(v.RealType.Size()))\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/mapiter.go#L9-L45","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// before iterating, confirm the resolved type is a map\nif _, ok := godwarf.ResolveTypedef(v.RealType).(*godwarf.MapType); !ok {\n    return fmt.Errorf(\"variable %s is not a map\", v.Name)\n}","typeGuard":"func isMapType(v *proc.Variable) bool {\n    _, ok := godwarf.ResolveTypedef(&(v.RealType.(*godwarf.MapType).TypedefType)).(*godwarf.MapType)\n    return v.Unreadable == nil && ok\n}","tryCatchPattern":"m, err := evalVariable(scope, expr)\nif err != nil { return err }\nif m.Unreadable != nil {\n    if strings.Contains(m.Unreadable.Error(), \"wrong real type for map\") {\n        return fmt.Errorf(\"%s is not a valid map in this process state\", expr)\n    }\n    return m.Unreadable\n}","preventionTips":["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"],"tags":["go","dwarf","maps","variables"],"backgroundTag":"malformed-map-type","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}