GDB修改参数时打印错误的价值观 [英] gdb prints wrong values when modifying arguments

查看:195
本文介绍了GDB修改参数时打印错误的价值观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全新安装$ 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编译,调试输出的正确

  • Remarks

    • 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.
    • 任何想法可能是错误的? =)

      Any idea what could be wrong ? =)

      推荐答案

      我搜索了海湾合作委员会的Bugzilla,发现这个bug报告:

      I searched on gcc bugzilla and found this bug report :

      • Bug 54218 - Debug info for function parameters is incorrect when compiled with -O0"

      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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆