Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set a conditional breakpoint in base class method which triggers only if it's an instance of specific derived class?

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.

like image 975
Serge Avatar asked Jul 07 '11 14:07

Serge


People also ask

What is a conditional breakpoint?

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.

How do I apply conditional breakpoints in eclipse?

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).


1 Answers

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.

like image 138
TechPriest Avatar answered Oct 08 '22 16:10

TechPriest