Debugging the .net compiler

I am currently working on a compiler for the language (external bytecode) and am using System.Reflection.Emit.

Now everything looks great when I open the generated assembly in the reflector and it recompiles, since C # works fine (and starts) too, but when I try to run the main function that is generated, I get InvalidProgramException:

"The usual runtime runtime detected an invalid program."

This is probably just one op code causing this problem, but since this main function uses more than 100 op codes, I cannot determine which of the op codes is causing the problem.

Each op code is very involved, so manually each op code is non-go.

Is there a way to get .NET to tell me where in the function it detects an invalid program?

And if not, is there another tool I can use to determine the source of the problem?

+5
source share
1 answer

I'd rather write this as an answer. You can use the PEVerify tool to verify the build. This is part of the Windows SDK tools, the best way to run it is from the Visual Studio command line, peverify.exe. You want to run it with the / il command-line option to check the IL you created, / md, to check the assembly metadata.

, , , , . , , , , . , , , , IL. promises, MSDN:

Peverify.exe MSIL . , Peverify.exe, . " " " MSIL" " " Windows (SDK).

, , :)

+10

All Articles