gdb prints wrong values when modifying arguments

前端 未结 3 920
夕颜
夕颜 2020-12-11 17:02

System

Fresh install of codeblocks 12.11 + mingw pack.

  • win7 64
  • gcc 4.7.1
  • gdb 7.5

Example code

Compiled wit

相关标签:
3条回答
  • 2020-12-11 17:20

    Sometimes the optimizer is smarter than the debugger. Try debugging unoptimized code, or step through disassembly and watch the HW registers directly rather than stepping through C source lines and watching the debugger's idea of what the variables are.

    0 讨论(0)
  • 2020-12-11 17:30

    I searched on gcc bugzilla and found this bug report :

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

    Althoug the report is about gcc 4.8 and I'm using 4.7, I tried the proposed workaround and it works !

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

    0 讨论(0)
  • 2020-12-11 17:33

    gcc does not generate debugging info correctly for values that are in registers -- either values that have been put in registers or values that start there due to the calling conventions. This is a long-standing problem with gcc since at least 4.0, and makes it tricky to debug things.

    0 讨论(0)
提交回复
热议问题