3

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?

jonrsharpe
123k30 gold badges277 silver badges488 bronze badges
asked Nov 5 at 12:24
2
  • 1
    The schema is published here. Commented Nov 5 at 17:38
  • 1
    Also consider studying windows.natvis (in the same folder you placed your visualizer). It provides a visualizer for SAFEARRAY/tagSAFEARRAY that 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. Commented Nov 6 at 11:29

1 Answer 1

3

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.

answered Nov 5 at 15:54
Sign up to request clarification or add additional context in comments.

2 Comments

Also note that you can enable visualizer debugging under tools -> options, Debugging -> Output window. Errors in the visualizer schema will then be related as encountered.
Your answer, combined with the natvis schema link, provided by your colleague "stackoverflow.com/users/1889329/iinspectable" (iinspectabe), solves my question. Thanks.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.