Sign in to follow this  
Kest

Breaking on variable modification

Recommended Posts

Moderators, feel free to move this if it doesn't belong here. This is more of a compiler question than programming question. It is possible to use private data for every structure in your program, then use interface functions to modify the data. Then it's as simple as placing a break point in that interface function to see when it is modified. Is it possible to break on variable modification without going through all of this? I'm using C++ in Visual Studio.net version 7. I really appreciate any suggestions :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Yes. (Support is inconsistent, but if you're using VS on a Windows PC, it should work.) Go to the breakpoints window, create a new breakpoint (using 'New'). Click on the 'Data' tab, and enter the variable that you want to watch. In my experience:

1) Watching anything larger than 4 bytes is unlikely to work.
2) Watching things by name might not work. Instead, get the address of the variable you want, and put "*(int*)(0x12345678)" (replacing the address) into the box.
3) Setting more than one or two of these at a time will either not work, or make your app INCREDIBLY slow.

Still, highly useful once you know about it.

Share this post


Link to post
Share on other sites
That's great :)

It worked perfectly by setting "no condition" and "break always", even with the variable name. I couldn't ask for better help. You're my hero. Thanks AP!

Share this post


Link to post
Share on other sites
Yeah, this is invaluable for tracking down memory corruption. The "1..2" limitation is due to x86, which provides for 4 hardware (code or data) breakpoints. If you want more than this, VC is forced to single-step your program, thus explaining the slowdown.
These breakpoints can watch 1, 2 or 4 bytes, which accounts for that observation as well (although MS could have gone to the trouble of splitting larger variables into several "watchpoints").

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this