SOS Command: !DumpIL
<Managed DynamicMethod object> |
<DynamicMethodDesc pointer> |
<MethodDesc pointer>
!DumpIL prints the IL code associated with a managed method. We added this function specifically to debug DynamicMethod code which was constructed on the fly. Happily it works for non-dynamic code as well.
You can use it in three ways:
- If you have a System.Reflection.Emit.DynamicMethod object, just pass the pointer as the first argument.
- If you have a DynamicMethodDesc pointer you can use that to print the IL associated with the dynamic method.
- If you have an ordinary MethodDesc, you can see the IL for that as well, just pass it as the first argument.
Note that dynamic IL is constructed a bit differently. Rather than referring to metadata tokens, the IL points to objects in a managed object array. Here is a simple example of the output for a dynamic method:
0:000> !dumpil b741dc
This is dynamic IL. Exception info is not reported at this time. If a token is unresolved, run “!do <addr>” on the addr given in parenthesis. You can also look at the token table yourself, by running “!DumpArray 00b77388″.
IL_0000: ldstr 70000002 "Inside invoked method " IL_0005: call 6000003 System.Console.WriteLine(System.String) IL_000a: ldc.i4.1 IL_000b: newarr 2000004 "System.Int32" IL_0010: stloc.0 IL_0011: ldloc.0 IL_0012: ret