I have simple program:
#include <stdio.h>
void func(int i) {
i = 1;
printf("%d\n", i);
}
int main(int argc, char *argv[]){
func(0);
return 0;
}
and now:
gcc test.c -g -o test
gdb test
(gdb) b main
Breakpoint 1 at 0x400543: file test.c, line 9.
(gdb) run
Starting program: /tmp/test
Breakpoint 1, main (argc=1, argv=0x7fffffffe458) at test.c:9
9 func(0);
(gdb) s
func (i=0) at test.c:4
4 i =1;
(gdb) p i
$1 = 0
(gdb) n
5 printf("%d\n", i);
(gdb) p i
$2 = 0
(gdb)
Program works fine, shows "1", but why gdb shows me "0" value?
Debian wheezy.
I observed that on gcc-4.7, gcc-4.6. On gcc-4.4 all is ok.
This is a bug that is fixed if you compile with -fvar-tracking
. Your question is a tighter version of this SO question, which references a bug report on GCC 4.8.0 suggesting the above compile flag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With