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

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

问题描述

全新安装代码块 12.11 + mingw pack.

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
", b);

}

问题

我在void foo(int a, int b)"上放了一个断点,当我通过 3 行时,我查看了 b 的值.无论是使用代码块调试功能还是使用 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)CodeBlocksMinGWingdb.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:DebugTestinDebugDebugTest.exe...done.
(gdb) break foo
Breakpoint 1 at 0x401363: file C:DebugTestmain.c, line 14.
(gdb) run
Starting program: C:DebugTestinDebugDebugTest.exe
[New Thread 3596.0x658]

Breakpoint 1, foo (a=400, b=42) at C:DebugTestmain.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
", b);
(gdb) print b
$3 = 42
(gdb)

备注

  • 相同的操作完成没有一个函数,a和b作为main内部的局部变量时,调试输出是正确的.
  • 使用 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 ? =)

      推荐答案

      我在gcc bugzilla上搜索,发现了这个错误报告:

      I searched on gcc bugzilla and found this bug report :

      尽管报告是关于 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-tracking 编译允许 GDB 在赋值后打印正确的 b 值.

      Compiling with -fvar-tracking allows GDB to print the correct value for b after assignment.

      这篇关于gdb 在修改参数时打印错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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