Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

debugging - Visual Studio 2013 C++: STL container's elements display in debugger

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 DocumentsVisual Studio 2013Visualizerscustom.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...