调试时跳过说明? [英] Skipping instructions when debugging?

查看:193
本文介绍了调试时跳过说明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PropertyGrid和新的.NET Framework 4.6开发WindowsForms应用程序。我的自定义控件具有PrepareReadOnlyBrowsableProperty方法来修改其属性的'Readonly'和'Browsable'属性:



  protected   void  PrepareReadOnlyBrowsableProperty( string  propertyName,
bool readOnly, bool 可浏览)
{
PropertyDescriptor descr = TypeDescriptor.GetProperties( .GetType())将[PropertyName];

// ReadOnly
var attr =(ReadOnlyAttribute)descr.Attributes [ typeof (ReadOnlyAttribute)];

FieldInfo field = attr.GetType()。GetField( isReadOnly
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);

field.SetValue(attr,readOnly);

// 可浏览
var attr3 =(BrowsableAttribute)descr.Attributes [ typeof (BrowsableAttribute)];

FieldInfo field3 = attr3.GetType()。GetField( browsable
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);

field3.SetValue(attr3,browsable);
}





问题如下。当我尝试按步骤( operands 指令)调试上述方法时,调试器在第一行停止,然后跳转到var attr3 = ...行。为什么会发生这种情况(跳过几个操作数指令)?



在我的应用程序的Build页面中,配置设置为Active (Debug),复选框Define DEBUG constant被选中,复选框Define TRACE constant被选中,复选框'Optimize code'被UNCHECKED(关闭)。



提前谢谢。

解决方案

如果调试出错(如上所述),我通常采用这种方法:

1)关闭并重新启动Visual Studio,重建解决方案,再次尝试调试

2)如果没有成功,检查每次创建生成的PDB文件是否

3 )如果是这种情况,请检查项目设置中的调试选项卡:是否启动位于旧/无PDB文件所在位置的外部程序

4)如果您尝试调试到每次都不从源重建的库,库可能被编译为optim ized和PDB也匹配优化的代码 - 即在调试器中更进一步,因为控制流的顺序可能已经改变...

5)如果库是重建的一部分,它可能仍然可以通过优化设置进行重建。如果在Debug中重建,请参阅解决方案的Configuration Manager设置。将所有相关项目重建为Debug。

6)检查工具 - 选项 - 调试:如果您有其他源路径集,即源可能是旧的



注意:PDB文件包含将IL指令映射到源行号的信息。如果此关系中的任何内容被破坏(过时的PDB,引用过时的来源等),则调试器无法显示正确的源级别信息。您也可以在反汇编级别进行调试。默认情况下,您会看到源和CPU指令交错。即使您不理解CPU指令,您也可能会看到代码是否正在使用。



问候

Andi

I am developing a WindowsForms application, using the PropertyGrid and new .NET Framework 4.6. My custom control has the PrepareReadOnlyBrowsableProperty method to modify 'Readonly' and 'Browsable' atrributes of its properties:

protected void PrepareReadOnlyBrowsableProperty(string propertyName,
                                                bool readOnly, bool browsable)
{
PropertyDescriptor descr = TypeDescriptor.GetProperties(this.GetType())[propertyName];

// ReadOnly
var attr = (ReadOnlyAttribute)descr.Attributes[typeof(ReadOnlyAttribute)];

FieldInfo field = attr.GetType().GetField("isReadOnly",
                  System.Reflection.BindingFlags.NonPublic |                                               
                  System.Reflection.BindingFlags.Instance);

field.SetValue(attr, readOnly);

// browsable
var attr3 = (BrowsableAttribute)descr.Attributes[typeof(BrowsableAttribute)];

FieldInfo field3 = attr3.GetType().GetField("browsable",
                                       System.Reflection.BindingFlags.NonPublic |  
                                       System.Reflection.BindingFlags.Instance);

field3.SetValue(attr3, browsable);
}



The problem is the following. When I try to debug by steps (operands instructions) the above-mentioned method, the debugger stops at the first line, and then jumps to the line "var attr3 = ...". Why does it happen (several operands instructions are skipped)?

In the Build page of my application, the configuration is set as "Active (Debug)", the checkbox "Define DEBUG constant" is checked, the checkbox "Define TRACE constant" is checked, and the checkbox 'Optimize code' is UNCHECKED (turned off).

Thank you in advance.

解决方案

If debugging goes wrong (as you describe above), I usually go this approach:
1) close and restart Visual Studio, rebuild the solution, try debugging again
2) if no success, check if the produced PDB file is created every time
3) if this is the case, check the debug tab in the project settings: do you start an external program that is located elsewhere where old/no PDB file is located
4) if you try to debug into a library that is not rebuilt from source every time, the library might be compiled as optimized and the PDB also matches the optimized code - i.e. step further in the debugger, since the sequence of control flow might have changed...
5) if the library is part of the rebuild, it might still be rebuild with optimizing settings. See the Solution's Configuration Manager settings if you rebuild in "Debug" rebuilds all dependent projects as "Debug" too.
6) Check in the tools - options - debugging: if you have an alternative source path set, i.e. the sources might be "old" ones

Note: the PDB file contains information that maps IL instructions to source line numbers. If anything in this relation is broken (out-dated PDB, references to out dated sources, etc.), then the debugger cannot display proper source level information. You might debug in Disassembly level too. By default, you see the sources and the CPU instructions interleaved. Even if you don't understand the CPU instructions, you might see if the code is in use.

Regards
Andi


这篇关于调试时跳过说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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