Debugging an OwnedArray

Hi

I am trying to understand how I can see elements hold in an OwnedArray.

I explain:

when digging into let's say, member OwnedArray<AudioPluginFormat> formats (in class AudioPluginFormatManager), I can see that member numUsed = 3. There are 3 elements into the array and I need to see what they are.

So I expand the object into VS Watch section, I can see member data, then elements, then data again, etc etc etc, and I never get to the elements themselves. (see attached picture)

I surely miss something, thanks for your kind help.

 

Nathaniel

will show the arrays contents but is in most cases useless as one often wants to have a look at some members of the element. The following will work in this case but is a bit more cumbersome as you can't easily search through the array:
[code]
ownedArray.data.elements.data[0]->member
ownedArray.data.elements.data[1]->member
[/code]

As a related question: Is it possible to look into Arrays, HeapBlocks and so on in XCode without having to decrypt the memory view?

will show the arrays contents but is in most cases useless as one often wants to have a look at some members of the element. The following will work in this case but is a bit more cumbersome as you can’t easily search through the array:

ownedArray.data.elements.data[0]->member
ownedArray.data.elements.data[1]->member

As a related question: Is it possible to look into Arrays, HeapBlocks and so on in XCode without having to decrypt the memory view?

You can, for example, use the "Add Expression..." feature of the Xcode debugger, which is quite useful for stuff like that.

I have a clear preference on working with VS...

Thanks

Nathaniel

You could create your own debugger extension for VS using autoexp.dat -> https://blogs.msdn.microsoft.com/vcblog/2012/07/12/debugger-type-visualizers-for-c-in-visual-studio-2012/

 

Maybe this is something that could be added to JUCE package?

Sorry to drag this 8 year old subject back to life.
I’ve been using OwnedArray quite a lot recently, and it would be really useful to easily see the individual array elements whilst debugging.

Did anyone make a suitable visualiser script for doing this in Visual Studio?
I can’t make sense of the MS pages on natvis files. Can anyone help please?

Dave H.

You could have a look at the .natvis file in here:

While I don’t think it has the OwnedArray, you can easily expand it to handle it.

1 Like

Thanks Marcel, I’ll take a look.

Oh man, I still can’t get that to work, even with the the standard juce:Array.
I’ve tried adding the file via ‘add existing’, and add new natvis file options. I’ve also added it to the two directories given here:

I can’t believe such a basic idea as debugging container contents would be so weirdly complicated. It should be the primary thing a C++ debugger would do.

If using Cmake:

Or put the file in:
%USERPROFILE%\Documents\Visual Studio 2022\Visualizers

Thanks Adam, no, I don’t use CMake.
I’ve put it in that location again, but no joy. Rebooting did nothing as well.

Perhaps I missed an option somewhere in VS? I’ve even tried add->existing, and adding that Juce.natvis from that location.
VS is not seeing it at all.

image
Try adding in Projucer? Could save some time if you have to rebuild your project at some point too.

Yeah, I’ve tried adding it to the sources. I see you’ve clicked off the Binary Resource checkbox as well. No joy yet, but thanks for the help.
edit I’ve also tried debugging Array and std::vector

If it’s of any help for you, juce.natvis seems to work for me. I have it in two locations

%USERPROFILE%\Documents\Visual Studio 2022\Visualizers
and
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Packages\Debugger\Visualizers

Don’t know which one of those is the active one. They are the same file anyway.
I can send you my actual file if it for any reason is different than yours

Thanks oxxyyd.
It was already in those two locations though. Plus I had it in the source code directory as suggested before.

I believe I’m using the same juce.natvis as everyone else, from that juce-toys github.

I’m not using any extensions, apart from Visual Assist, which I disabled.

Not sure it would help, but you can turn natvis diagnostic output on/off from the Debugging/Output Window section of Options. Maybe it’s finding the file, but having issues using it?

2 Likes

@cpr2323 Great idea. Setting it to verbose gives me a lists of found natvis files. The Juce one is on the list:

Natvis: C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Packages\Debugger\Visualizers*juce.natvis(7,11): Fatal error: DTD is prohibited.*

DTD appears to be a security problem. I’m going to compare it with all the others to see how it differs.

1 Like

I deleted all the links at the top of the file and I’ve just got this:
It now says the parsing is OK…

<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer 
xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">

I don’t get the error now, when I open an Array called ‘gather’ which can contain many objects, in the debugger the output lists this:

Natvis: C:\Users\daveh\Documents\Visual Studio 2022\Visualizers\juce.natvis(6,6): Successfully parsed expression 'values.numUsed == 0' in type context 'juce::Array<Wall *,juce::DummyCriticalSection,0>'.
Natvis: C:\Users\daveh\Documents\Visual Studio 2022\Visualizers\juce.natvis(6,75): Successfully parsed expression 'values.numAllocated' in type context 'juce::Array<Wall *,juce::DummyCriticalSection,0>'.
Natvis: C:\Users\daveh\Documents\Visual Studio 2022\Visualizers\juce.natvis(7,32): Successfully parsed expression 'values.numUsed' in type context 'juce::Array<Wall *,juce::DummyCriticalSection,0>'.
Natvis: C:\Users\daveh\Documents\Visual Studio 2022\Visualizers\juce.natvis(7,47): Successfully parsed expression 'values.numAllocated' in type context 'juce::Array<Wall *,juce::DummyCriticalSection,0>'.
Natvis: C:\Users\daveh\Documents\Visual Studio 2022\Visualizers\juce.natvis(9,32): Successfully parsed expression 'values.numUsed' in type context 'juce::Array<Wall *,juce::DummyCriticalSection,0>'.
Natvis: C:\Users\daveh\Documents\Visual Studio 2022\Visualizers\juce.natvis(11,19): Successfully parsed expression 'values.numUsed' in type context 'juce::Array<Wall *,juce::DummyCriticalSection,0>'.
Natvis: C:\Users\daveh\Documents\Visual Studio 2022\Visualizers\juce.natvis(12,27): Successfully parsed expression 'values.elements.data' in type context 'juce::Array<Wall *,juce::DummyCriticalSection,0>'.

BUT it still doesn’t display anything different in either the debugger or the watch window.

Using a simple int array I get:

The verbose natvis output says values.numUsed == 0’:
I don’t know if that’s significant.

Natvis: C:\Users\daveh\Documents\Visual Studio 2022\Visualizers\juce.natvis(4,6): Successfully parsed expression 'values.numUsed == 0' in type context 'juce::Array<int,juce::DummyCriticalSection,0>'.

Bummer. I get the correct results, but I am using JUCE 7. How about you?
image