Is there any IL level debugger in form of a VS plugin or standalone application?
Visual studio’s debugger is great, but it allows you to debug on either HLL code level or assembly language, you can’t debug IL.
It seems that in some situations it would be useful to have an opportunity to debug at IL level.
In particular it might be helpful when debugging a problem in the code that you don't have the source of.
It is arguable if it is actually useful to debug IL when you don't have the source, but anyway.
The best way to do this is to use ILDASM to disassemble the managed binary, which will generate the IL instructions. Then recompile that IL source code in debug mode using ILASM, when you fire up the Visual Studio debugger you will be able to step through the raw IL.
ildasm foo.exe /OUT=foo.exe.il /SOURCE
ilasm foo.exe.il /DEBUG
I've written a blog post about this topic at:
How to debug Compiler Generated code.
Debug Companion VS plugin seem to be exactly what I was looking for, except that it won't see library project in my solution. Only when I added a console win application to the solution did something appear in that list of projects.
The problem with the decompile/compile approach for me was that the code I was debugging wasn't my code. I could have decompiled it anyway but I think there's no way to sign that recompiled assembly so that it gets loaded instead of the original one.
With the particular problem I had it turned out that it was enough to just debug it on the assembly language level and get the call stack of the method which was throwing the exception and the parameters with which the method was called.
Here's the .BAT file that I use to debug IL assembler in Visual Studio. The created .IL.IL file contains the original source code lines and your generated IL assembler lines but does not show jitted machine code. I named the batch file ILDEB.BAT and is invoked as "ILDEB mypgm". I use the IL assembler directive "break" to force Visual Studio debugger to breakpoint when hit.
for /f "tokens=1 delims=." %%1 in ("%1") do set NAME_ONLY=%%1
@erase/q %NAME_ONLY%.il.il
@if not exist %NAME_ONLY%.dll goto quit
ildasm /out:%NAME_ONLY%.il.il /source /nobar %NAME_ONLY%.dll
@if not exist %NAME_ONLY%.il.il goto quit
ilasm /dll /debug /out=%NAME_ONLY%.dll %NAME_ONLY%.il.il
@if not exist %NAME_ONLY%.dll goto quit
peverify %NAME_ONLY%.dll
:quit
Here is an article about IL debugging. It says you can't do it and then talks about ways to do it. There is also some info in the comments about doing it also.
ISTR there's a debugger plug-in for Reflector.
Not used it myself, though I have used TestDriven.net to debug a 3rd-party assembly with the aid of Reflector:
weblogs.asp.net/nunitaddin