Over a million developers have joined DZone.

PSSCor2: Object Inspection Commands, Part 1

·

PSSCor2 is a recently released debugging extension used internally by Microsoft support engineers to debug managed applications. It’s a separate download that installs its 32-bit and 64-bit flavors, and currently there’s only a version that works with CLR 2.0, but its additions on top of the core SOS are significant and therefore it’s worth learning how to use them.

In this installment, we’ll take a look at some of the new object inspection commands. Stay tuned for more—all in all, there are a couple of dozen new commands that I’d like to show you.

Let’s start with some object inspection commands. Although SOS ships with the very useful !do and !dumpvc commands, it’s somewhat difficult to parse some primitive types nevertheless. For example, if you have a DateTime instance, inspecting it with !dumpvc provides the following (not very helpful) output:

0:000> !do 024c90a8
Name: SimpleManagedApp.Program
MethodTable: 002e32e4
EEClass: 002e1350
Size: 16(0x10) bytes
GC Generation: 0
Fields:
[…edited for brevity…]

      MT    Type VT            Attr     Value    Name
70518148    System.DateTime    instance 024c90ac date

0:000> !dumpvc 70518148 024c90ac
Name: System.DateTime
MethodTable 70518148
EEClass: 702f0564
Size: 16(0x10) bytes
Fields:
      MT    Type VT          Attr     Value         Name
705193ec    System.UInt64    instance 9857553727207558089 dateData

On the other hand, using the new !PrintDateTime command, this is a piece of cake:

0:000> !PrintDateTime 024c90ac
2888cbc9
As a TimeSpan: 11409205.16:52:00.7558089
As a DateTime: 08/23/2010 14:03:55

Note that there are two additional new commands, !ConvertVTDateToDate and !ConvertTicksToDate, which accomplish essentially the same thing. To the former you pass a DateTime instance; to the latter, you pass the dateData field—the number of ticks embedded in the DateTime instance. Using the information from the previous example:

0:000> !ConvertTicksToDate 9857553727207558089
2888cbc9
As a TimeSpan: 11409205.16:52:00.7558089
As a DateTime: 08/23/2010 14:03:55

Similarly, the new !PrintIPAddress command displays the contents of an IPAddress instance (a fairly ugly parsing task without it):

0:000> !dumpvc 6e52e13c 025d90ec
Name: System.Net.IPAddress
MethodTable 6e52e13c
EEClass: 6e39f9d8
Size: 40(0x28) bytes
Fields:
      MT   Type VT  Attr    Value Name
70542374   System.Int64  1 instance 72058141349699900 m_Address
70540ae8   System.String 0 instance 00000000 m_ToString
6e52dca0   System.Int32  1 instance 39686420 m_Family
70534268   System.UInt16[]  0 instance 00000000 m_Numbers
70542374   System.Int64  1 instance 0 m_ScopeId
70542d34   System.Int32  1 instance        2 m_HashCode
[…edited for brevity…]

0:000> !PrintIPAddress 025d90ec
127.0.0.1

Another unpleasant thing that you had to accomplish manually using SOS is displaying the contents of an XML document. This isn’t trivial, as the string representation of the XML is not part of the XmlDocument instance. Fortunately, the new !DumpXmlDocument command prints out the document for you:

0:000> !dso
OS Thread Id: 0x5a8 (0)
ESP/REG  Object   Name
[…edited for brevity…]
003ceea4 025295c0 System.Xml.XmlDocument
003cf154 02529098 System.Object[]    (System.String[])
0:000> !do 025295c0
Name: System.Xml.XmlDocument
MethodTable: 6c527e14
EEClass: 6c476744
Size: 156(0x9c) bytes
GC Generation: 0
Fields:
[…huge dump of all XmlDocument fields…]

0:000> !DumpXmlDocument 025295c0
<books>
   <book author="Tolstoy">
      War and Peace
   </book>
</books>

Nice! Let’s conclude today’s PSSCor2 tour with a command that has lots of potential—!DumpCollection. This command takes a collection and displays in a convenient way the elements of the collection, eliminating the need to traverse manually the collection’s internal implementation. This command’s biggest disadvantage is that it wasn’t updated to support the generic collections of .NET 2.0. It does support hash tables, which is the hardest collection to traverse. Here’s some sample output:

0:000> !dso
OS Thread Id: 0xbc8 (0)
ESP/REG  Object   Name
[…edited for brevity…]
0022f16c 023ecc50 System.Collections.Hashtable
0022f178 023ecc18 System.Collections.ArrayList
0022f17c 023ecbd0 System.Collections.Generic.List`1[[System.String, mscorlib]]

0:000> !dumpcollection 023ecc50
Going to dump the Collection passed.
Collection 0x023ecc50: System.Collections.Hashtable

        Address            MT    Class Name
key: 0x023e9338    0x70540ae8    Masha
val: 0x023ecd24    0x70542d34    System.Int32

key: 0x023e931c    0x70540ae8    Sasha
val: 0x023ecd18    0x70542d34    System.Int32

0:000> !dumpcollection 023ecbd0
Going to dump the Collection passed.
0x023ecbd0 is not a supported Collection object

0:000> !dumpcollection 023ecc18
Going to dump the Collection passed.
Collection 0x023ecc18: System.Collections.ArrayList
[0] 023e931c
    Name: System.String
    MethodTable: 70540ae8
    EEClass: 702fd65c
    Size: 28(0x1c) bytes
    GC Generation: 0
    String:     Sasha   
    Fields: […removed for brevity…]
[1] 023e9338
    Name: System.String
    MethodTable: 70540ae8
    EEClass: 702fd65c
    Size: 28(0x1c) bytes
    GC Generation: 0
    String:     Masha   
    Fields: […removed for brevity…]

Next time, we’ll take a look at some additional object inspection commands, as well as commands tailored specifically for ASP.NET.

Topics:

Published at DZone with permission of Sasha Goldshtein, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}