Welcome to MSDN Blogs Sign in | Join | Help

Sara Ford's Weblog

My adventures embracing open source on CodePlex and at Microsoft

News

    • Did you know... All author proceeds go directly to sending Hurricane Katrina survivors to college.

      Microsoft Visual Studio Tips book

      Recent Entries

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: ,
Posted: Tuesday, June 17, 2008 3:00 AM by saraford

Comments

Csabi said:

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

# June 17, 2008 9:49 AM

Kelvin said:

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

# June 17, 2008 10:08 AM

Serge Wautier said:

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.

# June 17, 2008 10:24 AM

John said:

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

# June 17, 2008 10:38 AM

Chris adf471587879rzq said:

FYI, the white "+" is present in VS 2005 as well.  Cheers!

# June 17, 2008 12:02 PM

Kirk said:

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

# June 18, 2008 8:09 AM

Graham said:

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?

# June 18, 2008 8:19 AM

Anastasio said:

Shouldn't it really be "You can make breakpoints conditional?".

A "conditional breakpoint" would be more like the ability to get the program to break when a condition is met at whatever line it happens on. Unfortunately, breakpoints must be set on a particular line, not a condition.

For example, I would like to set a breakpoint when a button on my form changed it's .enabled property to False, but I don't know when that happens (have many statements that can change it).

Maybe the next VS version?

Thanks for the great tips though!!

# June 18, 2008 4:01 PM

GregM said:

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.

# June 20, 2008 11:34 PM

Visual Studio Hacks said:

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

# June 22, 2008 1:33 PM

Greg Young said:

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

# June 23, 2008 6:28 PM

Alvaro said:

This is useful, but unfortunately it's not a complete solution.  What's missing is the ability to break when a certain condition is true on the line that caused it to be true.  Sometimes I spend a long time trying to figure out who changes a static variable.  It would be nice to just say, "whenever this condition is met, stop the program and show me who did it."  

Visual C++ had this feature ages ago!

# July 16, 2008 4:16 PM

xjb said:

# January 7, 2009 8:40 PM
New Comments to this post are disabled
Page view tracker