【问题标题】:Breakpoints that conditionally break when a pointer to a base class points to a specific subclass当指向基类的指针指向特定子类时有条件中断的断点
【发布时间】:2017-09-12 15:43:54
【问题描述】:

是否有任何适当的方法可以在 Visual Studio 2015 中设置条件断点,以便在指向基类的指针指向指定的子类类型时中断? (见下面的示例截图)

我不想为此花时间编写调试实用程序代码,也不想破解虚拟表数据。

【问题讨论】:

    标签: c++ oop debugging visual-studio-2015 conditional-breakpoint


    【解决方案1】:

    两种方法:

    在 IDE 中添加以下作为断点条件:

    dynamic_cast<DerivedClassYouWantToBreak*>(ptr.get())
    

    或将以下代码添加到您的代码中并编译:

    if (dynamic_cast<DerivedClassYouWantToBreak*>(ptr.get()))
    {
        int breaksHere = 0; // put breakpoint here
    }
    

    【讨论】:

    • 你刚才说条件断点的测试要写什么。
    • 如果我想更改派生类的类型,这需要我编写代​​码并重新编译,然后再次重新编译。现在我使用的断点条件类似于 * (void**)ptr.get() != 但这非常hacky,指针可能会在下一个运行
    • @bigD as Blindy 建议将 IDE 中的断点条件更改为 dynamic_cast&lt;DerivedClassYouWantToBreak*&gt;(ptr)
    猜你喜欢
    • 2015-08-12
    • 2011-05-03
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    • 2016-02-19
    • 2015-05-03
    相关资源
    最近更新 更多