开发者

Simultaneously debug through intermediate language (IL) and C# in Visual Studio

I'm looking for an extension for Visual Studio where in debug mode it's possible to single step through the intermediate langu开发者_JAVA百科age beside C#.

I'm not looking for a solution to debug managed and unmanaged code.


What is your purpose? Is your IL generated by C# compiler or dynamically produced at run time? If the former one, you can use a trick of re-compiling your binary through ilasm.

  1. Compile C# code as you normally would. It does not matter if it is optimized or not, but you have to specify compilation option to produce full PDB symbols.
  2. Use ildasm to convert your binary to .il file. It is option Dump in the menu.
  3. re-compile the .il file to get a new binary (and a new symbols)

    ilasm .il [/exe|/dll] /debug

  4. Now when debugging that specific assembly you will see IL code rather than C# code. You will also see a matching lines from original C# file if you select appropriate option in step 2.

For the case of dynamically generated IL, I would simply use WinDbg with SOS extension. It can dump IL and step through it, but it takes a bit to get used to.


Although not strictly a Visual Studio extension as the OP requested, there's now a maybe even better way to do this using dnSpy, a comprehensive, standalone, open-source .NET debugging tool. The tool actually does much more than just debugging; for example it allows direct editing of .NET and native (PEFile) assemblies, de-obfuscating them, browsing and modifying the raw managed and native headers, content, resources, BAML, and metadata, and more that I probably haven't discovered.

Simultaneously debug through intermediate language (IL) and C# in Visual Studio

For the purposes of the discussion on this page, be sure to check out the IL interpreter section of the dnSpy project. Exactly as requested by the OP, this is the library that implements an IL interpreter for simulating the (pretend) execution of the IL code in parallel with the debugger's (actual) native instruction single-stepping, for the purposes of displaying the state of the (logical) IL execution stack. I believe there's some excellent x86/x64 disassembly rendering built-in to the debugger as well, if needed. Kudos to the developer of this tour-de-force app.


I don't think that an external disassembler is necessary here. When you're debugging in VS 2010 (though not Express) you can right-click on the code window and select "Go To Disassembly" to step through the IL code. Could that be what you're looking for? Read more here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜