javaLover javaLover - 1 year ago 44
C++ Question

Display void* (array) with known type and length in debugger automatically

Assume that type

and length
is known,
how to display array
in debugger gracefully?

template<class T>class Container{
void* data; //<-- display it!
int size;

In watch windows (Visual studio 2015), I can display
by typing:-


Question: Are they any technique (especially modify code in
) to make this process to be automatic and elegant - like std::vector?

In other words, it would be nice if I can just type
, then the watch will show :-

+data (the + button, can click to expand)
--data[0] (expanded)

My best clue is to use
, but I am not sure.

Answer Source

VS2015 allows debug visualization customization via custom .natvis configuration.

Among the other features it has support for the templated classes. The Name attribute of the Type element accepts an asterisk * as a wildcard character that can be used for templated class names. To refer template parameter in the visualization entry you can use $T1 macros. Examples are located in VS2015 Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers folder.