Solved

setting breakpoint condition for variable value change

Posted on 2004-04-19
3
449 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:jesterepsilon
3 Comments
 
LVL 4

Assisted Solution

by:bkfirebird
bkfirebird earned 100 total points
Comment Utility
0
 
LVL 7

Accepted Solution

by:
vijay_visana earned 200 total points
Comment Utility
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
 
LVL 3

Assisted Solution

by:aphillips
aphillips earned 200 total points
Comment Utility
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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 74
maxBlock challenge 30 99
if loop in java 3 113
Making an alias 7 49
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now