4

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.

Nips
  • 13,162
  • 23
  • 65
  • 103

1 Answers1

7

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.

Community
  • 1
  • 1
David Duncan
  • 1,225
  • 8
  • 14