ASP.NET, Coding

Debugging .NET Application: Using Son of Strike(SOS) Debugging Extension

Son of Strike (SoS) is a debugging extension shipped with .NET Framework(v1.1 onwards) which can be used for advanced debugging and meory profiling. SoS can be loaded into Visual Studio 2005 or to a debugging tools like WinDbg to analyze memory structures and hang/crash details. It gives you an in-depth understanding of .NET memory allocations and CLR data structures.

SoS can be loaded in 2 ways:

  1. By using absolute path of .NET Framework directory
    .load C:WINNTMicrosoft.NETFrameworkv2.0.50727sos.dll
  2. By using relative path of .NET Framework directory
    .loadby sos mscorwks

SoS can be used in 2 ways:

  1. On a running application in the immediate window of Visual Studio 2005.
  2. On crash/hang dumps loaded in a debugging tool such as WinDbg.

SoS has a number of useful commands to analyze memory. Once SoS is loaded, these commands can be run passing suitable parameters.
Useful SoS Commands

  • All the SoS commands start with an exclamation mark [“!”].
  • !Help can be used to get a full list of available SoS commands
  • !Help [Command Name] can be used to get specific details about a single command
  • !Help FAQ gives you the FAQ’s and answers on SoS.

Here is the full list of SoS commands categorized based on functionality:

Command Help

  • Help
  • !Help FAQ

Object Inspection

  • DumpObj (do)
  • DumpArray (da)
  • DumpStackObjects (dso)
  • DumpHeap
  • DumpVC
  • GCRoot
  • ObjSize
  • FinalizeQueue
  • PrintException (pe)
  • TraverseHeap

Examining CLR data structures

  • DumpDomain
  • EEHeap
  • Name2EE
  • SyncBlk
  • DumpMT
  • DumpClass
  • DumpMD
  • Token2EE
  • EEVersion
  • DumpModule
  • ThreadPool
  • DumpAssembly
  • DumpMethodSig
  • DumpRuntimeTypes
  • DumpSig
  • RCWCleanupList
  • DumpIL

Examining code and stacks

  • Threads
  • CLRStack
  • IP2MD
  • U
  • DumpStack
  • EEStack
  • GCInfo
  • EHInfo
  • COMState
  • BPMD

Diagnostic Utilities

  • VerifyHeap
  • DumpLog
  • FindAppDomain
  • SaveModule
  • GCHandles
  • GCHandleLeaks
  • VMMap
  • VMStat
  • ProcInfo
  • StopOnException (soe)
  • MinidumpMode

This link provides detailed description of each of these commands and a couple of examples of how to use them: http://msdn.microsoft.com/en-us/library/bb190764.aspx

To debug an application in production, take the “hang dump” or “crash dump” of the process using ADPlus (ADPlus.vbs) or User Mode Process Dump tool. After that, the dump can be analyzed with a tool like WinDbg. Creating the dump file using ADPlus and analyzing it using WinDbg and SoS will be covered in a separate section.