Riddle with Python 2/3 and GDB.py checkpoint-restart
At the moment, I'm playing with thread checkpoint-restart, implemented somehow like setjmp/longjmp :
REGS = "rax","rbx","rcx","rdx","rsi","rdi","rbp","rsp","r8","r9", ... def checkpoint(): reg_values = map(gdb.newest_frame().read_register, REGS)) return reg_values def restart(reg_values): for reg, val in zip(REGS, reg_values): gdb.execute("set ${} = {}".format(reg, val), to_string=True)
This a naive implementation, but with a few more tricks, it does work (what I have to do is save/restore rip and rbp for the frame above, I'm not sure why).
However this code works for Python 2, but not for Python 3. Can you find why?
I'll let you guess, the answer is written below in white:
The map function in Python 3 returns a generator, which is lazily evaluated. Thus in Python 3, the registers are actually read ... in the restart function! So, of course, they don't hold the values of the check-point, and hence the restart function does nothing!