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

后端 未结 8 1151
伪装坚强ぢ
伪装坚强ぢ 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:36

    When debugging optimized programs (which may be necessary if the bug doesn't show up in debug builds), you often have to understand assembly compiler generated.

    In your particular case, return value of cpnd_find_exact_ckptinfo will be stored in the register which is used on your platform for return values. On ix86, that would be %eax. On x86_64: %rax, etc. You may need to google for '[your processor] procedure calling convention' if it's none of the above.

    You can examine that register in GDB and you can set it. E.g. on ix86:

    (gdb) p $eax
    (gdb) set $eax = 0 
    

提交回复
热议问题