I'm working with COM objects, which means I need to debug SAFEARRAY objects.
It looks as follows in the watch-window:
receivedData 0x007cc980 safearray of UI1, [rank]=1 _variant_t
safearray 0x007cc980 safearray of UI1, [rank]=1 tagSAFEARRAY*
[0] 55 '7' unsigned char
[1] 48 '0' unsigned char
...
I would like it to look as follows:
receivedData 0x007cc980 safearray of UI1, [rank]=1 _variant_t
safearray 0x007cc980 safearray. ILbound=0, cElements=19, array=[55 '7', 48 '0', ...] tagSAFEARRAY*
In order to achieve this, I have created a SAFEARRAY.natvis file, which looks as follows:
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="tagSAFEARRAY">
<DisplayString>
0x{address} safearray. ILbound={ILbound[0]}, cElements={cElements}, array=[{Items}]
</DisplayString>
<Expand> <!-- Customize how each element is displayed -->
<Item Name="Items">
<ArrayItems> <!-- Assuming the array is of type UI1 (unsigned 8-bit integer) -->
<ItemExpression>data[0]</ItemExpression>
</ArrayItems>
</Item>
</Expand>
<Expand>
<Item Name="ILbound">
<ArrayItems>
<ItemExpression>rgsabound[0].lLbound</ItemExpression> <!-- Adjust if necessary -->
</ArrayItems>
</Item>
</Expand>
<Expand>
<Item Name="cElements">
<ArrayItems>
<ItemExpression>cElements</ItemExpression>
</ArrayItems>
</Item>
</Expand>
</Type>
</AutoVisualizer>
Now I'd like to test this.
I have put the mentioned file in one of the required directories and I've launched .natvisreload. In my output window, I see the following error message:
Natvis: C:\Program Files\Microsoft Visual Studio2022円\Professional\Common7\
Packages\Debugger\Visualizers\SAFEARRAY.natvis(10,21):
Fatal error:
Element '{http://schemas.microsoft.com/vstudio/debugger/natvis/2010}ArrayItems'
is unexpected according to content model of parent element
'{http://schemas.microsoft.com/vstudio/debugger/natvis/2010}Item'.
Where can I find a schema/DTD for creating native visualisers? I know it's embedded into the executable of Visual Studio but in a world of sharing knowledge, there must be a copy of this document somewhere. Can anybody show me such a schema/DTD?
1 Answer 1
ArrayItems doesn't belong inside an Item. It should be at the same level (under Expand) as any Items you may have.
If you're trying to flatten the hierarchy, then I think you'll need ExpandedItem. If you're trying to create an extra level, see Synthetic.
The links above jump into the Microsoft reference for creating C++ visualizers. It seems a rather complete description of the XML scheme.
2 Comments
Explore related questions
See similar questions with these tags.
SAFEARRAY/tagSAFEARRAYthat can serve as a starting point for customization. I don't know how Visual Studio's debugger prioritizes which visualizer to use in case there is more than one for a particular type.