MohamedG's Log


Visual GCRoot via DGML

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 –?

!vgcroot [/nostacks] [/do] <Object address> [<DGML output file>]

  /nostacks – Restricts the search to garbage collector handles and freachable objects.
  /do – Collects more data using DumpObj for all the objects in the graph.
  /fields – Shows field names on links for all the objects in the graph if possible (implies /do).
  <Object address> – Address of object to look for.
  <DGML output file> – The DGML output file path, without spaces. (defaults to temp.dgml)

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[]:

Object[] Tooltip

As you can see, I used the –do flag to get the details provided by DumpObj. Hence, a String will show its value:

String Tooltip

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”:

Field Names

Using the powerful Advanced Selection feature, I can select certain nodes based on their properties:

Advanced Selection

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.

Some DGML Features

I hope you find this extension useful, I’ll be blogging about the experience I had developing it, it was fun!

Download: 32-bit | 64-bit