Vs 2012 natvis: possible to define class in xml?

1.1k views Asked by At

I am currently trying to create a natvis XML file for a large Project at work. We have a Pointer to a type, which the Debugger knows nothing of (Information hiding with a typedef, it was a stupid idea by the author, but can't be changed at the Moment...).

The original struct is similar to this one (the Debugger knows nothing of These types, he only sees the pointer):

struct INNER_1_t
{
    int* pointerToArray;
    int n;
}

struct INNER_2_t
{
    int v_1;
    int v_2;
}

struct OUTER_t
{        
    /* a lot of other, primitive members ... */
    int lface;

    int *edges; //Array with num_edges members
    int num_edges;

    INNER_1_t *ptr1; //Array with n1 members
    int n1;

    INNER_2_t *ptr2; //Array with n2 items
    int n2;
}

My Goal is to make the members of this struct visible via a natvis XML file. For the normal members, this is easy, with Items and pointer arithmetic. Example:

<Item Name="lface">*((int*)(((char*)this)+92))</Item>

I also know how to define Arrays of known types:

        <Synthetic Name="edge">
            <DisplayString>Edges({*((int*)(((char*)this)+80))})</DisplayString>
            <Expand>
                <ArrayItems>
                    <Size>*((int*)(((char*)this)+80))</Size>
                    <ValuePointer>*((double**)(((char*)this)+76))</ValuePointer>
                </ArrayItems>
            </Expand>
        </Synthetic>

Is there any way to define an Array of an (for the Debugger) UNKNOWN type? Or can i somehow declare the type inside the XML file?

1

There are 1 answers

0
Jay Carlton On

I'm currently experimenting with something similar. If you have access to OUTER_t but not the inner ones, I think one strategy involves declaring Types for INNER_1_t and INNER_2_t, with Items corresponding to the locations you expect the private/invisible fields to be. You need to know the exact offsets and types, and watch out for compiler alignment options. So you won't be creating a whole class from scratch in natvis, but rather faking the display of the opaque types. If the array entries are void pointers, you might be out of luck, but with a typedef you should be able to safely cast to whatever the real type is. You can only customize non-primitive types (with the exception of HRESULT).

FWIW, I learned at https://stackoverflow.com/a/11545420/611672 that you can turn on natvis diagnostics with a registry key at

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config\Debugger]

"EnableNatvisDiagnostics"=dword:00000001

There's also a syntax guide at http://msdn.microsoft.com/en-us/library/vstudio/jj620914.aspx if that helps.

Good luck.