[contents]
[usage]
[execution]
[stack]
[breakpoints]
[watchpoints]
[advanced]
5. How do I use watchpoints?Watchpoints are similar to breakpoints. However, watchpoints are not set for functions or lines of code. Watchpoints are set on variables. When those variables are read or written, the watchpoint is triggered and program execution stops. It is difficult to understand watchpoint commands by themselves, so the following simple example program will be used in the command usage examples.
How do I...?
5.1 How do I set a write watchpoint for a variable? [top]  [toc]Use the watch command. The argument to the watch command is an expression that is evaluated. This implies that the variabel you want to set a watchpoint on must be in the current scope. So, to set a watchpoint on a non-global variable, you must have set a breakpoint that will stop your program when the variable is in scope. You set the watchpoint after the program breaks. *NOTE* You may notice in the example below that the line of code printed doesn't match with the line that changes the variable x. This is because the store instruction that sets off the watchpoint is the last in the sequence necessary to do the 'x=y' assignment. So the debugger has already gone on to the next line of code. In the examples, a breakpoint has been set on the 'main' function and has been triggered to stop the program.
5.2 How do I set a read watchpoint for a variable? [top]  [toc]Use the rwatch command. Usage is identical to the watch command.
5.3 How do I set a read/write watchpoint for a variable? [top]  [toc]Use the awatch command. Usage is identical to the watch command. 5.4 How do I disable watchpoints? [top]  [toc]Active watchpoints show up the breakpoint list. Use the info breakpoints command to get this list. Then use the disable command to turn off a watchpoint, just like disabling a breakpoint.
[contents] [usage] [execution] [stack] [breakpoints] [watchpoints] [advanced] Questions? Comments? Flames? email rms@unknownroad.com |