Jump to content
  • Advertisement
Sign in to follow this  
Kest

Breaking on variable modification

This topic is 4633 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!