diassemble managed code issue

2019-02-11 08:38发布

问题:

I am using Windbg to diassemble managed code (written in C#, console application) using Windbg's !U command from sos.dll. I find when using !U to diassemble a managed function, the diassembled IL code only contains function calls I made, and for remaining parts (non-function call C# code), for example a=a*2, and foreach loops in C#, only native assembly language code is shown, is that the correct expected behavior?

My question is, I want to know whether !U is capable of diassemble managed code binary DLL into IL with all code (besides function call code)?

Thanks in advance, George

回答1:

If you want to dump IL while debugging you can use the !dumpil command from SOS. It takes a MethodDesc pointer as input, so you have to obtain that first.

One way to get the MethodDesc pointer use the !name2ee command.

So for instance if you have a method Foo in the type Bar (in assembly ClassLibrary1) use !name2ee like this

0:000> !name2ee ClassLibrary1!ClassLibrary1.Bar.Foo
Module: 001630bc (ClassLibrary1.dll)
Token: 0x06000001
MethodDesc: 00163450  <=== HERE
Name: ClassLibrary1.Bar.Foo()
JITTED Code Address: 007500f0

Following that, you can do a !dumpil 00163450 to dump the IL for method Foo like this

0:000> !dumpil 00163450
ilAddr = 73532050
IL_0000: ldstr "Foo"
IL_0005: call System.Console::WriteLine


回答2:

I don't think WinDbg works at the IL level. You'd probably have to use ildasm to get an IL disassembly.