Home > Articles > Programming > Windows Programming

Debugging Tools for Windows: The psscor2 Managed Code Debugger Extension

  • Print
  • + Share This
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. Mario Hewardt takes a look at some of the powerful commands that are available as part of the psscor2 debugger extension.
Like this article? We recommend

Like this article? We recommend

Introduction

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.

Installation

The psscor2 debugger extension can be downloaded from

http://www.microsoft.com/downloads/details.aspx?FamilyID=5c068e9f-ebfe-48a5-8b2f-0ad6ab454ad4&displayLang=en

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:

New Commands

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.

ASP.NET Commands

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\2.0.0.0__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:

  • ArrayList
  • HashTable
  • Queue
  • 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
[0] 000000000270c6c8
    Name: System.String
    MethodTable: 000007fef7dbec90
    EEClass: 000007fef79cb038
    Size: 36(0x24) bytes
    GC Generation: 0
     (C:\Windows\assembly\GAC_64\mscorlib\2.0.0.0__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 <<
[1] 000000000270c6f0
    Name: System.String
    MethodTable: 000007fef7dbec90
    EEClass: 000007fef79cb038
    Size: 32(0x20) bytes
    GC Generation: 0
     (C:\Windows\assembly\GAC_64\mscorlib\2.0.0.0__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 <<
[2] 000000000270c710
    Name: System.String
    MethodTable: 000007fef7dbec90
    EEClass: 000007fef79cb038
    Size: 36(0x24) bytes
    GC Generation: 0
     (C:\Windows\assembly\GAC_64\mscorlib\2.0.0.0__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 

Summary

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.

  • + Share This
  • 🔖 Save To Your Account

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020