I just learned about .natvis
files in Visual Studio and I've been setting up some for my Ruby C++ Extension project. http://msdn.microsoft.com/en-us/library/jj620914.aspx
However, then I tried to use one of the Ruby macro's in a conditional statement then I get errors:
Natvis: C:\Users\Thomas\Documents\Visual Studio 2013\Visualizers\SUbD.natvis(79,4): Error: identifier "NIL_P" is undefined
Error while evaluating 'NIL_P(value_)' in the context of type 'SUbD.so!SUbD::ruby::Numeric'.
The rule I'm trying is this:
<Type Name="SUbD::ruby::Numeric">
<DisplayString Condition="NIL_P(value_)">Ruby Numeric: Nil</DisplayString>
<DisplayString>Ruby Numeric: {value_}</DisplayString>
</Type>
In my project I am wrapping Ruby's VALUE
type in small C++ wrapper classes for common types such as String
, Hash
, Array
etc. And I've been able to set up natvis rules for these. But whenver I want to use some of the macros from the Ruby system I always get errors.
Is it not possible to use macros in natvis
files?
http://msdn.microsoft.com/en-us/library/jj620914.aspx#BKMK_Expressions_and_formatting
"Natvis expressions are evaluated in the context of the object being visualized, not the current stack frame." The debugger cannot evaluate preprocessor macros, thus is would follow that the visualizer can't either. You would need to 'manually' expand the preprocessor macro for the expression. For example, if NIL_P is defined as:
#define NIL_P(v) !((VALUE)(v) != Qnil)
Then your natvis DisplayString tag would have to be:
<DisplayString Condition="!((VALUE)(value_) != Qnil)">Ruby Numeric: Nil</DisplayString>