We can add a watchpoint for a variable or a field so that whenever its value changes, the debugger stops. Each watch item is assigned a number that can be used to delete it from the watch list, using the unwatch command:
- watch var: Sets watchpoint for variable var
- unwatch [n]: Unsets the watchpoint specified with number n
Let's set the watchpoint for the variable result in our program calc.awk, which is being debugged, as follows:
gawk> watch resultWatchpoint 4: result
Here, we have set the watchpoint for the variable result, so during execution, whenever its value changes, the debugger will give a notification and stop there.