4

I need to use smart pointers for an application which has several hierarchy of classes. One difficulty while debug the code is the view of smart pointers (e.g. unique_ptr) inside the watch windows of Visual Studio 2015. It always shows [ptr], [deleter] and [Raw View]at the same time, while I mostly care about seeing quickly the content of [ptr] when expanding the view for the pointer. Is there a way to make debugging easier and customize the view of displaying the content of smart pointer to become same as raw pointers in visual Studio 2015? I know that this should be doable by using the appropriate NavisFile, however I don't know how should the following NavisFile be modified to show the content of [ptr] ?

<?xml version="1.0" encoding="utf-8"?> 
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"> 

  <Type Name="std::unique_ptr&lt;*&gt;">
      <SmartPointer Usage="Minimal">_Mypair._Myval2</SmartPointer>
      <DisplayString Condition="_Mypair._Myval2 == 0">empty</DisplayString>
      <DisplayString Condition="_Mypair._Myval2 != 0">unique_ptr {*_Mypair._Myval2}</DisplayString>
      <Expand>
          <Item Condition="_Mypair._Myval2 != 0" Name="[ptr]">_Mypair._Myval2</Item>
      </Expand>
  </Type>


</AutoVisualizer> 
0

1 Answer 1

3

I am no expert, but it seems like you could simply remove the <Expand> node, and then change the second <DisplayString> to display just _Mypair._Myval2, eg:

<?xml version="1.0" encoding="utf-8"?> 
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"> 

  <Type Name="std::unique_ptr&lt;*&gt;">
      <SmartPointer Usage="Minimal">_Mypair._Myval2</SmartPointer>
      <DisplayString Condition="_Mypair._Myval2 == 0">empty</DisplayString>
      <DisplayString Condition="_Mypair._Myval2 != 0">_Mypair._Myval2</DisplayString>
  </Type>


</AutoVisualizer>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes this works as you said. Many thanks for your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.