开发者

VSX: Programmatically disabling breakpoints at runtime

开发者 https://www.devze.com 2022-12-15 12:36 出处:网络
How can breakpoints be enabled or disabled at runtime?I\'m writing a test workbench application that can run other .net code for the purposes of debugging plugins.The workbench app itself is not debug

How can breakpoints be enabled or disabled at runtime? I'm writing a test workbench application that can run other .net code for the purposes of debugging plugins. The workbench app itself is not debuggable (DebuggableNonUserCodeAttribute) but the user code that it calls should be. But then, under certain circumstances at runtime, the user code breakpoints should not be honored.

I can imagine various ways of achieving this, many may not be possible:

1) Attach and detach the debugger programmatically

2) Enable and disable all breakpoints programmatically (preferably localized to an assembly or class)

3) Dynamically decorate and undecorate methods with the DebuggableNonUserCodeAttribute at runtime.

4) Somehow mark an entire code branch of a thread beyond a chosen stackframe as "non-breakpointable" for the debugger. DebuggableNonUserCodeAttribute only seems to work within a method or 开发者_高级运维class, but does not affect downstream code debuggability.

EDIT: To clarify: during runtime, the same piece of end user code will be run multiple times by the hosting executable, some where breakpoints should be honored and other times when they shouldn't be. It would be inappropriate to require that the user modify their code for this feature or that they be required to set conditional breakpoints.


You can do both #1 and #2 through the Debugger portion of the DTE automation object model.

How to enable/disable Breakpoints via DTE

How to attach the debugger via DTE


You could use System.Diagnostics.Debugger.Break() instead of setting breakpoints. Just put the method call inside whatever if blocks would be necessary.

0

精彩评论

暂无评论...
验证码 换一张
取 消