15

How does Visual Studio show the elements of a vector, or the characters of a string, in C++? Is there a way for me to make it show my own classes in a custom way?

user541686
  • 205,094
  • 128
  • 528
  • 886
  • Also see [Boost 1.54 multiprecision visualizer](http://www.boost.org/doc/libs/1_54_0/libs/multiprecision/doc/html/boost_multiprecision/tut/misc/visualizers.html). It adds entries to `autoexp.dat`. – jww Feb 02 '18 at 01:11

3 Answers3

16

http://msdn.microsoft.com/en-us/library/zf0e8s14(v=VS.100).aspx

For native code, you can add custom data type expansions to the file autoexp.dat, which is located in the Program Files\Microsoft Visual Studio 10.0\Common7\Packages\Debugger directory. Instructions on how to write autoexp rules are located in the file itself.

For this class:

template<class T>
struct  auto_array {
     T* data;
     int Len;
};

the autoexp.data might look like:

auto_array<*> {
    children
    (
        #array
        (
            expr :      $e.Data[$i],
            size :      $e.Len
        )
    )
    preview
    (
        #(
            "[", $e.Len , "](",
            #array
            (
                expr :  $e.Data[$i],
                size :  $e.Len
            ),
            ")"
        )
    )
}

KindDragon reports that Visual Studio 2012 uses a new file format: natvis

Community
  • 1
  • 1
Mooing Duck
  • 64,318
  • 19
  • 100
  • 158
  • 6
    Visual Studio 2012 uses a new file format natvis http://blogs.msdn.com/b/vcblog/archive/2012/07/12/10329460.aspx – KindDragon Aug 10 '12 at 10:40
5

You can add visualizers for custom C++ types to the autoexp.dat file. The format used in the file and the location change from version to version of Visual Studio but if you Google for autoexp.dat you should find some examples of how to customize it.

mattnewport
  • 13,728
  • 2
  • 35
  • 39
2

For VS2017/2015, use Natvis visualizations to Create custom views of native objects in the Visual Studio debugger.

zwcloud
  • 4,546
  • 3
  • 40
  • 69