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[]:
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!
Comments
Anonymous
March 01, 2010
The digrams are little unclear to see.Anonymous
March 02, 2010
Please click the thumbnail to view the enlarged diagram.Anonymous
March 03, 2010
Any chance you will publish the source code of your extension?Anonymous
March 03, 2010
Yes, very soon I'll be blogging on how to write an extension using this one as an example, and I'll attach the source code along with the post.Anonymous
March 28, 2010
Ooo man! You rock! I wish I wrote that first :)Anonymous
March 29, 2010
Thanks Martin!Anonymous
June 08, 2010
where to copy this dll (in the vgcroot.dll)?Anonymous
June 08, 2010
I'd copy it to the winext folder in Windbg's setup folder.Anonymous
June 10, 2010
so this thing is run within VS 2010 or windbg? because it errors out in VS 2010. !vgcroot Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: IDebugClient asked for unimplemented interface Error during command: Warning. Extension is using a callback which Visual Studio does not implement. ERROR: Unable to query interfaces, 0x80004001Anonymous
June 10, 2010
You need to run it in either windbg or cdb, then open the dgml file in Visual Studio 2010.Anonymous
June 15, 2010
We are waiting for the blog with the source code !Anonymous
April 26, 2011
Can I use this extension in VS 2008 or Windbg?Anonymous
April 27, 2011
You can use it in WinDbg and CDB, but not in VS.Anonymous
June 24, 2011
Good work. Is the source code for it available?Anonymous
February 14, 2012
Good Stuff, How about chaging the default file name to addr.dgml (i.e. 3db8a70c.dgml)Anonymous
May 31, 2012
Marvelous !!Anonymous
May 01, 2013
Excellent post!! Can you guide me how to run your extension in windbg.exe as i'm new to using windbg? Any help on the same would be greatly appreciated!!. Thanks in advance.Anonymous
May 04, 2013
Thanks Shilpa, you should copy vgcroot.dll to the winext folder where windbg is installed and run: .load vgcroot Then you can run !help vgcroot for detailed help.