gdb displays wrong values for variables while debugging c code

Bug #1224651 reported by bhuvi
12
This bug affects 2 people
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.20130417-cvs-ubuntu

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.

Tags: gdb
Revision history for this message
bhuvi (bhuvanesh) wrote :
summary: - gdb displays wrong values for variables in c code
+ gdb displays wrong values for variables while debugging c code
Revision history for this message
Mathew Hodson (mhodson) wrote :

The verification-needed tag is added by the SRU team when the upload is approved in the -proposed pocket.

tags: removed: verification-needed
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in gdb (Ubuntu):
status: New → Confirmed
Revision history for this message
Matthias Klose (doko) wrote :

closing as invalid. please recheck with 14.04 LTS and 14.10, and re-open the issue if appropriate.

Changed in gdb (Ubuntu):
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.