Conditional Debug on Visual C++ 2008 Express

2019-08-10 08:06发布

问题:

Is there a way to debug code on Visual C++ 2008 Express, such as I can watch a variable for certain value(s) and, when it assumes this value, to break?

For instance, I want to break when xbecomes 5. In gdb I would set a breakpoint then a condition that x == 5. How can I do it (if possible) on Visual C++ 2008 Express?

回答1:

Although built in support for it is missing in the express editions, there is another way around it.

I found this on another answer for a similar question.

#if DEBUG
if( node.Name == "Book" )
    System.Diagnostics.Debugger.Break();
#endif

The example shows that if the Name property matches "Book", a breakpoint occurs.

Here is the original question:

How Do I: Create a Breakpoint Using Conditions? [C# Express]



回答2:

This is not possible in the Express versions of Visual Studio. But it is possible in the full versions.



回答3:

It seems it's possible to do this even in express, at least here it worked. After marking the breakpoint, I right-clicked on its mark, and set a "Condition" (it couldn't be easier than that)

!Setting a condition

Then you can write an expression which evaluates to true. My colleague who has just showed this to me said they have some issues using this for comparing strings, but it's pretty neat for simple comparisons using ints.

!Condition window

However, as said in the other answer, this is not so fast as typing the break code directly.



回答4:

Lucky! Visual Studio 2010 Express of C/C++ does support it. See How to: Specify a Breakpoint Condition.

I've tried it.