Partager via


Did you know… You can set conditional breakpoints? - #239

This was tip #16 for my TechEd VS IDE Tips and Tricks talk.

I believe this has been around since 2005, but maybe the white ‘+’ is new for 2008?

When you only want to break under certain conditions, you can right-click on a breakpoint red circle (or go to the Breakpoints Window and bring up the context menu on a given breakpoint) and select Condition to bring up the dialog box for conditional breakpoints. 

Conditional Breakpoints on Context Menu

You’re given two options: break only when the specified expression is true or break only when the specified value has changed.  For this example, since I’m in a for loop, i’ll break when the value of i > 5.

breakpoint condition message box

You’ll notice that the breakpoint circle now has a red plus on it to indicate it is conditional.

conditional breakpoint icon

Technorati Tags: VS2005Tip,VS2008Tip

Comments

  • Anonymous
    June 17, 2008
    How about strings? How can I set a condition on a string variable, e.g. I want to stop when strTmp == "User3"?

  • Anonymous
    June 17, 2008
    Great post Sara. The white "+" is also in VS2005, but it only shows up when using the "Is True" option.

  • Anonymous
    June 17, 2008
    around since 2005? Mind you, I think Turbo C++ 2.0 already had conditional breakpoints circa 1988. And Visual C++ 4.1 (The first version I used) for sure had them. The + is indeed a nice cosmetic... plus.

  • Anonymous
    June 17, 2008
    Thanks!  I wish I would've known about this one a long time ago!  FWIW, the white '+' is in 2005.

  • Anonymous
    June 17, 2008
    FYI, the white "+" is present in VS 2005 as well.  Cheers!

  • Anonymous
    June 18, 2008
    Hi everyone, Remember to use == for a comparison, not just a single =. I spent ages trying to figure out how one of my variables was being updated! :) Kirk

  • Anonymous
    June 18, 2008
    I have VS2008Express... i only get two options when i right click a breakpoint - disable and remove. Is this not in express?  or only in express SP1?

  • Anonymous
    June 18, 2008
    The comment has been removed

  • Anonymous
    June 20, 2008
    Anastasio, you can set data breakpoints in VC++ (break when this variable changes, break when this address changes), not sure about about form control properties.

  • Anonymous
    June 22, 2008
    My latest in a series of the weekly, or more often, summary of interesting links I come across related to Visual Studio. I've been on vacation in Alaska for 10 days so this is an extra long list of links. Sara Ford: Tip of the Day #236 covers the file

  • Anonymous
    June 23, 2008
    This is quite useful but be wary that the way this works is you still actually hit a breakpoint long enough for the expression to be evaluated by the debugger. This is important when you deal with code that is in a tight loop as it will be incredibly slow ... To work around this you will tend to have to write your conditional right into your code. Greg

  • Anonymous
    July 16, 2008
    The comment has been removed

  • Anonymous
    January 07, 2009
    本篇包括tip231-tip240 http://www.watch-life.net/visual-studio/visual-studio-2008-tip-day-24.html #23...