Solved

setting breakpoint condition for variable value change

Posted on 2004-04-19
3
455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 58
Looking for a specific application/software 2 119
string initialization in java 11 117
ffmpeg - "rtsp://...... Operation not permitted" 4 89
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

761 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