I'm using Mono.Cecil to write a simple utility that looks for type/method usage within .NET assemblies (ex. calling ToString on enums).
I am able to get find the method, but it would be cool to display the source/line information to the user. Is this possible with Mono.Cecil?
Mono.Cecil. Cecil is a library written by Jb Evain to generate and inspect programs and libraries in the ECMA CIL format. With Cecil, you can load existing managed assemblies, browse all the contained types, modify them on the fly and save back to the disk the modified assembly. Today it is used by the Mono Debugger,...
Emphasizing this simple piece of code is because reading in an assembly was achieved with the AssemblyFactory class before Cecil’s 0.9 version which was completely removed yet most of the existing few tutorials still use this class and other deprecated ones.
With Cecil, you can load existing managed assemblies, browse all the contained types, modify them on the fly and save back to the disk the modified assembly. Today it is used by the Mono Debugger, the bug-finding and compliance checking tool Gendarme and many other tools. There is a Google Group to discuss everything Cecil related: mono-cecil
IL code is not executed, it is compiled during the JIT process and the compiled code, let's just say assembly instructions, are the ones that are executed. And one IL instruction can be compiled into many assembly instructions e.g. a function call, meaning the original IL instruction is not executed atomically. Hey wait!) Re: Hey wait!)
It is possible. First you should read the guide from the Mono.Cecil wiki about debugging symbols.
Make sure you have Mono.Cecil.Pdb.dll near Mono.Cecil.dll, set the ReaderParameters to read the symbols as indicated in the guide, and then, instructions who have a sequence point in the pdb file will have their SequencePoint
property non null, with line information available. The Document
property of the SequencePoint
holds the name of the source file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With