setting breakpoint condition for variable value change

C++,MFC, VS.NET.
I have a variable that is setting itself back to 0 at some point in my code.  I have not been able to find that point.  I tried setting a breakpoint based on a change in the variable's value, but could not get that to work.  I don't understand how to set the 'context' properly in the breakpoint dialog box.  I referred to help, but I still don't think that I am setting it up properly.  

I start a new breakpoint, go to the Data tab, and set the variable name, language, item count, and condition.  What must be specified in the Context?  I think this is the part that I am missing.

Thanks
je
jesterepsilonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bkfirebirdCommented:
0
vijay_visanaCommented:
ALT+F9
goto data tab
put following string with condition in expression list

{main,testcondefprinter.cpp,testcondefprinter} c == 2


//Here main is name of function.
//testcondefprinter.cpp is name of file. -file where variable is declared
//testcondefprinte is name of executable.
//c == 2 is name of variable

as you know the variable you must know the scope of that variable I mean in which file it is declared etc.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aphillipsCommented:
The 'context' property is documented in the help index under "context operator in debug expressions".

However, I have tried the "Data" breakpoint facility (mainly in earlier versions of Visual Studio) and never been able to get anything useful from it.  First it makes the program run incredibly slow because it has to check the variable after executing each line of code.  (I also think it checks after every single machine instruction if it can't find the source code!)

Also I think there are/were bugs in the debugger that meant it gave spurious results (both bogus finds, and missed ones).  Also the slowness of running can affect the behaviour of the program (eg, order that Windows events are received) so the problem may disappear.  Even if it works it may be due to a bad pointer and you might have to repeat the whole process (several times) to find the root cause.

You might instead try searching for all places the variable is modified and setting breakpoints there.  Of course, this will not find problems such as bad pointer bugs, in which case you could try a product such as Purify or Bounds Checker (although in my experience they don't always work either).  If you don't have access to those (or they find nothing) also:

1. Add TRACE statements at crucial places in the code.  (You should have some idea of where the problem is?)

2. Add TRACE statements before and after recent code changes if the problem has just appeared.

3. Turn on Buffer Security Check (Properties\C/C++\Code Generation) if it is an auto (local) variable.  (This is off by default in debug builds.)

4. Try setting normal (code) breakpoints at various places with a Condition like "var==0".

Note: If it is a member variable it might be useful to check the value whenever you execute a member function.  It is easy to set a breakpoint on all member functions by entering the class name in the Function: box in the New Breakpoint dialog (Function page).  Visual Studio then displays a list of member functions - just click the "All" button to set breakpoints on all of them. (Don't forget to click the "Condition" button first and set the condition as mentioned above.)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.