Post by CathyHow can I set a breakpoint that stops the program when a variable has
changed its value?
You can set up to 4 hardware breakpoints that stop the program when
a particular memory address is written to. As such, they're not easy
to use if you're trying to breakpoint a variable on the stack, as the
stack's memory addresses are generally recycled from function to
function. To set a breakpoint, do the following:
1) Obtain the address you wish to breakpoint at. I generally do this
in DevStudio's watch window, adding an entry for "&g_SomeVariable".
You'll get an address like 0x12345678
2) In the breakpoints window (alt-F9), go to New -> New Data
Breakpoint. If you don't see the entry for "New Data Breakpoint",
then go to the main DevStudio Tools -> Options... -> Debugging, and
check [x] Enable Address-level Debugging. Once address-level debugging
is enabled, then go back to the breakpoints window.
Side note: with address-level debugging, DevStudio 2003/2005 has
the REALLY ANNOYING behavior for me of treating F10 (step over when
stopped) as a "go into the disassembly window and step one
instruction" instead. For me, it does that, even if I didn't have the
disassembly window open, and was staring at the source code. I have
to go turn off address-level debugging, and then DevStudio will get a
clue and *stay* in the source window and step one C/C++ line at a time
when I hit F10. Very frickin' annoying. Fix it, MS!
3) Anyhow, once you you've selected New Data Breakpoint, in the window
that appears, enter the address (e.g. 0x12345678) where specified, and
hit ok.
Side note - this can't be used to easily breakpoint memory that's
changed due to a file load or other times the OS writes to your
memory. I seem to remember that the OS has a different view of your
app's memory, so the address entered won't trip the breakpoints.
Nathan Mates
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein