I was trying to learn a bit about .NET intermediate language and was hoping to step through it, but fr开发者_运维技巧om what I can tell, I'm seeing something else - maybe the output of a just-in-time (JIT) compiler?
Is there a way to step through the CIL?
This article Debugging .NET Framework and MS Visual Studio Managed Classes at Run time and Design time explains how it is possible to seamlessly set breakpoints, step into, set watches and examine local variables for .NET framework classes as well as any other managed assemblies.
Your machine never executes IL, it is always translated to machine code. The job of the JIT compiler. The Disassembly window shows you the result of that translation.
As long as you do this with the Debug build then you can see a reasonable match between the IL and the machine code. That disappears however when the JIT optimizer is enabled, it makes a lot of optimizations that make the machine code as fast as reasonably possible. Typical is that entire methods disappear (called inlining), local variables disappear (replaced by CPU registers) and code gets re-organized.
Any introductory book about the x86 assembly language will help you interpret the machine code.
Yes, they are the output of the JIT. See David Moye's answer for a way to step through CIL. .NET Reflector is another great way to learn CIL from your own code.
- MSDN: How to: Use the Disassembly Window
精彩评论