I was inspired by Lovett‘s post about Visualizing Runtime Object Graphs to create my first debugger extension that takes the output of !gcroot and creates a graph that one can interact with easily in Visual Studio 2010.
So, what does my extension do?
!vgcroot [/nostacks] [/do] <Object address> [<DGML output file>]
/nostacks – Restricts the search to garbage collector handles and freachable objects.
Runs GCRoot which looks for references (or roots) to an object, then visualizes its output into a DGML file.
While the textual output of !gcroot is hard to follow, looking at the output of !vgcroot makes it easier to follow roots and use the powerful features of DGML. Here’s an example:
Tooltips show detailed information about the object, like this Object:
As you can see, I used the –do flag to get the details provided by DumpObj. Hence, a String will show its value:
The next cool feature was suggested by Tess Ferrandez (thanks Tess!). You can specify /fields to show the member variable name (the field name) under which the object is referenced, for example, the selected object below is referenced by the “ui” field in “Program” and by the “_target” field in “UserPreferenceChangedEventHandler”:
Using the powerful Advanced Selection feature, I can select certain nodes based on their properties:
The features of DGML are endless, to name a few: you can follow links, search within the graph, assign a legend to a set of nodes based on a criterion, change the layout of the graph (top-to-bottom and vice-versa; right-to-left and vice-versa; and quick clusters), you can create a dependency matrix, create groups and add nodes and/or other groups to them, analyze the graph to find circular references, hubs, unreferenced nodes, etc.
I hope you find this extension useful, I’ll be blogging about the experience I had developing it, it was fun!