Solved

setting breakpoint condition for variable value change

Posted on 2004-04-19
3
452 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
ID: 10864801
0
 
LVL 7

Accepted Solution

by:
vijay_visana earned 200 total points
ID: 10866193
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
ID: 10866849
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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