c# - 执行路径特定断点

标签 c# c++ visual-studio breakpoints callstack

我希望 Visual Studio 调试器在调用来自特定的调用者序列时在函数内中断。有没有办法设置这样的断点?或者也许是一些替代黑客?

我在 native (C++) 和托管 (C#) 代码的上下文中问这个问题。

最佳答案

我想你可以设置一个 conditional breakpoint利用 System.Diagnostics.StackTrace类。

编辑:GrayWizardx 在评论中指出这可能是不可能的。在这种情况下,您可能会导致您的代码以编程方式中断:

#if DEBUG
    // Use StackTrace class in this conditional to determine whether or not to break:
    if (yourConditionIsTrue)
    {
        System.Diagnostics.Debugger.Break();
    }
#endif

关于c# - 执行路径特定断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1932061/

相关文章:

c# - 如何用多个线程写入单个文件?

c# - 在 C# 中使用 Timer 触发 Action

c# - 在独立应用程序上使用 ADFS 进行 Windows 身份验证

asp.net-mvc - 构建错误 - 'System.Web.Mvc.ModelClientValidationRule' 冲突

visual-studio - 将 Visual Studio 与 Git 结合使用时要忽略的文件

c# - 将字节数组上传到 HTTP 服务器

c++ - is_const 不能按预期工作以供引用

c++ - 新变量的可访问性( "new"的范围)

c++ - 相同代码在不同设备上的不同行为

c++ - 什么是 “pch.h”,为什么需要将其作为第一个头文件包含在内?