Visual Studio 2005 CMap and CArray Debugging Tips

Amyuni's Development Team would like to share with fellow developers general information about Windows and Web development. These are issues encountered by Amyuni's team and were either solved or pending solution.
Post Reply
Devteam
Posts: 115
Joined: Fri Oct 14 2005
Location: Montreal
Contact:

Visual Studio 2005 CMap and CArray Debugging Tips

Post by Devteam » Wed Aug 20 2008

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...
Amyuni Development Team

Efficient and accurate conversion to PDF, XPS, PDF/A and more. Free trials at - http://www.amyuni.com

Post Reply