the swine
the swine

Reputation: 11031

Class member decoration for Visual Studio debugger

When debugging C++ code in Visual Studio, mouseover over a variable shows its value. If the variable is a structure, its members are shown in a table. If the variable is a class with inheritance, the inherited members are grouped in a treeview, and it is all getting messy. Sometimes (e.g. with matrix objects in Eigen library) one needs to open several tree nodes before even seeing any values.

However, mouseover over a STL container yields a nice clean view of the number of elements (which is not even a member variable) and their values in a list.

If I wanted to write my own container class, is there a way to somehow decorate its members (in the source code) for the debugger to display in a way that would be easier to read, or is this functionality hardcoded in VS IDE binaries?

I found this article, but that requires modification of some of IDE files, which is not what I would prefer. I would like anyone running my code to be able to see the value preview as intended, without having to modify their VS files.

Upvotes: 2

Views: 101

Answers (1)

Joey Hammer
Joey Hammer

Reputation: 76

Starting in VS2012, a new way to create native visualizers was introduced by way of *.natvis files. These files are XML and can be added to the Visual Studio projects folder in My Documents directory.

This article describes how to solve your problem of cleaning up the deep nesting into a cleaner format: https://msdn.microsoft.com/en-us/library/jj620914.aspx

Previous to VS2012, you either had to modify the cryptic autoexp.dat file in the Visual Studio installation directory, or write a custom AddIn.

Upvotes: 1

Related Questions