While trying to answer another question, I tried to set-up a Python script to automatize the extraction of an assembly execution trace. But, I am really not satisfied of this script and I would like to know how to improve it.First, here is the script:import gdbgdb.execute('break main')gdb.execute('run')while (True):    gdb.write (gdb.execute('x /i $pc', to_string=True).rstrip('\n'), gdb.STDOUT)    gdb.execute('stepi', to_string=False)    gdb.flush ()Then, just execute:$> gdb -x ./script.py ./main 1> log.txtThe problems that I would like to solve are as follow:First, the while(True) is definitely not satisfactory. I would like to stop or suspend the loop when a breakpoint or an exit is reached.Also, the way we export the list of instructions outside of gdb is not really satisfactory. Saving it to a file would be much better than having to redirect stdout to a file.Finally, be able to interact with the software, feeding it through stdin would also be something we want.So, if you know how to improve this script in any manner, I would be interested.
How to get a full execution trace with Python gdb?
disassembly;gdb