[Bug 1224651] [NEW] gdb displays wrong values for variables while debugging c code

bhuvi 1224651 at bugs.launchpad.net
Thu Sep 12 19:26:31 UTC 2013


Public bug reported:

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.

** Affects: gdb (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: gdb verification-needed

** Attachment added: "c source code used to find the bug. variable name which is displayed wrong - optind"
   https://bugs.launchpad.net/bugs/1224651/+attachment/3818298/+files/gdb_bug_rpt.c

** Summary changed:

- gdb displays wrong values for variables in c code
+ gdb displays wrong values for variables while debugging c code

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gdb in Ubuntu.
https://bugs.launchpad.net/bugs/1224651

Title:
  gdb displays wrong values for variables while debugging c code

Status in “gdb” package in Ubuntu:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gdb/+bug/1224651/+subscriptions




More information about the foundations-bugs mailing list