user541686
user541686

Reputation: 210745

How to get std::pair<char *, char *> to display as a proper string segment in Visual Studio's debugger?

How do I get std::pair<char *, char *> to display as a proper string segment in Visual Studio, rather than as two pointers to null-terminated strings?

Upvotes: 1

Views: 365

Answers (1)

user541686
user541686

Reputation: 210745

Create %UserProfile%\Documents\Visual Studio 2015\Visualizers\custom.natvis (replace 2015 with your version of Visual Studio, obviously) and then try something like the following:

<?xml version='1.0' encoding='utf-8'?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
  <!-- For more information on how to create debugger visualizers, refer to:
       https://msdn.microsoft.com/en-us/library/jj620914.aspx
       https://msdn.microsoft.com/en-us/library/75w45ekt.aspx
  -->
  <Type Name="std::pair&lt;*,*&gt;">
      <DisplayString Condition="*second - *first &gt;= 0">{first,[second - first]}</DisplayString>
  </Type>
  <Type Name="std::pair&lt;*,*&gt;">
      <DisplayString Condition="*second._Ptr - *first._Ptr &gt;= 0">{first._Ptr,[second._Ptr - first._Ptr]}</DisplayString>
  </Type>
</AutoVisualizer>

Result:

Screenshot

Upvotes: 1

Related Questions