How to get source/line number for IL instruction u

2020-07-06 06:26发布

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?

1条回答
Anthone
2楼-- · 2020-07-06 07:18

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.

查看更多
登录 后发表回答