Debugging Tools for Windows is an incredibly useful toolbox that every developer should know how to use. It contains powerful debuggers, troubleshooting tools, and debugger extensions that make debugging different technologies on Windows much easier. Amongst the debugger extensions is an extension called SOS, which allows developers to peek into the CLR itself to make debugging of managed code applications much more efficient. SOS has long been the standard when dealing with managed code using the native debuggers, but there are additional extensions that add even more value to the debugging process. Unfortunately, these added and powerful extensions were only available to Microsoft engineers, making the debugging process more tedious for third party developers. Fortunately, Microsoft very recently decided to release a very commonly used debugger extension to the public called psscor2. In this article, I will take a look at some of the powerful commands that are available as part of the psscor2 debugger extension.
The psscor2 debugger extension can be downloaded from
The installation process is very simple and comes in the form of a ZIP file that contains the psscor2.dll for all three flavors (x86, amd64, ia64). Simply extract the flavor you are interested in and place it in your favorite debugger extensions folder (I typically install it into the default debugger folder). You can then load the debugger extension in any of your debug sessions using the .load debugger command as shown below:
Psscor2 provides a slew of new commands in different areas of .NET. Some commands are specific to ASP.NET applications, whereas others are related to the core of the CLR. In this section of the article I will describe some of the new commands that are available as part of this new and exciting debugger extension.
A task when investigating ASP.NET problems is to figure out which ASPX pages are currently loaded into the IIS hosting process. The ASPXPages command can be used for this purpose. For example, attaching the debugger to an IIS hosting process (w3wp.exe) with a simple ASPX page loaded, the output of the ASPXPages command is shown below:
0:024> !ASPXPages Going to dump the HttpContexts found in the heap. Loading the heap objects into our cache. HttpContext Timeout Completed Running ThreadId ReturnCode Verb RequestPath+QueryString 0x00000000ff92c818 0 no 980 Sec XXX 200 /test/ 0x00000000ff94d258 110 Sec no 980 Sec XXX 200 GET /test/default.aspx Total 2 HttpContext objects
As you can see, the information presented is quite useful to get an overall idea behind the ASPX usage. If you want to see the IP addresses of the client and server, you can specify the –ip switch.
Another very useful task is to be able to see what the thread configuration is for the given ASP.NET application. For example, if the thread configuration is set to 100 and your debug session seems to imply that there are several hundred threads, the configuration may be an issue. To see the thread configuration, the DumpThreadConfig command can be used. An example of the output is shown below:
0:024> !DumpThreadConfig Loading the heap objects into our cache. 0x0000000000000000 is not a ServicePoint object autoConfig is true
Number of Processors: 4 (multiplied by number to get total value). MaxWorkerThreads: 100 (400) MaxIoThreads: 100 (400) minFreeThreads: 88 (352) minLocalRequestFreeThreads: 76 (304) maxConnection: 0 (0)
In the output above, we can see thread configuration such as max number of workers and Io threads as well as other useful information.
It is quite common for ASP.NET applications to utilize the built in ASP.NET application cache. Similarly, it is quite common when debugging to inspect the cache to make sure the source of the problem isn’t related to any issues within the cache itself. Psscor2 offers the DumpASPNETCache command to help with this task. For example, the following shows the output of the command when run against a simple ASP.NET application. For the sake of brevity, I have used the –stat switch since the detailed output for each object is quite verbose:
0:024> !DumpASPNETCache -stat Going to dump the ASP.NET Cache. Loading the heap objects into our cache. Statistics: MT Count TotalSize Change Class Name 0x000007fef67f1750 1 48 1 System.Reflection.Assembly 0x000007fee9bceef0 1 48 1 System.Web.Security.FileSecurityDescriptorWrapper 0x000007fee9b73d50 1 88 1 System.Web.Compilation.BuildResultCompiledTemplateType 0x000007fee9bfec38 5 320 5 System.Web.CachedPathData 0x000007fee9bffe38 10 400 10 System.Web.Configuration.MapPathCacheInfo 0x000007fee2f27880 2 928 2 System.Web.Mobile.MobileCapabilities Total 20 objects, Total size: 1,832
If there is anything strange (i.e., objects you don’t expect) you can use the same command without the –stat switch to get more detailed information.
In addition to the ASP.NET related commands above, there are other new commands as well such as DumpHttpRuntime, DumpHttpContext, DumpRequestTable, DumpHistoryTable and DumpRequestQueues. All of the commands simplify the inspection of ASP.NET state, and I encourage you to play around with the commands to get an idea of the incredible time savings that they can accomplish.
Date and Time Commands
Many applications make use of the data type System.DateTime. When debugging, however, it can sometimes be hard to convert the values of a DateTime object to a more human readable form. For example, the address 0x000000000016eef0 represents a DateTime value type instance. If I dump the contents of that memory I’ll get something similar to what is shown below:
0:000> dd 0x000000000016eef0 00000000`0016eef0 af64f480 88cc9fc5 af64f480 88cc9fc5 00000000`0016ef00 0000001d 00000000 00000001 00000000 00000000`0016ef10 00033988 000007ff f93bd502 000007fe 00000000`0016ef20 0216c960 00000000 f929240a 000007fe 00000000`0016ef30 f9165890 000007fe 00000000 00000000 00000000`0016ef40 0016f1c8 00000000 00000000 00000000 00000000`0016ef50 0016f1a0 00000000 00000000 00000000 00000000`0016ef60 003a87e0 00000000 f9279fd3 000007fe
The output doesn’t really tell me in a nice way what the DateTime instance contains. Enter the new psscor2 commands PrintDateTime and ConvertVTDateToDate. The ConvertVTDatetoDate (shortcut cvtdd) command takes as input the address of a value type and outputs the result to the screen. Using the same pointer as above, the output of the ConvertVTDateToDate command shows:
0:000> !cvtdd 0x000000000016eef0 As a TimeSpan: 11409061.18:38:59.8003808 As a DateTime: 04/01/2010 15:50:54
The PrintDateTime, on the other hand, takes an address to a reference type and outputs the DateTime in a nice format much like the ConvertVTDateToDate command.
General Object Inspection
In today's world, many applications make use of XML in one form or another. In the .NET world, a common way to represent an XML document is to use the XmlDocument class. The XmlDocument class provides a ton of great functionality to manipulate different XML snippets. During debugging, however, it is painstakingly difficult to find out what the XML looks like based solely on a pointer to an XmlDocument instance. For example, if I dump out an instance of the XmlDocument class I see the following (abbreviated):
0:000> !do 0x000000000267c730 Name: System.Xml.XmlDocument MethodTable: 000007fef5e1b218 EEClass: 000007fef5cdbd00 Size: 304(0x130) bytes GC Generation: 0 (C:\Windows\assembly\GAC_MSIL\System.Xml\18.104.22.168__b77a5c561934e089\System.Xml.dll) Fields: MT Field Offset Type VT Attr Value Name 000007fef5e1b5f8 40008d7 8 System.Xml.XmlNode 0 instance 0000000000000000 parentNode 000007fef5e1e5c0 40008e7 10 ...XmlImplementation 0 instance 000000000267c860 implementation 000007fef5e1e7b8 40008e8 18 ....Xml.DomNameTable 0 instance 000000000267cdb0 domNameTable 000007fef5e1e910 40008e9 20 ...Xml.XmlLinkedNode 0 instance 0000000002680078 lastChild 000007fef5e1f340 40008ea 28 ...l.XmlNamedNodeMap 0 instance 0000000000000000 entities 000007fef7dc65e8 40008eb 30 ...ections.Hashtable 0 instance 0000000000000000 htElementIdMap 000007fef7dc65e8 40008ec 38 ...ections.Hashtable 0 instance 0000000000000000 htElementIDAttrDecl 000007fef5e312c8 40008ed 40 ...Schema.SchemaInfo 0 instance 0000000000000000 schemaInfo 000007fef5e251a0 40008ee 48 ...hema.XmlSchemaSet 0 instance 0000000000000000 schemas 000007fef7dbde60 40008ef 120 System.Boolean 1 instance 1 reportValidity 000007fef7dbde60 40008f0 121 System.Boolean 1 instance 0 actualLoadingStatus 000007fef5e32070 40008f1 50 ...angedEventHandler 0 instance 0000000000000000 onNodeInsertingDelegate 000007fef5e32070 40008f2 58 ...angedEventHandler 0 instance 0000000000000000 onNodeInsertedDelegate 000007fef5e32070 40008f3 60 ...angedEventHandler 0 instance 0000000000000000 onNodeRemovingDelegate
That really doesn’t tell me much about the actual XML content. Fortunately, psscor2 introduces the DumpXmlDocument command that takes a pointer to an XmlDocument instance and produces the actual XML content:
0:000> !DumpXmlDocument 0x000000000267c730 <Configuration Product="HomeStudentr"> <Display Level="none" CompletionNotice="No" SuppressModal="Yes" AcceptEula="no"> </Display> <Setting Id="OEM" Value="1"> </Setting> <Setting Id="REFERRAL" Value="QW2E3T5A"> </Setting> <Setting Id="SETUP_REBOOT" Value="NEVER"> </Setting> <AddLanguage Id="es-es"> </AddLanguage> </Configuration>
Another great command is the DumpCollection command, which is able to dump the contents of one of the following:
- Collections derived from DictionaryBase
- Collections derived from NamedObjectCollectionBase
For example, if I had an ArrayList that contained five names (of type string), the output of the DumpCollection command would look like:
0:000> !DumpCollection 0x000000000270c738 Going to dump the Collection passed. Collection 0x000000000270c738: System.Collections.ArrayList  000000000270c6c8 Name: System.String MethodTable: 000007fef7dbec90 EEClass: 000007fef79cb038 Size: 36(0x24) bytes GC Generation: 0 (C:\Windows\assembly\GAC_64\mscorlib\22.214.171.124__b77a5c561934e089\mscorlib.dll) String: Gemma Fields: MT Field Offset Type VT Attr Value Name 000007fef7dc5f00 4000096 8 System.Int32 1 instance 6 m_arrayLength 000007fef7dc5f00 4000097 c System.Int32 1 instance 5 m_stringLength 000007fef7dc06d8 4000098 10 System.Char 1 instance 47 m_firstChar 000007fef7dbec90 4000099 20 System.String 0 shared static Empty >> Domain:Value 00000000001bebf0:00000000026a1308 << 000007fef7dc0588 400009a 28 System.Char 0 shared static WhitespaceChars >> Domain:Value 00000000001bebf0:00000000026a1a50 <<  000000000270c6f0 Name: System.String MethodTable: 000007fef7dbec90 EEClass: 000007fef79cb038 Size: 32(0x20) bytes GC Generation: 0 (C:\Windows\assembly\GAC_64\mscorlib\126.96.36.199__b77a5c561934e089\mscorlib.dll) String: Pia Fields: MT Field Offset Type VT Attr Value Name 000007fef7dc5f00 4000096 8 System.Int32 1 instance 4 m_arrayLength 000007fef7dc5f00 4000097 c System.Int32 1 instance 3 m_stringLength 000007fef7dc06d8 4000098 10 System.Char 1 instance 50 m_firstChar 000007fef7dbec90 4000099 20 System.String 0 shared static Empty >> Domain:Value 00000000001bebf0:00000000026a1308 << 000007fef7dc0588 400009a 28 System.Char 0 shared static WhitespaceChars >> Domain:Value 00000000001bebf0:00000000026a1a50 <<  000000000270c710 Name: System.String MethodTable: 000007fef7dbec90 EEClass: 000007fef79cb038 Size: 36(0x24) bytes GC Generation: 0 (C:\Windows\assembly\GAC_64\mscorlib\188.8.131.52__b77a5c561934e089\mscorlib.dll) String: Mario Fields: MT Field Offset Type VT Attr Value Name 000007fef7dc5f00 4000096 8 System.Int32 1 instance 6 m_arrayLength 000007fef7dc5f00 4000097 c System.Int32 1 instance 5 m_stringLength 000007fef7dc06d8 4000098 10 System.Char 1 instance 4d m_firstChar 000007fef7dbec90 4000099 20 System.String 0 shared static Empty >> Domain:Value 00000000001bebf0:00000000026a1308 << 000007fef7dc0588 400009a 28 System.Char 0 shared static WhitespaceChars >> Domain:Value 00000000001bebf0:00000000026a1a50 <<
The last general object inspection command we will discuss is the PrintIPAddress command. Similarly to the above objects, dumping out the raw form of the System.Net.IPAddress doesn’t easily tell you what the textual representation of the IP address is. The PrintIPAddress comes to rescue. By specifying the address to the IPAddress object, PrintIPAddress will give you the easily digestible version of the IPAdress object:
0:000> !PrintIPAddress 0x00000000024bc6c8 254.7.0.0
In this article I took a look at the new managed code debugger extension called psscor2. Psscor2 contains a plethora of powerful commands, both in the general object inspection arena and in the ASP.NET arena, allowing developers to be much more efficient in their debug sessions. While I only looked at some of the more commonly used commands in psscor2, there is more to the debugger extension, and I urge you to take a closer look at some of the other commands it has to offer.