1

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

ds-bos-msk
  • 780
  • 9
  • 13

1 Answers1

1

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
}
Griffin
  • 716
  • 7
  • 25
  • 1
    You just said what to write in the conditional breakpoint's test. – Blindy Sep 12 '17 at 15:55
  • See that requires me to write code and recompile and then recompile again if I want to change the type of derived class. Right now the breakpoint condition I'm using is something like * (void**)ptr.get() != But this is very hacky and the pointer will likely change for the next run – ds-bos-msk Sep 12 '17 at 16:01
  • @bigD as Blindy suggested change your breakpoint condition in your IDE to `dynamic_cast(ptr)` – Griffin Sep 12 '17 at 16:07