Let's say I have some base class A and two derived classes B and C. Class A has some method called f().
Is there a way to set a conditional breakpoint in A::f() in visual studio which will be hit only when my 'this' is actually an instance of class C?
For example
void A::f()
{
some code and a breakpoint
}
void foo(A* a)
{
a->f();
}
void bar()
{
A a;
B b;
C c;
foo(&a); // breakpoint isn't hit
foo(&b); // breakpoint isn't hit
foo(&c); // breakpoint is hit
}
I've managed to achieve it by testing virtual table pointer in breakpoint's condition but there's got to be a better(more easy) way.
Thanks in advance.
EDIT: Modifying source code as was suggested in comments is not kind of a solution I'm looking for. It has to be done only by means of VC++ debugger.
Conditional breakpoints allow you to break inside a code block when a defined expression evaluates to true. Conditional breakpoints highlight as orange instead of blue. Add a conditional breakpoint by right clicking a line number, selecting Add Conditional Breakpoint , and entering an expression.
To set a conditional breakpoint just set a breakpoint as normal then right click on the breakpoint and select Breakpoint Properties. In the window that opens click Enable Conditional. Then type in counter (or some variable name) == 303 (or whatever value you want to set).
You can. First of all, determine address of virtual table of type you wish to check against. Then setup a breakpoint with condition like (arg).__vfptr != 0x01188298 where 0x01188298 is your type vtable's address. That's it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With