Last Updated: February 25, 2016
·
2.059K
· hoffoo

Redirect GDB stdout to another terminal

In gdb I often want stdout of the program I'm debugging to go to another terminal. To do this I open a terminal where the output will go and run 'tty' to get its path. Then I set this in my gdb with 'tty /dev/pts/17'. Now stdout appears in the other location.

This is annoying to redo every time when restarting gdb. Save your tty in an environmental variable. Then something like this in .gdbinit.

python
import os
if 'OUTTY' in os.environ:
    gdb.execute('tty ' + os.environ['OUTTY'])
end