如何使用 Mono.Cecil 获取 IL 指令的源代码/行号 [英] How to get source/line number for IL instruction using Mono.Cecil

查看:42
本文介绍了如何使用 Mono.Cecil 获取 IL 指令的源代码/行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Mono.Cecil 编写一个简单的实用程序,用于在 .NET 程序集中查找类型/方法的使用情况(例如,在枚举上调用 ToString).

I'm using Mono.Cecil to write a simple utility that looks for type/method usage within .NET assemblies (ex. calling ToString on enums).

我能够找到该方法,但是向用户显示源/行信息会很酷.Mono.Cecil 可以做到这一点吗?

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 wiki 中关于调试符号的指南.

It is possible. First you should read the guide from the Mono.Cecil wiki about debugging symbols.

确保在 Mono.Cecil.dll 附近有 Mono.Cecil.Pdb.dll,设置 ReaderParameters 以读取指南中指示的符号,然后,在 pdb 文件中具有序列点的指令将有它们的SequencePoint 属性非空,具有可用的行信息.SequencePointDocument 属性保存源文件的名称.

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.

这篇关于如何使用 Mono.Cecil 获取 IL 指令的源代码/行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆