1

When I use the disassembly window of Visual Studio 2012 for a C# project, I expect to see IL code. But it shows x64 assembly. Is this caused by the jitter? The assembly below is a portion of the assembly code disassembled.

        public static void Main() {
00000000  sub         rsp,1C8h 
00000007  xor         eax,eax 
00000009  mov         qword ptr [rsp+60h],rax 
0000000e  mov         qword ptr [rsp+58h],rax 
00000013  mov         qword ptr [rsp+50h],rax 
00000018  mov         qword ptr [rsp+38h],rax 
0000001d  mov         qword ptr [rsp+30h],rax 
00000022  mov         qword ptr [rsp+28h],rax 
00000027  mov         qword ptr [rsp+20h],rax 
0000002c  xor         eax,eax 
0000002e  mov         dword ptr [rsp+4Ch],eax 
00000032  mov         dword ptr [rsp+48h],eax 
00000036  mov         dword ptr [rsp+44h],eax 
0000003a  mov         dword ptr [rsp+40h],eax 
0000003e  mov         rax,7F8786239C0h 
00000048  mov         eax,dword ptr [rax] 
0000004a  test        eax,eax 
0000004c  je          0000000000000053 
0000004e  call        000000005FA4647C 
Tongfei Chen
  • 613
  • 4
  • 14
  • 1
    Your expectation is wrong. The disassembly window shows assembly code, not IL. If you want IL use a decompiler like ILDasm, ILSpy, etc. – D Stanley Jan 08 '14 at 14:12
  • Yes, it is the jitter's job to turn IL into actual executable code. The Disassembly window shows that code. – Hans Passant Jan 08 '14 at 14:49

2 Answers2

1

The current C# .NET debugger always shows the native code for methods (at least for x86 and x64). This is the code produced from the IL by the JIT. If you want to see the IL for a method, I recommend taking a look at ILSpy.

Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
0

The dissembly window looks at the code which is running directly on the processor. Hence it will show assembler and not IL.

If you want to see the raw IL of a C# method then look at a tool like ildasm or reflector

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • 1
    This isn't quite accurate. The disassembly window uses the information provided by the implementation of [IDebugDisassemblyStream2](http://msdn.microsoft.com/en-us/library/bb161331.aspx), which could be native code but can just as easily [be bytecode](http://blog.280z28.org/wp-content/uploads/2013/03/JavaBytecodeDisassembly.png). If I had to guess, I'd say Microsoft chose to implement the interface with assembly code so developers could more easily answer [questions like this](http://stackoverflow.com/questions/17328641/ternary-operator-is-twice-as-slow-as-an-if-else-block/17331230#17331230). – Sam Harwell Jan 08 '14 at 14:17
  • @280Z28 correct, but in the CLR debug engine (which is really the native + CLR engine) this will always return the assembly code. Many times I wish it would return the IL but unfortunately it doesn't – JaredPar Jan 08 '14 at 17:29