Visualizing MFC Containers in autoexp.dat

MFC containers are more or less officially deprecated in favor of STL. Even so, when navigating in legacy code the need often arises to watch CArrays, CLists, CMaps and the like. autoexp.dat provides only STL visualizers out of the box, but you can just paste the lines below into autoexp’s [Visualizer] section, and have a similar debugging experience with MFC code:

[Visualizer]
; This section contains visualizers for STL and ATL containers
; DO NOT MODIFY     (HAAAAAAAAA. -o.s.)

...

;---------------------------------------------------------------------
;  MFC Types
;---------------------------------------------------------------------
CArray<*,*> |CObArray|CByteArray|CDWordArray|CPtrArray|CStringArray|CWordArray|CUIntArray|CTypedPtrArray<*,*>{
 preview([$c,!])
 children(
            #(
              #array (
                  expr: $c.m_pData[$i],
                  size: $c.m_nSize
                     )
             )
         )
}

CList<*,*>|CObList|CPtrList|CStringList|CTypedPtrList<*,*>{
 preview([$c,!])
 children(
          #(
              #list  (
                  head: $c.m_pNodeHead,
                  next: pNext
                     ) : $e.data
               )
            )
}

CMap<*,*,*,*>::CAssoc|CMapPtrToWord::CAssoc|CMapPtrToPtr::CAssoc|CMapStringToOb::CAssoc|CMapStringToPtr::CAssoc|CMapStringToString::CAssoc|CMapWordToOb::CAssoc|CMapWordToPtr::CAssoc|CTypedPtrMap<*,*,*>::CAssoc{
preview(#("key= ",$e.key,", value= ", $e.value))
}

CMap<*,*,*,*>|CMapPtrToWord|CMapPtrToPtr|CMapStringToOb|CMapStringToPtr|CMapStringToString|CMapWordToOb|CMapWordToPtr|CTypedPtrMap<*,*,*>{
children (
    #(
        #if ($c.m_nHashTableSize >= 0 && $c.m_nHashTableSize <= 65535) (
            #array (
                expr : ($c.m_pHashTable)[$i],
                size : $c.m_nHashTableSize
                   ) : #list(
                             head : $e,
                             next : pNext
                            ) : $e
            ) #else (
             #(  __ERROR – Hash table too large!!!__: 1,Table size: $c.m_nHashTableSize)
         )
       )
)
}

[EDIT: CAssoc visualizer fix, thanks to @Gerald].

[EDIT: CMap visualizer fix, thanks to @avek]

Here’s what you’d get:

I’m aware of the formatting issues in the snippet above, but the autoexp parser is notoriously fragile and I didn’t want to risk extra spaces for proper line-wrapping.

And btw, unlike Avery (the original autoexp Jedi), I prefer to avoid cluttering the visualizers with ‘raw’ watch entries.  If you ever need to watch into, say, raw members of a CList, just postfix the variable with ‘,!’ , as in: