Visual Studio 2013 – Visualizers

One of very useful feature of Visual Studio is custom variables views. It’s possible to configure own views to each of your class. For this, VS2013 (and VS2012) uses .natvis files located in following directories:

%VSINSTALLDIR%\Common7\Packages\Debugger\Visualizers
%USERPROFILE%\My Documents\Visual Studio 2013\Visualizers

Files are stored in common .xml format and has following format:

<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
  <Type Name="String::CStringHolder&lt;String::string_trait&lt;char&gt; &gt;">
    <DisplayString>{m_pszData,s8}</DisplayString>
    <StringView>m_pszData</StringView>
    <Expand>
      <Item Name="[m_pszData]">m_pszData</Item>
      <Item Name="[nDataLength]">m_pStringData->nDataLength</Item>
      <Item Name="[nAllocLength]">m_pStringData->nAllocLength</Item>
      <Item Name="[nRefs]">m_pStringData->nRefs</Item>
    </Expand>
  </Type>
</AutoVisualizer>

Debugging .natvis files

Visual studio contains a way how to catch syntax and logical errors in natvis format. All warnings/errors can be displayed to Visual Studio output panel by specifying following registry key to “1”.

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\Debugger
"EnableNatvisDiagnostics"=dword:00000001

Note: It’s necessary to restart Visual studio to turn on this feature

Other usefull links