SOS your Visual Studio


 If you as a developer are interested in taking quick peeks into memory allocation you can load SOS (Son Of Strike) in Visual Studio to do that. SOS is written as a WinDbg extension but can load in Visual Studio and do most of the stuff.


To begin with you will have to go to the Properties of the project and check “Enable unmanaged code debugging” under the Debug options. Once you hit a breakpoint you can load SOS in the Immediate Window (Ctrl+Alt+I). It is similar to working with WinDbg you use the .load command to load the extension.


.load sos


SOS_load


 


Once loaded you can start running standard SOS commands (Use !heap for all SOS commands).


SOS_commands


 


  If you want to switch the thread context you will have to use the Threads Window(Ctrl+Alt+H) All you need to do is double click on the Thread in the Thread Window. You can use the thread ID to match the !threads output to the Threads Window.


SOS_Thread ID


 


A couple of commands like !vmmap will error out in Visual Studio


“Extension is using a feature which Visual Studio does not implement.”


Also note that by default with ASP.NET projects you are debugging the Cassini process. You can also attach to a IIS worker process running your code and break into it.

Bookmark and Share

Comments (4)

  1. Jeff R says:

    Note that you must be attached with "Native" enabled as a debugging type, in addition to "Managed" debugging to load the SOS dll, even if you have built your project with the "allow unmanaged debugging" checkbox selected.

  2. I found this blog post from Shawn Burke to be very useful. Comes in handy if you have to step through

  3. Jialiang says:

    考虑一下如下两个问题:Q1:HowtofindtheliveSqlDataReaderfromaSqlConnectionobject.Q2:HowtofindallS…