【问题标题】:Fody/Mono.Cecil: Hide Lines in debuggerFody/Mono.Cecil:在调试器中隐藏行
【发布时间】:2015-02-28 18:40:39
【问题描述】:

我正在开发一个 fody 插件(使用 mono.cecil)并在方法的开头注入一些代码。我希望调试器跳过注入的代码。

我在这里找到了一些信息:http://blogs.msdn.com/b/abhinaba/archive/2005/10/10/479016.aspx

所以我尝试将注入指令的序列点更新为行号 0xfeefee。

我正在使用以下代码进行此操作:

    public static void Inject(MethodDefinition method, List<Instruction> instructions)
    {
        var methodInstructions = method.Body.Instructions;

        int index = 0;
        var sequencePoint = method.Body.Instructions
            .Where(instruction => instruction.SequencePoint != null)
            .Select(instruction => instruction.SequencePoint)
            .FirstOrDefault();

        if (method.HasBody && sequencePoint != null && sequencePoint.Document != null)
        {
            var instruction = instructions[0];
            instruction.SequencePoint = new SequencePoint(sequencePoint.Document);
            instruction.SequencePoint.StartLine = 0xfeefee;
            instruction.SequencePoint.EndLine = 0xfeefee;
        }

        foreach (var instruction in instructions)
        {
            methodInstructions.Insert(index++, instruction);
        }

        method.Body.OptimizeMacros();
    }

这应该与 NullGuard.Fody 项目使用的代码基本相同,但它不起作用。在尝试调试注入代码的方法时,我仍然从 Visual Studio 获得源不可用的信息。

我是否需要做其他事情才能更新 pdb 文件?

【问题讨论】:

    标签: c# .net pdb mono.cecil fody


    【解决方案1】:

    尝试从查询中删除Where 以选择第一个序列点。

    如果方法的第一条指令有序列点,您应该只需要添加隐藏的序列点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-22
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 2018-05-16
      相关资源
      最近更新 更多