panda
panda copied to clipboard
[PyPANDA] BlockingIOError: [Errno 11] write could not complete without blocking
Trying to dump the CPU registers for each instruction may cause a BlockingIOError
:
@panda.cb_insn_translate
def should_run_on_insn(CPUState_env, target_ptr_t_pc):
return True
@panda.cb_insn_exec
def on_insn(CPUState_env, target_ptr_t_pc):
print("CPU STATE: ", CPUState_env)
print(panda.arch.dump_regs(CPUState_env))
return 0
Traceback (most recent call last):
File "./pypanda_test.py", line 118, in <module>
panda.run_replay("preinit_launch")
File "/usr/local/lib/python3.8/dist-packages/pandare/panda.py", line 626, in run_replay
self.run()
File "/usr/local/lib/python3.8/dist-packages/pandare/panda.py", line 540, in run
raise saved_exception
File "/usr/local/lib/python3.8/dist-packages/pandare/panda.py", line 2581, in _run_and_catch
r = fun(*args, **kwargs)
File "./pypanda_test.py", line 114, in on_insn
print(panda.arch.dump_regs(CPUState_env))
File "/usr/local/lib/python3.8/dist-packages/pandare/arch.py", line 237, in dump_regs
telescope(self.panda, cpu, val)
File "/usr/local/lib/python3.8/dist-packages/pandare/utils.py", line 60, in telescope
print()
BlockingIOError: [Errno 11] write could not complete without blocking
This seems to be an issue on non-blocking writes to stdout
, which is set somewhere in the code.
I haven't been able to replicate your issue, but I will suggest that you change:
print(panda.arch.dump_regs(CPUState_env)
to:
panda.arch.dump_regs(CPUState_env)
as dump_regs
calls print
itself and does not return a value.
It may well be that the telescope
call, which calls print
, inside an existing print
evaluation might run into a blocking IO issue? Hard to say.
panda.arch.dump_regs(CPUState_env)
The issue still happens with this change.
Odd. Well it looks like stdout is blocking. You could set stdout to not block like in this issue:
import fcntl
fcntl.fcntl(1, fcntl.F_SETFL, 0)
Let me know if that makes the error go away. If so we can look at handling it at some other level.