ds-bos-msk
ds-bos-msk

Reputation: 772

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

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

Upvotes: 1

Views: 1368

Answers (1)

Griffin
Griffin

Reputation: 766

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
}

Upvotes: 1

Related Questions