gdb displays wrong values for variables while debugging c code
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gdb (Ubuntu) |
Invalid
|
Undecided
|
Unassigned |
Bug Description
Hi,
gdb shows wrong values for variables when displayed through "print <variable name>" command. Although it is not the case always and I cannot figure out under what circumstances this happens.
I checked the value of the variable by adding printf command directly in the code, the actual value printed to stdout is correct. Only the gdb shows wrong value.
Environment details :
Linux mint 15 (based on Ubuntu 13.04)
gdb version :
GNU gdb (GDB) 7.5.91.
gdb configuration:
"i686-linux-gnu"
steps to reproduce the bug:
compile the attached c source code (source code is a simple demo of getopt_long function) using,
gcc -o gdb_bug_rpt gdb_bug_rpt.c -g -Wall -pedantic
run the code using gdb
gdb ./gdb_bug_rpt
cmds given below are gdb commands,
(gdb)break main
(gdb)run -o file1 file 2 file3
(gdb)next
...
(gdb)next (step through the code until line -- printf ("value of optind = %d\n", optind);
now check value of optind variable using print cmd
(gdb)print optind
gdb will display the value to be 1, but the actual value is 3 ,which you can see by executing the printf line.
Also the value of optind is assigned to variable i.you can also check the value of i using print i after executing the foe loop for the first time. the value of i is also found to be 3.
But gdb displays wrong values to the user.
The verification-needed tag is added by the SRU team when the upload is approved in the -proposed pocket.