How does Visual Studio 2015 Natvis display a function of a static variable?

I write debugger visualizers using the .natvis file in Microsoft Visual Studio 2015. In my class there is one information that I would like to get, if possible. I am wondering what syntax will be for this variable.

Here is a simplified version of C ++ code:

class MyClass { public: MyClass() {} int getAValue(size_t index) { static std::vector<int> numberVector; if (numberVector.size() <= index) { addSomeNumbersToTheEnd(numberVector); } return numberVector[i]; } } 

In the debugger, I would like to see the size of the vector when I hover over an instance of MyClass, but I do not know how to reference it (or if possible). Here is the Type visualizer, with <what goes here?> In the place where I am having problems:

 <Type Name="MyClass"> <DisplayString>[$(Type)] staticVectorSize={<what goes here?>}</DisplayString> </Type> 

The actual problem is much more complicated, involving a curiously repeating template of the template for creating the best enumeration objects, so do not comment on the futility of this somewhat contrived scenario.

+6
source share
1 answer

If you can force the viewport to specify the value of a static function outside the function, you can use this. However, AFAIK, access to static function variables is permitted only within the function area. Since there is no path to this object, if you do not enter this function, you are SOL.

The workaround is to move the static variable to the class area, then there is a symbolic path to the variable, and you can access it from there.

0
source

All Articles