Loading and using SOS from within Visual Studio
Posted by: Eran Sandler, in Managed Debugging, SOS, Visual StudioDid you know that you can use SOS from within Visual Studio 2005, not just from WinDbg?
It has been previously discussed in a couple of places but most people don’t know it is possible to do that.
“Why should I use the SOS extension from within Visual Studio?”, you are probably asking.
The answer is quite simple.
Visual Studio is a rich debugger that shows us most of the information we want to know but it doesn’t show us a few important things like the actual size of an object and all of its references and who is referencing our object. While these things are not straight forward in Visual Studio, they are very easy to accomplish in SOS. For example, you can run the following command in SOS:
- !objsize - to find out the actual size of the object and all of its referenced objects
- !gcroot - to find who is referencing our object
- !dumpheap - to see what’s all the stuff that we have on the heap. By using the -gen [generation number] parameter with !dumpheap, we can see all the objects that are currently in that generation
- !SyncBlk - find out which managed locks are locked at the moment (I’ve talked about it before)
So, how do we actually do that?
Well, the first thing you need to do is enable “unmanaged debugging” by going to the “Project Properties” -> “Debugging” -> “Enable Unmanaged Debugging”.
After doing that, you can stop somewhere in your program, open the “Immediate” window (Debug -> Windows -> Immediate) and type:
.load sos
This will load the SOS extension. From there on you have most of the commands of the SOS extension at your disposal.
You might need to set the symbols path by calling .sympath, just like you would do in WinDbg.
An added bonus to this whole thing is that it also works on Visual Studio 2003, so you get to use it even with .NET Framework 1.1.








Entries (RSS)
November 26th, 2006 at 1:39 am
Can this be done with VS 2003 too?
November 26th, 2006 at 9:33 am
Yes. You can use SOS with Visual Studio 2003.
Just make sure that when you load the SOS DLL you are either using the one supplied with the .NET Framework (v1.1 of course) or the one that comes in any of the versions of WinDbg (which usually contains bug fixes and additional functionality).
January 11th, 2007 at 7:50 pm
[...] He also shows how to load our favorite WinDbg Extension - SOS - into Visual Studio and use it while debugging as well as use Reflector to disassemble the framework’s code into readable C# or VB.NET code. I also briefly talked about loading SOS into Visual Studio a while back and mentioned the use of Reflector all over the place (because its such a great and useful utility!). [...]
January 3rd, 2008 at 7:04 pm
[...] located at Microsoft.NETFrameworkv2.0.50727 with either Visual Studio (as I’ve explained on this post) or with [...]