Breakpoints that conditionally break when a pointer to a base class points to a specific subclass

1.2k Views Asked by At

Is there any proper way to set a conditional breakpoint in Visual Studio 2015 such that it breaks whenever a pointer to a base class points to a specified subclass type? (see example screenshot below)

I don't want to have to spend time writing debug utility code for this, nor do I want to hack virtual table data.

enter image description here

1

There are 1 best solutions below

3
On BEST ANSWER

Two ways to do it:

Add below as your breakpoint condition in your IDE:

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

Or add below code to your code and compile:

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