Christophe
Christophe

Reputation: 165

Visual Studio .natvis file, array of class visualization

I have classes that basically look like the following and I would like to make then more readable in Visual Debugger:

template <typename T, precision P = defaultp>
struct tvec4
{
    T x, y, z, w;
};

template <typename T, precision P = defaultp>
struct tmat4x4
{
    typedef tvec4<T, P> col_type;

private:
    col_type value[4];
};

Here is what the natvis file looks like for the vector:

<Type Name="glm::tvec4&lt;*&gt;">
    <DisplayString>{x}, {y}, {z}, {w}</DisplayString>
    <Expand>
        <Item Name="x">x</Item>
        <Item Name="y">y</Item>
        <Item Name="z">z</Item>
        <Item Name="w">w</Item>
    </Expand>
</Type>

Which work fine. However, for the matrix class, I can't manage to get anything to work.

Try1:

<Type Name="glm::tmat4&lt;*&gt;">
    <DisplayString>{{value[0]}, {value[1]}, {value[2]}, {value[3]}}</DisplayString>
    <Expand>
        <Item Name="[0]">value[0]</Item>
        <Item Name="[1]">value[1]</Item>
        <Item Name="[2]">value[2]</Item>
        <Item Name="[3]">value[3]</Item>
    </Expand>
</Type>

Try2:

<Type Name="glm::tmat4&lt;*&gt;">
    <DisplayString>{size = {4 x 4}}</DisplayString>
    <Expand>
        <Item Name="[size]">4</Item>
        <Item Name="[capacity]">4</Item>
        <ArrayItems>
            <Size>4</Size>
            <ValuePointer>value</ValuePointer>
        </ArrayItems>
    </Expand>
</Type>

Any idea what am I doing wrong?

Thanks! Christophe

Upvotes: 1

Views: 1774

Answers (2)

Ewan
Ewan

Reputation: 1

This is an old question so I'm assuming you have a solution by now but just in case anyone else has a similar problem it is down to your use of curly braces in the description:

<DisplayString>{{value[0]}, {value[1]}, {value[2]}, {value[3]}}</DisplayString>

A single brace {} indicates that the contents should be interpreted by the debugger but if you actually want the brace as part of the description then you need to use double braces:

{{Text here {variable_name_here}}}

So in your case that would make the correct display string:

<DisplayString>{{{value[0]}, {value[1]}, {value[2]}, {value[3]}}}</DisplayString>

Upvotes: 0

CsorvaGep
CsorvaGep

Reputation: 75

You should try switching the diagnostics on. It is explained here: https://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2

Create the registry key below:

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config\Debugger]
   "EnableNatvisDiagnostics"=dword:00000001

Upvotes: 1

Related Questions