In Visual Studio 2012, I'm looking for a way to customize the default display of floating point types in the Autos, Locals, and Watch windows. I'm familiar with the Native Visualizer (Natvis) utility, but don't see any debugger formatting facilities to accomplish this. Likewise, I'm not aware of any means to override the default display of any primitive types (aside from enabling hex).
The goal would be to create display strings with fewer digits expanded for types corresponding to points, geometric vectors, etc, but still have all the precision show up when I expand the types. So for example I might have a variable of a point type display as (0.000, 1.234, 2.429)
instead of m_x = 0.00000000, m_y = 1.234245213...
in the middle column of the Autos window.
I looked through the format specifiers at this page, but don't see a way to control floating point precision.
The Autos and Locals windows show variable values while you are debugging. The windows are only available during a debugging session.
When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable. If the variable is an object, you can expand the object by clicking on the arrow to see the elements of that object.
Visual Studio Debugging Windows: Watch, Locals, Autos, Immediate, Call Stack and Threads.
Although it doesn't appear to be supported in their documentation, we have used the following definition to shorten the numbers (in VS 2015):
<Type Name="MyVec3d">
<DisplayString>{vectorX,g}, {vectorY,g}, {vectorZ,g}</DisplayString>
</Type>
Unfortunately there is really no way to do this fine grained level of a change in C++ debugging. In a managed language it would be possible in some limited scenarios (when the primitives were fields of objects and annotated with special [DebuggerDisplay]
attributes). For C++ though this type of customization just doesn't exist.
Primitive types cannot currently be NatVizzed. However, if the specific primitives you're wanting to look at are members of another type that you can watch, you can apply formatting to that type, e.g.
<!-- displays the double value as 0.000 -->
<Type Name="DoubleHolder">
<DisplayString>{(int)myDouble}.{(int)(myDouble*1000) % 1000}</DisplayString>
</Type>
Based on Overlord Zurg's answer, display the value of m_x
with three digits as follows:
<Type Name="Point">
<DisplayString>
{(int)m_x}.{(int)(10*m_x) % 10}{(int)(100*m_x) % 10}{(int)(1000*m_x) % 10}
</DisplayString>
</Type>
To account for negative numbers as well:
<Type Name="Point">
<DisplayString>
{(int)m_x}.{(int)((m_x<0?-1:1)*10*m_x) % 10}{(int)((m_x<0?-1:1)*100*m_x) % 10}{(int)((m_x<0?-1:1)*1000*m_x) % 10}
</DisplayString>
</Type>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With