views:

48

answers:

2

Hi, guys. I am wondering if I could define a variable during debugging in visual studio. For instance, I want to know how many times the breakpoint was hit when some flag was true. This rquirement seems need more advanced programmable skill to visual studio debugger.

Visual studio conditional breakpoint can only satisfy partial requirement.

A: 

Why don't you use a IFDEBUG kind of flag and conditional compiling?

Kangkan
+1  A: 

To determine the hit count of a break point, set the required hit count of break point to a very high value which you don't expect to be reached.

Then you can examine the break point's current hit count by hovering the break point icon on the left or by right-clicking it and then chosing "Hit Count..." again.

int c3 = 0;
int c5 = 0;
for(int i = 0; i < 100; ++i)
{
    if(0 == i % 3)
    {
        ++c3; // Set break point with hit count 1000 here
    }

    if(0 == i % 5)
    {
        ++c5; // Set normal break point here
    }
}

In the above example, when you reach the normal break point, you can examine the hit count of the other break point.

mxp