Archived

This topic is now archived and is closed to further replies.

TroneX

Debugging: Breakpoints with Conditions ?

Recommended Posts

Hello community! Everyone working with VS will have noticed, that when setting breakpoints, there is a possibility of defining conditions when to break and when not. Those conditions can either been defined as a something to evaluate or through a hit count meaning that for instance this breakpoint will break into the code the 2nd time it is hit. But how do I get this actually to work? For example: Imagine thousands of lines of code in really a lot of different files and classes. Now image one class called CGameInput (e.g.) having a member called m_pid which contains data about the players state (whether he moves left, right, and so on ...) What I would like to do is settings a breakpoint this way, that the debugger breaks exactly when CGameInput->m_pid.bMovingRight changes to 1. I expect the debugger to break in the exact line which causes this variable to change. Furthermore, I am hoping that with this feature, also errors could be found. For example: Assume that you have a variable which changes its value but it is not supposed to do that. There isn''t even the slightest possibility that you implemented code chaning this variable. But it does though. How could this happen? Maybe, because you are accessing an array out of bounds or write too much text into a string which is not supposed to hold such a long text ... in those cases, your variable could have been overwritten. I know this is not supposed to happen. But sometimes it does, so could this debugger feature help to find something like this? And how the hell does it work? Regards, Chris.

Share this post


Link to post
Share on other sites
quote:
Original post by TroneX
... For example: Assume that you have a variable which changes its value but it is not supposed to do that ... so could this debugger feature help to find something like this? And how the hell does it work?


This type of breakpoint is very handy for finding out when or why a value is changed.

Share this post


Link to post
Share on other sites
That''s the point. But how does it work?

How exactly do I set a breakpoint, so that the debugger breaks when a specific variable changes its value?

Share this post


Link to post
Share on other sites
Data breakpoints can be used by entering the New Breakpoint dialog and typing the variable name in the data tab (in MSVC .NET anyways, it might be different in MSVC 6). There are limitations on data breakpoints. IIRC, they can only be applied to global variables or local variables at the top most scope of a function. Look up "data breakpoints" in your debugger documentation for more information.

Share this post


Link to post
Share on other sites