View Internal CLR Details using the .NET SOS Debugger Extension
Posted by: Suprotim Agarwal
in Category .NET Framework
Abstract: In this article, we will explore some SOS Debugger Extensions commands to give you an overview of how easy it is to use the commands to view the details of the internal CLR Environment.
SOS is a very useful debugger extension DLL, designed to aid in the debugging of managed programs. In a previous article, I had shown how to Debug .NET 4.0 applications using SOS extension where we had discussed where to download the extensions from and how to use it in your application.
In this article, we will explore some SOS commands to give you an overview of how easy it is to use the SOS Debugger Extensions to view the details of the internal CLR Environment. I am assuming you have read my previous article and are familiar of how to use the SOS Extension
Note: The SOS dll is specific to the version of the CLR that the application is using.
View all Managed Threads in the Process
Use the command - !thread
Display all Application Domains for the Executable
Use the command – !dumpdomain
Shown above are three application domains in this process - System, Shared, and Domain 1. If you wanted to see the output for only a specific domain, say Domain 1, type the following command
002817f8 is a pointer to the domain Domain 1, as seen in the screenshot above.
Display Information About an Assembly
We know that an assembly is bound to an application domain. In the previous example, we got a list of all application domains and its details. One of the detail was the assembly address. Here’s how to use it to display information about the assembly, using this address.
Use the command – !dumpassembly
View the Stack Trace and local Variable information
Use the command – !ClrStack –l
The parameter –l is used to get local variable information (without the name). In order to get detailed Variable Information, use the command – !DumpObj <variable address>
These were just a few examples of how we can use the SOS Debugger Extension to view information about the internal common language runtime (CLR) environment. Similarly you can get object information, dump memory, view stack objects, CLR Exceptions, managed heap and garbage collection, Thread Pool and much more. The best way to do so would be by browsing through the SOS Debugging Commands Table.