2.3 The ‘set’ and ‘print’ commands
Once a debugger pauses at an executable statement, one can read or modify the
value of any live variable at that point. It is also possible to evaluate an arithmetic or
logical operation over the live variables.
Set variables in GDB
-
1.
- In GDB, the content of a variable can be read and printed on the console
using the ‘print’ command. Back to the example from Figure 5, the value
of size at line 46 is 0 (Figure 13).
-
2.
- One can alter the value of a live variable while the program execution is
paused at a breakpoint. For example, after the breakpoint in the push
function, we can manually insert the square of the argument in the current
index and push the argument in the next index. Figure 14 shows how the
value array[size] and size are set.
Set variables in Visual Studio
-
1.
- One can change a variables value through ‘Autos’ window. Once the
program execution is paused on a breakpoint, like the one in the push
function, all live variables can be read or modified through ‘Autos’
window. For example, we can by altering the value of v we can insert 20
instead of 10 in the stack. Figure 15 shows modification and Figure 16
shows the result.