检索JIT输出JIT

2023-09-02 10:32:49 作者:温柔、冷先生

我很感兴趣,查看实际的x86汇编输出由C#程序(而不是CLR字节code指令)。有没有好的办法做到这一点?

I'm interested in viewing the actual x86 assembly output by a C# program (not the CLR bytecode instructions). Is there a good way to do this?

推荐答案

您应该使用WinDbg与SOS / SOSEX,确保你想看到86 $ C $下的即时编译的方法表,然后看看实际unassembly与方法U 命令。因此,你会看到实际的code。

You should use WinDbg with SOS/SOSEX, ensure that method you want to see x86 code for is JITted in method tables and then see actual unassembly with u command. Thus you would see actual code.

正如其他人在这里提到的,与NGEN你可以看到code,是不是完全匹配的实际JIT编译的结果。与Visual Studio,也可以因为JIT的编译很大程​​度上取决于如果调试器是present与否的事实。

As others mentioned here, with ngen you could see code that is not exactly matches actual JIT compilation result. With Visual Studio it is also possible because JIT's compilation depends heavily on the fact if debugger is present or not.

UPD:一些澄清。 WinDbg的是调试器还,但它的本机的之一。

UPD: Some clarification. WinDbg is a debugger also, but it is native one.

这里中你可以看到详细的技术。

Here you can read about the technique in detail.