GDB修改参数时打印错误的价值观 [英] gdb prints wrong values when modifying arguments
问题描述
全新安装$ C $的cblock 12.11 + MinGW的包。
Fresh install of codeblocks 12.11 + mingw pack.
- WIN7 64
- GCC 4.7.1
- GDB 7.5
编译时-g,没有优化。
Compiled with -g and no optimization.
#include <stdio.h>
void foo(int a, int b);
int main() {
foo(400, 42);
return 0;
}
void foo(int a, int b) {
a = a - 10;
b = a + 1;
printf("y2 %d\n", b);
}
问题
我把一个断点无效美孚(INT A,INT B)我期待的B值,因为我通过3线一步。
无论是与$ C $个cblocks调试功能或使用gdb的命令行, b的值是42而不是被391 。
控制台输出是正确的,391。
Problem
I put a breakpoint on "void foo(int a, int b)" and I look value of b as I step through the 3 lines. Either with the codeblocks debugging features or with the gdb command line, the value of b is 42 instead of being 391. The console output is correct, 391.
C:\DebugTest>"C:\Program Files (x86)\CodeBlocks\MinGW\bin\gdb.exe"
GNU gdb (GDB) 7.5
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) file bin/Debug/DebugTest.exe
Reading symbols from C:\DebugTest\bin\Debug\DebugTest.exe...done.
(gdb) break foo
Breakpoint 1 at 0x401363: file C:\DebugTest\main.c, line 14.
(gdb) run
Starting program: C:\DebugTest\bin\Debug\DebugTest.exe
[New Thread 3596.0x658]
Breakpoint 1, foo (a=400, b=42) at C:\DebugTest\main.c:14
14 a = a - 10;
(gdb) print b
$1 = 42
(gdb) step
15 b = a + 1;
(gdb) print b
$2 = 42
(gdb) step
17 printf("y2 %d\n", b);
(gdb) print b
$3 = 42
(gdb)
说明
- 当相同的操作完成的无功能,具有A和B内的主要局部变量,调试输出的正确。
- 当用gcc 4.4.1编译,调试输出的正确
- When the same operations are done without a function, with a and b as local variables inside main, the debug output is correct.
- When compiled with gcc 4.4.1, the debug output is correct.
- 54218错误 - 当用-O0 <编译为函数的参数调试信息是不正确/ LI>
- Bug 54218 - Debug info for function parameters is incorrect when compiled with -O0"
Remarks
任何想法可能是错误的? =)
Any idea what could be wrong ? =)
推荐答案
我搜索了海湾合作委员会的Bugzilla,发现这个bug报告:
I searched on gcc bugzilla and found this bug report :
Althoug报告是关于GCC 4.8和我使用的是4.7,我想提出的解决办法和它的作品!
Althoug the report is about gcc 4.8 and I'm using 4.7, I tried the proposed workaround and it works !
与编译-fvar跟踪
允许GDB来分配后打印b的正确值。
Compiling with -fvar-tracking
allows GDB to print the correct value for b after assignment.
这篇关于GDB修改参数时打印错误的价值观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!