diassemble managed code issue

爷,独闯天下 提交于 2019-11-30 16:18:29

问题


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.



来源:https://stackoverflow.com/questions/1558221/diassemble-managed-code-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!