I would like Visual Studio debugger to break within a 开发者_运维知识库function only when the call is from a specific sequence of callers. Is there a way to set such a breakpoint? Or perhaps some alternative hack?
I ask this in the context of native (C++) as well as managed (C#) code.
I think you could set a conditional breakpoint that utilizes the System.Diagnostics.StackTrace class.
EDIT: GrayWizardx has pointed out in a comment that this may not be possible. In that case you could cause your code to break programmatically:
#if DEBUG
// Use StackTrace class in this conditional to determine whether or not to break:
if (yourConditionIsTrue)
{
System.Diagnostics.Debugger.Break();
}
#endif
精彩评论