Tuesday, February 14, 2012

GDB: Changing/Modifying value of the variable

while doing debegging the application using GDB, at the run time variable values can be changed for easy debugging. Assume the there is while loop repeating for 100 times, but if you want to chech the values at 77th iteration. doing step by step will take lot of time and its not a good practice. using the set GDB command we can get this.see the example below

(gdb) p x
$1 = 10
(gdb) set var x = 20
(gdb) p x
$2 = 20
(gdb) set var x = 30
(gdb) p x
$3 = 30
(gdb) set var x = -6
(gdb) p x
$4 = -6
(gdb) p &x
$5 = (int *) 0x7fffffffdc9c
gdb) set {int }0x7fffffffdc9c = -7
gdb) p x
$6 = -7

For changing the variable value, use the set command with var as parameter saying to the GDB that x is a variable. In the above example, in line 14, changed the value of x using address also.

No comments:

Popular Posts