Natvis Floating Point Format

Yesterday I discovered the MSVC Natvis tool , which allows you to debug a debugger to present your types in an intelligent way. I quickly started overcoming my math library.

This is what my 3 * 3 matrix class (uninitialized data) looks like:

matrix 3x3

Great, right? My day did not spare.

However, now we turn to a slightly more complicated case:

matrix 4x4

As you can see, the numbers are not aligned. I realized that way a nasty scream to get negative numbers, to align them with positive numbers, but my method has nothing to do with this (here is my basic plan):

<Type ...> <DisplayString>...</DisplayString> <Expand ...> <Synthetic ...> <DisplayString ...>...</DisplayString> </Synthetic> ... </Expand> </Type> 

What happens is that the number of numbers printed varies from number to number.

So my question is: Can I configure Natvis to print a well-defined number of digits for debugging? Alternatively, maybe you have a smart solution?


PS: I will be happy to download a Python script that generates a .natvis file for the y'all game for your own types if I get this working. sub>

+4
source share
1 answer

In case you are still interested: an unpleasant workaround is to compute each digit after the dot on natvis and provide an auxiliary type that you can assign to your POD data type:

First, you inject a simple structure into your source code, which simply contains a float or double member in your code. This allows you to assign a float value to NATVIS_FLOAT and access the number.

 struct NATVIS_FLOAT { float f;} 

Now you can create a visualizer for the type NATVIS_FLOAT, where you define each digit after the precision point that you want to display, for example. 4:

 <Type Name="NATVIS_FLOAT"> <DisplayString>{(int)f}.{((int)(f*10))%10}{((int)(f*100))%10}{((int)(f*1000))%10}{((int)(f*10000))%10}</DisplayString> </Type> 

Finally, you can drop your floating-point members of the matrix in NATVIS_FLOAT. If your matrix has a member float m [9], you can visualize one record, for example

 {(NATVIS_FLOAT*)&m[2],na} 
+3
source

All Articles