Code: Select all
import os
# create input/output pipes
in_pipe = "in"
out_pipe = "out"
try:
os.unlink(in_pipe)
except FileNotFoundError:
pass
try:
os.unlink(out_pipe)
except FileNotFoundError:
pass
os.mkfifo(in_pipe)
os.system(f"sleep infinity > {in_pipe} &")
print("in pipe:", in_pipe)
os.mkfifo(out_pipe)
os.system(f"sleep infinity > {out_pipe} &")
print("out pipe:", out_pipe)
# open in/out pipes to prevent starti command from blocking
# open a tmp read-only FD for the input pipe to prevent it's write-only open from blocking
out_fd = os.open(out_pipe, os.O_RDONLY | os.O_NONBLOCK)
tmp_fd = os.open(in_pipe, os.O_RDONLY | os.O_NONBLOCK) # prevent blocking
in_fd = os.open(in_pipe, os.O_WRONLY | os.O_NONBLOCK)
gdb.execute(f"set target-async on")
gdb.execute(f"starti < {in_pipe} > {out_pipe}")
gdb.execute(f"c&")
print(os.read(out_fd, 8)) # causes BlockingIOError for some reason, even if I ensure enough time for the target to print
print("--- DONE ---")