避免对 C# 中的一段代码进行调试和调用堆栈
在 Delphi 中,编译器指令 {$d-} 和 {$l-} 允许您有效地避免为定义的代码部分生成调试和局部变量信息。
在实际问题中,具有从调试视图中“隐藏”代码的效果,它不会出现在调用堆栈中,并且您在调试时不会单步进入它。
有没有办法使用 VS 2008 在 C# 中达到相同的结果?
注意:原因是我们有一个稳定的框架,不需要调试,但往往会弄乱调用堆栈和标准调试流程。
In Delphi the compiler directives {$d-} and {$l-} allow you to effectively avoid generation of debug and local variable information for a defined section of code.
In a practical matter that has the effect to "hide" the code from the debug view, it doesn't appear in the call stack and you don't step into it while debugging.
Is there any way to achieve the same result in c# using VS 2008?
Note: The reason is we have a stable framework which does not need to be debugged but tend to mess up with the call stack and with the standard debug flow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用 DebuggerNonUserCodeAttribute 这样默认情况下就不会中断或单步执行代码;但是,与 DebuggerStepThrough 相比,这样做的好处是您可以转到“选项”->“调试器”->“仅我的代码”设置,并允许中断/调试您标记的代码。如果您遇到问题,这会很有帮助。我通常在整个课程中使用它。
顺便说一句,调用堆栈将自动隐藏标有此属性的非用户代码:)
当然,您可以简单地右键单击调用堆栈窗口并切换“显示外部代码”来隐藏/显示丢失的堆栈信息。
I use DebuggerNonUserCodeAttribute so that you by default do not break or step into the code; However, the benifit to this over DebuggerStepThrough is that you can go to the Options->Debugger->Just My Code setting and allow breaking/debugging of the code you marked. This helps significantly if you have issues. I typically use it on entire classes.
BTW, the call stack will automatically hide non-user code as marked with this attribute :)
Of course you can simply right-click the call stack window and toggle "Show External Code" to hide/show the missing stack information.
我认为您想要
DebuggerStepThrough
属性:DebuggerStepThrough
指示调试器单步执行代码而不是单步执行代码。这对于 setter/getters 特别有用,因为调试这些通常只会增加噪音(来自 msdn 的示例):
I think you want the
DebuggerStepThrough
attribute:DebuggerStepThrough
instructs the debugger to step through the code instead of stepping into the code.This is especially useful for setters/getters since debugging into those usually just adds noise (example from msdn):
或者跳过代码的特定部分:
Or to skip a specific section of the code: