Breaking when a value in memory changes... Tracking down a 'walk'
Hi. I''ve got a game of checkers that I am working on and in this game, the board owns 24 checkerpieces. Each of these pieces is an object that owns a BOOL bCrowned variable.
When a checkerpiece gets to the far edge of the board, a function is called on the checkerpiece object to ''crown'' it. The function sets bCrowned = TRUE.
Whenever a checkerpiece is asked to move, the direction it can move is restricted based on the bCrowned variable.
Anyway, I can take a checkerpiece all the way to the far edge and it gets crowned. Then it will usually move backwards from the far edge for at least one or two moves, sometimes more. But somehow it gets ''uncrowned''. My guess is that something is overwriting my variable in memory (doh!) and stomping my bCrowned with a 0.
I was wondering if MSVC6 has a feature whereby I can trigger a breakpoint when my variable''s value gets changed, whether via a proper piece of code or via a memory walk.
Anyone know what I should do?
I don''t know of an easy way to break the program if the value changes, however I know of a round-a-bout way. Just for testing, make bCrowned a pointer, and allocate memory for it using
If there happens to be something writing into your memory, it will trigger an access violation trying to write into read-only memory.
That''s the best I can think of. I''m sure there is something in MSVC, but I haven''t found it yet Something like a "break on change!"
VirtualAlloc
. Then use VirtualProtect
to only give read-only access to the memory. Whenever you want to change the value, use VirtualProtect
to give write access, do the write, and then protect it again.If there happens to be something writing into your memory, it will trigger an access violation trying to write into read-only memory.
That''s the best I can think of. I''m sure there is something in MSVC, but I haven''t found it yet Something like a "break on change!"
Well, I found the problem by just watching the variable and stepping through my code. Luckily the problem was in the code that I could step through easily while being able to watch the variable.
It is too bad MSVC doesn''t have that break on change functionality. I have seen it elsewhere, I think maybe in the Tornado debugger (WindRiver product). Basically I could give it a location in memory and tell it to break if the value at that location changed.
It is too bad MSVC doesn''t have that break on change functionality. I have seen it elsewhere, I think maybe in the Tornado debugger (WindRiver product). Basically I could give it a location in memory and tell it to break if the value at that location changed.
MSVC 6 does have break on variable change. In fact, you can even break when an arbitrary expression evaluates to an arbitrary value.
[edited by - Mastaba on March 8, 2003 7:48:18 PM]
[edited by - Mastaba on March 8, 2003 7:48:18 PM]
Open the breakpoints windows (Edit->Breakpoints) you can set a data break point on the Data tab.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement