如何使用 Mono.Cecil 获取 IL 指令的源代码/行号
我正在使用 Mono.Cecil 编写一个简单的实用程序,用于查找 .NET 程序集中的类型/方法使用情况(例如,在枚举上调用 ToString)。
我能够找到该方法,但向用户显示源/行信息会很酷。 Mono.Cecil 可以做到这一点吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可能的。首先,您应该阅读 Mono.Cecil wiki 中有关调试符号的指南。
确保 Mono.Cecil.Pdb.dll 靠近 Mono.Cecil.dll,设置 ReaderParameters 以读取指南中指示的符号,然后,在 pdb 文件中具有序列点的指令将具有其
SequencePoint
属性非空,具有可用的行信息。SequencePoint
的Document
属性保存源文件的名称。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. TheDocument
property of theSequencePoint
holds the name of the source file.