Equivilent to !clrthreads

Provides a list of the managed threads in the process, as PSObjects. The -live and -special parameters of the underlying SOS command are supported.

Example: Viewing the Exception For A Thread

One of the things that !clrthreads reports is the address of the exception (if any) currently on the stack for each thread. In the case of a crash mode dump for an unhandled exception, that exception is the one that's just about to kill your process. So seeing what the exception actually is is pretty useful.

(In this example the threads are rendered using Format-List (the default) otherwise you don't see the column with the ExceptionAddress in. Piping the output to Out-GridView is what I'd normally recommend)

PowerDbg > Dump-ClrThreads

DbgID            : 0
ID               : 1
OSID             : 15cc
ThreadOBJ        : 000000000042aff0
State            : a02
GC               : Enabled
GC Alloc Context : 000000000275fea0:000000000275ffd0
Domain           : 00000000003cf120
Lock Count       :
APT              : MTA
Exception        : System.InvalidOperationException (000000000275fd58)
ExceptionAddress : 000000000275fd58

DbgID            : 2
ID               : 2
OSID             : 630
ThreadOBJ        : 0000000000554340
State            : b22
GC               : Enabled
GC Alloc Context : 0000000000000000:0000000000000000
Domain           : 00000000003cf120
Lock Count       :
APT              : MTA
Exception        : (Finalizer)
ExceptionAddress : Finalizer

The first has an exception, so we want to see what the exception message is:

PowerDbg > $ex = (Dump-ClrThreads)[0].ExceptionAddress | Dump-Object
PowerDbg > $ex._message | Dump-Object

__Fields        : {System.Object, System.Object, System.Object, System.Object...}
__Name          : System.String
__MethodTable   : 000007fee876ec90
__EEClass       : 000007fee837b038
__Size          : 162(0xa2) bytes
__String        : If you can read this, you're too close! 21:02:49
m_arrayLength   : 69
m_stringLength  : 48
m_firstChar     : 49
Empty           : static
WhitespaceChars : static

Ah. It all makes sense now.

Last edited May 22, 2010 at 2:57 PM by piers7, version 1


No comments yet.