Interrogating ValueTrees while debugging

While debugging I regularly need to figure out information about a particular ValueTree instance, and where it belongs on its hierarchy. toXmlString() tells you about a ValueTree’s children, but not its parents, which what you need to know if you’re trying to locate it.

I’ve probably accumulated and wasted several hours on this over the last few months, so I thought I’d invest some time into this problem, and came up with this quick and dirty solution:

void printVT(ValueTree& vtToPrint)
    auto identifyMe = Identifier("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
    vtToPrint.setProperty(identifyMe, var(), nullptr);
    vtToPrint.removeProperty(identifyMe, nullptr);

As you can see, this function prints out the entire hierarchy, with the identifier “xxxxxxxxxxxx” attached to the one you’re trying to find. Very useful!

Of course this might have unintended consequences if it notifies listeners to the change in properties. I guess you could exclude them, but in any case this is only intended for quick debugging scenarios.

Does anyone have any other tips for interrogating ValueTrees?

If you are using VisualStudio you can install the juce-natvis debugger extensions, that will allow you to easily view your ValueTrees in the debugger. I’m not the original author, but I have updated them to work with the latest JUCE.


Awesome! How did I not know about this?

I’ve got the NatVis file working. For ComponentDebugger and ValueTreeDebugger etc, what is the best way to add them to my Visual Studio project? Do I just copy the new folders into the main project folder and then add them to .gitignore? (I’m very timid about editing project files, because I don’t understand them and have broken them before).

Yay! :slight_smile:

I actually don’t know about the *Debugger classes. I have just been using the natvis. I submitted a pull request to the author of the library, but he hasn’t pulled my changes yet, so I’ve been pointing people to my fork.