4

我有简单的程序:

#include <stdio.h>

void func(int i) {
    i = 1;
    printf("%d\n", i);
}

int main(int argc, char *argv[]){
    func(0);
    return 0;
}

现在:

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)

程序运行良好,显示“1”,但为什么 gdb 显示“0”值?

Debian 喘不过气来。

我在 gcc-4.7、gcc-4.6 上观察到了这一点。在 gcc-4.4 上一切正常。

4

1 回答 1

7

如果您使用-fvar-tracking. 您的问题是这个 SO question的更严格版本,它引用了关于 GCC 4.8.0 的错误报告,建议使用上述编译标志。

于 2013-08-15T19:52:48.807 回答