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

Started by
5 comments, last by BCullis 15 years, 5 months ago
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.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

Advertisement
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.
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
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]
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."

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

Make sure the program is running in the debugger when you try adding the data breakpoint.
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

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

This topic is closed to new replies.

Advertisement