调试器StepInto自动生成的代码和JMC问题 [英] Debugger StepInto auto-generated code and JMC issue

查看:177
本文介绍了调试器StepInto自动生成的代码和JMC问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MDBG样品管理的.NET调试器。

I'm making a managed .NET debugger using MDBG sample.

目前我与StepInto行为挣扎,而失步和步距似乎工作。

Currently I'm struggling with StepInto behavior, while StepOut and StepOver seems to work.

要实现刚刚我-代码踩着我打电话 SetJMCStatus 上模块负载。这工作正常,并允许我刚刚调试我的代码。

To achieve Just-My-Code stepping I'm calling SetJMCStatus on modules load. That works fine and allow me to debug just my code.

但自从我设置整个模块作为江铃,一些自动生成的代码进场和毁灭stepping-成。这种代码的一个例子是自动属性。

But since I'm setting entire module as JMC, some auto-generated code comes into play and ruin stepping-into. An example of such code could be auto-property.

由于调试器执行IL指令,以逐步进入我得到自动生成的 get_propertyName 和 set_propertyName 方法,其中被标记为我的代码,因为他们是我的模块的一部分。

Since debugger is executing Il instructions, with step-into I'm getting inside auto-generated get_propertyName and set_propertyName method, which are marked as my code, because they are part of my module.

要从我的代码区分这种自动生成的代码,我可以使用调试符号,也缺少在自动生成的代码的情况下存在。然后,我可以简单地标记方法,不是我的代码步进过程中跳过它。

To distinguish such auto-generated code from my code I can use presence of debugging symbols, that are missing in case of auto-generated code. And then I could simply mark method as not my code to skip it during stepping.

问题是我不知道之前哪些方法自动生成步进期间我收到内部:当我走到一个没有调试符号的方法里面,我可以将其标记为不是我的代码,但为时已晚。 - 调试器停在那里应该不会停止

The problem is I don't know which methods are auto-generated before I'm getting inside during stepping. When I stepped inside a method that has no debugging symbols I can mark it as not my code, but it's too late - debugger stopped where it supposed not to stop.

从理论上讲,我可以遍历使用IMetadataImport我模块的方法,并设置其JMCStatus调试器启动时,但它似乎相当昂贵:

Theoretically I could iterate over my module methods using IMetadataImport and set their JMCStatus when debugger starts, but it seems quite expensive:

 foreach (var methodToken in mdbgModule.Importer.EnumerateAllMethodTokens()) {
                var func = mdbgModule.GetFunction(methodToken);
                    if (func.SymMethod == null)
                        func.CorFunction.JMCStatus = false;
            }

如果只有我会知道将要接下来执行什么功能,那么我也可以设置它的状态和防止在第一时间自动生成的代码内步进。

If only I would know what function is going to be executed next, then I would be able to set it's status and prevent stepping inside auto-generated code for the first time.

我跟步进,不改变任何东西MDBG办法坚持,只是调用SetJMCStatus在需要的地方,所以我不知道这是否有道理提供任何代码。如果这样,我将修改的问题,只需添加一个评论!

I'm sticking with MDBG approach for stepping, not changing anything, just calling SetJMCStatus where it's needed, so I'm not sure if it makes sense to provide any code... If so, I'll edit the question, just add a comment!

在题目任何建议,非常感谢!

Any suggestion on topic is greatly appreciated!

问候,

推荐答案

麦克失速的在一个选项暗示,你可以为整个模块设置江铃汽车,然后在调试器步进休息,检查,看看是否该方法可调试,如果不是那么禁用它的JMC状态并重新运行步进。 (我不知道这是否会导致行为的改变,如果恢复步进将需要再次插手之前走出。)

Mike Stall hinted at one option, you could set JMC for the entire module and then when the debugger stepper breaks, check to see if the method is debuggable, if not then disable it's JMC status and rerun the stepper. (I'm not sure if this will result in a change in behaviour if the resuming stepper would need to step out before stepping in again.)

您也许可以改善的事情仅通过设置JMC对于具有PDB可用的模块,并通过与江铃禁用的类/方法 [DebuggerNonUserCode] 应用(也许是的 [DebuggerHidden] 太)。但是,而不是枚举所有的类/方法,并检查他们是否有属性,列举了自定义属性和下班回来(的 IMetaDataImport :: EnumCustomAttributes 与tkType设置而不是传统知识,然后使用的 IMetaDataImport :: GetCustomAttributeProps 得到的东西应用到)。

You could probably improve things by only setting JMC for modules that have a pdb available and by disabling JMC for classes/methods with [DebuggerNonUserCode] applied (and perhaps [DebuggerHidden] too). But rather than enumerating all the classes/methods and checking if they have the attribute, enumerate the custom attributes and work back (IMetaDataImport::EnumCustomAttributes with tkType set but not tk, then use IMetaDataImport::GetCustomAttributeProps to get the thing its applied to).

您可能能够如果在方法级别应用做的 [编译器生成] 属性类似的东西,但在类级别应用将得到误报(编译器应用它的迭代器和异步方法状态机,但都将可能有非生成的代码太)。

You might be able to do something similar with the [CompilerGenerated] attribute if its applied at the method level, but will get false positives when applied at the class level (the compiler applies it to state machines for iterators and async methods, but both will likely have non-generated code too).

这篇关于调试器StepInto自动生成的代码和JMC问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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