开发者

Can I define a variable in Visual Studio debugger?

I am wondering if I could开发者_如何学JAVA 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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜