Sign in to follow this  
BCullis

[C++] Debugging assistance with Visual C++ 2008 EE

Recommended Posts

BCullis    1955
Hello again all, I'm currently working on a simple array-usage program, but any time the program loops through, a specific value in the main 2-dimensional array gets changed. I'm having trouble catching exactly where (or why) that value is changing, but I've added a line to my code to tell me the value of that "cell" at the end of each run-through of the program's main loop, so I do know it's getting changed and not just failing to print. My question is then this: is there a way for me to flag that cell in the array so I can catch where in the program it's getting changed? I don't know if there's an easy debug option to do this(I see a "conditions" column in the breakpoints tab of the IDE, but can only seem to set breakpoints on functions themselves) or some bit of code I could add that checked for a change in value. Any ideas or input would be greatly appreciated, as always.

Share this post


Link to post
Share on other sites
SiCrane    11839
When your program is running you can set a data breakpoint to trip when memory at a certain address is changed. From the debug menu you can select "New Breakpoint" and then "New Data Breakpoint" to create one.

Share this post


Link to post
Share on other sites
Malal    118
You should be able to set a data breakpoint.

While the program is running put a watch on your array and get the address of the array item you want know about, I use VS 2005 so I would then click Debug->New Breakpoint->New Data Breakpoint and put the address in there.

The program should now break anytime the data at that address is changed.

Hope this helps

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by BCullis
Hello again all,

I'm currently working on a simple array-usage program, but any time the program loops through, a specific value in the main 2-dimensional array gets changed. I'm having trouble catching exactly where (or why) that value is changing, but I've added a line to my code to tell me the value of that "cell" at the end of each run-through of the program's main loop, so I do know it's getting changed and not just failing to print.

My question is then this: is there a way for me to flag that cell in the array so I can catch where in the program it's getting changed? I don't know if there's an easy debug option to do this(I see a "conditions" column in the breakpoints tab of the IDE, but can only seem to set breakpoints on functions themselves) or some bit of code I could add that checked for a change in value.

Any ideas or input would be greatly appreciated, as always.
Yup, you want a memory watchpoint. I don't have VC2008 here, but it'll be similar to VC2005. In VC2005:
1. Start debugging, and put a breakpoint on the line after the array entry is given it's initial value.
2. Go to Debug -> New breakpoint -> New Data Breakpoint
3. In "Address" enter &your_array[123][456] (Obviously the array name and index that changes), and make sure "byte count" is set to the size of one array element (4 for a 32-bit int).
4. Hit F5 to continue running. You should break to the debugger when that memory address is written to.


EDIT: Waaaaay too slow [smile]

Share this post


Link to post
Share on other sites
BCullis    1955
Thanks all, now I've run into a new snag: the option for "Data Breakpoint" is greyed out. Is this a fallback of using the EE version of Visual Studio? I'm googling around but so far haven't found a definite "this is not available in such-and-such version of VS."

Share this post


Link to post
Share on other sites
BCullis    1955
Aha, thanks SiCrane, between that and reading Evil Steve's steps more closely, I was able to make it work. Now the hard part: fixing the problem the debugger pointed out XD

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