12

MSVS 2013 during C++ debugging (Autos and Watch windows) shows only size of STL container's:

MSVS 2010: "[9](9,8,7,6,5,4,3,2,1)"
MSVS 2013: "{ size=9 }"

Line expand is required to see element's value in MSVS 2013.
Is there any way to make MSVS 2013 show STL containers like MSVS 2010 in debugger?
I tried to remove stl.natvis (it is used in 2013), but it doesn't help: autoexp.dat is still not used.
Is possible to force MSVS 2013 use autoexp.dat?
Is it possible to modify stl.natvis scripts (construct DisplayString from container element's values)?
Any other way?

DmitriyH
  • 420
  • 4
  • 15
  • 1
    It seems you can modify the files: http://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2 – cageman Dec 28 '13 at 21:47
  • autoexp.dat is no longer used since VS2012. You have to use .natvis files. See the link @user3125562 gave for instructions. Don't forget to save a copy of the original file! – Sjoerd Dec 29 '13 at 03:07
  • Yes, the file can be modified, but I could not understand from the article, how to construct **DisplayString** from element's values. – DmitriyH Dec 29 '13 at 08:34
  • boost also has its own visualisers, maybe those can be of help? or try looking for other examples. Else explain where you are and what goes wrong. – cageman Dec 29 '13 at 09:43
  • @user3125562, i found boost visualizers package (C++ Debugger Visualizers for VS2012/VS2013), but each record inside boost*.natvis files also shows only container size in **DisplayString**. So, the question "how to put all elements values in **DisplayString** in *.natvis?" is still without answer.. – DmitriyH Dec 30 '13 at 05:38
  • There is a suggestion [here](http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/5160933-c-edit-and-continue-in-the-new-debug-engine) at MS that is a way of asking MS to get off their a** and fix the problem. Vote for it if you want this to be fixed in the next release. – Adrian Jul 02 '14 at 22:12

4 Answers4

7

As a partial solution you can add multiple conditional DisplayString elements to each container type's information in a .natvis file.

The limitation to this is that you can specify that elements only up to some fixed maximum be displayed in the DisplayString debugger output (however, all elements are still displayed in the expansion area that you get when clicking on the variable's + sign in the debugger display).

As an example, drop this into a file named %USERPROFILE%\My Documents\Visual Studio 2013\Visualizers\custom.stl.natvis:

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

<Type Name="std::vector&lt;*&gt;">
    <DisplayString Condition="(_Mylast - _Myfirst) >  3">[{_Mylast - _Myfirst}] ({_Myfirst[0]}, {_Myfirst[1]}, {_Myfirst[2]}, ...)</DisplayString>
    <DisplayString Condition="(_Mylast - _Myfirst) == 3">[{_Mylast - _Myfirst}] ({_Myfirst[0]}, {_Myfirst[1]}, {_Myfirst[2]})</DisplayString>
    <DisplayString Condition="(_Mylast - _Myfirst) == 2">[{_Mylast - _Myfirst}] ({_Myfirst[0]}, {_Myfirst[1]})</DisplayString>
    <DisplayString Condition="(_Mylast - _Myfirst) == 1">[{_Mylast - _Myfirst}] ({_Myfirst[0]})</DisplayString>
    <DisplayString>{{ size={_Mylast - _Myfirst} }}</DisplayString>
    <Expand>
        <Item Name="[size]">_Mylast - _Myfirst</Item>
        <Item Name="[capacity]">_Myend - _Myfirst</Item>
        <ArrayItems>
            <Size>_Mylast - _Myfirst</Size>
            <ValuePointer>_Myfirst</ValuePointer>
        </ArrayItems>
    </Expand>
</Type>

</AutoVisualizer>

And in your next VS2013 C++ debug session vectors will show up to the first three elements in the debugger's DisplayString output in a format similar to the old autoexp.dat display.

You can make the obvious additional edits to the custom natvis to display more than 3 elements. Unfortunately, you'll need to do something similar for each container type you want displayed this way; probably a good job for an intern.

Michael Burr
  • 333,147
  • 50
  • 533
  • 760
  • Thanks for the answer! I will use it, if don't find any other way. But three elements is too few, special script will be required to generate custom.stl.natvis capable to display 1..32 elements :) – DmitriyH Dec 30 '13 at 08:43
  • I agree that three elements is too few; it was just to demonstrate the idea. I also agree that doing this for a reasonable number of elements and a reasonable set of containers will be tedious. Fortunately it only needs to be done once, though it'll probably need tweaks/fixes for different versions of VS. – Michael Burr Dec 30 '13 at 08:50
2

I found one way to force MSVS 2012/2013 use autoexp.dat: set "Enable Edit And Continue" and "Enable Native Edit and Continue".
It disables "data viewing enhancements" (natvis) for C++, and elements of std::vector (std::list, std::map, ...) become displayed on the main line of the variable (MSVS 2010 style).
But, it still would be interesting, is it possible to modify stl.natvis to get the same display result?

DmitriyH
  • 420
  • 4
  • 15
  • 2
    IMO natvis is a huge regression (among others in Vs2012/13). The very idea to use xml for things that are full of &, < and > is ridiculous. I guess somebody got XML-poisoned at Microsoft. – Pavel P Feb 28 '14 at 20:02
  • By the way, I hope I'll be able to make my autoexp.dat working using your suggestion, otherwise I'm still sticking with vs2008 – Pavel P Feb 28 '14 at 20:04
  • There is a suggestion [here](http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/5160933-c-edit-and-continue-in-the-new-debug-engine) at MS that is a way of asking MS to get off their a** and fix the problem. Vote for it if you want this to be fixed in the next release. – Adrian Jul 02 '14 at 22:14
  • I tried this with Visual Studio 2013 Community and it didn't work, ie. it didn't use the autoexp.dat file. :-( – martinako Apr 13 '15 at 17:42
1

FYI, to use autoexp.dat in VS2015 set "Use Native Compatibility Mode" under

Options > Debugging > General

Robert
  • 5,278
  • 43
  • 65
  • 115
Chris81
  • 41
  • 3
1

Uncheck "Show raw structure of objects in variables windows" in Options > Debugging > General.

0xFE
  • 344
  • 5
  • 17