Why GDB jumps unpredictably between lines and prints variables as “”?

后端 未结 8 1096
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 05:10

Can anyone explain this behavior of gdb?

900         memset(&new_ckpt_info,\'\\0\',sizeof(CKPT_INFO));
(gdb)
**903         prev_offset   = cp_node->of         


        
相关标签:
8条回答
  • 2020-12-02 05:57

    The compiler will start doing very clever things with optimisations turned on. The debugger will show the code jumping forward and backwards alot due to the optimized way variables are stored in registers. This is probably the reason why you can't set your variable (or in some cases see its value) as it has been cleverly distributed between registers for speed, rather than having a direct memory location that the debugger can access.

    Compile without optimisations?

    0 讨论(0)
  • 2020-12-02 05:59

    Recompile without optimizations (-O0 on gcc).

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