views:

120

answers:

4

Is there is a tool or a setting in the debugger to stop on the break point or if variable is set to a particular value? I mean if I know that value will be set to "HELLO" then the debugger will stop or do the same if it reached some break point in the loop? Any advise would be helpful!

+2  A: 

there are watchpoints.

bhups
+7  A: 

You're looking for a Conditional Breakpoint.

Dave Swersky
+4  A: 
  1. Set a breakpoint anywhere in code.
  2. Enable the list of breakpoints window by going to Debug menu -> Windows -> Breakpoints.
  3. In your breakpoints window, right click on a breakpoint
  4. Select Condition...
  5. Enter any expression involving your variable

The breakpoint will be hit when the condition is met.

Via the right click on breakpoints menu, you can also set breakpoints:

  • Only from certain processes or threads
  • Upon hit counts
  • Only when a condition or variable is changed
Brian R. Bondy
Can you do string comparisons there?
jeffamaphone
You can try and if it doesn't work you can for example only set a value to true in code when it's equal, and then use that as your condition.
Brian R. Bondy
+2  A: 

Daves answer.

And I'll add that you can just add a if statement that contains a couple of dummy statements and you put a breakpoint inside it. It does the same thing.

Typical use :

if (i == 250) {
 int dummy = 2+2;  //breakpoint here
}

In your case, since you watch the value of a string (assuming C++ strings)

if (mystring == "hello")
{
  int dummy = 2+2; //breakpoint here
}
toto
Or use DebugBreak() to break into the debugger and skip the dummy statement.
jeffamaphone
Cool, I didn't know that. Ty.
toto