Page 1 of 1

Visual Studio 2005 CMap and CArray Debugging Tips

Posted: Wed Aug 20 2008
by Devteam
If you use Visual C++ and have always been frustrated when debugging CMap and CArray variables then keep on reading, otherwise you can safely skip this post (Also this tip is just for VC2005 and does not apply to VC6.)

If you add a CMap or CArray variable into the debugger VC2005, all you get is the raw data structure of these containers, namely raw pointers, buckets, raw hash tables... Not very useful info for debugging! To get around this limitation you can edit the file "autoexp.dat" found in:
\Program Files\Microsoft Visual Studio 8\Common7\Packages\Debugger
and add support to any type (even custom types/classes defined by yourself), e.g.:

Code: Select all

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

Important: You have to disable a debugger setting found at : Tools->Options->Debugging->General which is "Show raw structure of objects in variables windows."This setting has to be disabled in order for the debugger to parse the "autoexp.dat". However, you can turn it on again in case you need the raw structure and memory location for something specific...