When compiled in the DEBUG
configuration ILSpy offers a few features that make it easier to work with the decompiler pipeline and the intermediate representation used by ILSpy (called "ILAst").
ILAst Verification
The decompiler pipeline runs an extra verification step after each transformation to ensure that all transformations produce an ILAst that is understood by the ExpressionBuilder / CallBuilder / StatementBuilder.
The Language Dropdown
In addition to the C#, IL and "IL with C#" modes available in release builds, debug builds add a few more entries:
Typed IL
The "Typed IL" view shows the output produced by the ILReader, without any control-flow analysis. It prints type information for every used slot of the evaluation stack after each instruction. Note: This view is only available on the method level.
ILAst
The ILAst view shows the ILAst of a single (top-level) ILFunction. Use View -> Show debug steps
or the Show Steps
button after the IL signature of the method, to open the "Debug Steps".
You can view the CFG ("Control-flow graph") for each BlockContainer
node in the ILAst output, by selecting DEBUG -- Show CFG
from the context menu. ILSpy will then generate an image showing the CFG of that BlockContainer
. Note that this feature requires that Graphviz dot.exe
is in the PATH
of your environment.
Debug steps
The tree view contains a node for each step in the decompiler pipeline. You can view the structure of the ILAst after each step by double-clicking on a tree node, or by pressing Enter
. Use Shift+Enter
to show the structure of the ILAst before the selected step. Both options are also included in the context menu on the tree view.
/images/ILSpy_5.0.0.5099-DebugSteps-Overview.png
The above image shows the ILAst right before the selected "Inline variable 'S_21'" step in Block IL_003b
.
You can step through a transform at a selected point by selecting the tree node and choosing Debug this step
from the context menu. The debugger will then break right before the selected step starts. (Note that you will have to step out of a few stack frames to get back to the transform.)
ILAst-specific options
UseFieldSugar:
Show ldobj+ldflda
or stobj+ldflda
as simplified ldfld
/stfld
instruction.
UseLogicOperationSugar:
Show if (a) b else ldc.i4 0
or if (a) ldc.i4 1 else b
as simplified logic.and
/logic.or
instruction.
ShowILRanges:
Show IL offsets and ranges next to each instruction.
ShowChildIndexInBlock:
Show the child index of each instruction, if it is a direct child of a Block
.
C# - Transformation steps
Each transformation step of the "C# transforms" is available in the language dropdown.
Additional commands
These commands are available in main menu or the context menu of the main tree view.
DEBUG -- Disassemble All
This command is available if there exists a directory named c:\temp\disassembled
on your system.
It will dump the contents (IL and metadata) of each assembly in the current assembly list. A separate .il
file is created for each assembly.
DEBUG -- Decompile All
This command is available if there exists a directory named c:\temp\decompiled
on your system.
It will decompile each assembly in the current assembly list. A separate .cs
file is created for each assembly.
DEBUG -- Dump PDB as XML
This command dumps the contents of a PDB file associated with the selected assembly in XML format.
DEBUG -- Decompile 100x
Decompiles the selected tree node 100 times and measures the time needed. The average time is printed after the decompilation finished. No other output is produced.