Sunday, December 09, 2012

Dumping the method descriptor for a System.Action (delegate)

In my previous post I needed to figure out what method descriptor a System.Action points to. This is painful so I wrote a small debugger script to automate it.  To use the script, copy this code to dumpMDForAction.dbg. Many thanks to Alois Kraos for posting how to do this.

Without further ado, fire up cdb and  find a System.Action:
 
0:000> !do 0000003de7023078
Name:        System.Action
MethodTable: 000007f9d26b9a68
EEClass:     000007f9d2071c10
Size:        64(0x40) bytes
File:        C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
000007f9d26c1ac8  400002d        8        System.Object  0 instance 0000003de7023078 _target
000007f9d26c1ac8  400002e       10        System.Object  0 instance 0000003de7028800 _methodBase
000007f9d26c60d8  400002f       18        System.IntPtr  1 instance       3de52e0900 _methodPtr
000007f9d26c60d8  4000030       20        System.IntPtr  1 instance      7f97fbfc040 _methodPtrAux
000007f9d26c1ac8  4000031       28        System.Object  0 instance 0000000000000000 _invocationList
000007f9d26c60d8  4000032       30        System.IntPtr  1 instance                0 _invocationCount

Next launch the script, passing the address of the action to the script:
0:000> $$>a< dumpMDForAction.dbg 0000003de7023078
usage - $$>a< ".\dumpMDForAction.dbg" addressOfObject
<.shell waiting 10 second(s) for process>
.shell: Process exited
0:000> r $t0=7f97fbfc040
0000003de7023078
Dumping
Method Name:  PerformanceOfSmallThings.Program.
b__3() Class: 000007f97fd022d0 MethodTable: 000007f97fbf39d0 mdToken: 0000000006000009 Module: 000007f97fbf2f90 IsJitted: yes CodeAddr: 000007f97fd10950 Transparency: Critical 0:000>
Happy debugging!

No comments: