I blog about debugging, development using .net, C#, SQL, and other Microsoft technologies.
Disclaimer: All posts are provided "AS IS" with no warranties, confering no rights, and expressing only my personal opinion, not Microsoft's.
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. /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!
Download: 32-bit | 64-bit
The digrams are little unclear to see.
Please click the thumbnail to view the enlarged diagram.
Any chance you will publish the source code of your extension?
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.
You rock! I wish I wrote that first :)
where to copy this dll (in the vgcroot.dll)?
I'd copy it to the winext folder in Windbg's setup folder.
so this thing is run within VS 2010 or windbg?
because it errors out in VS 2010.
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, 0x80004001
You need to run it in either windbg or cdb, then open the dgml file in Visual Studio 2010.
We are waiting for the blog with the source code !
Can I use this extension in VS 2008 or Windbg?
You can use it in WinDbg and CDB, but not in VS.
Good work. Is the source code for it available?
Good Stuff, How about chaging the default file name to addr.dgml (i.e. 3db8a70c.dgml)