How can I run a program that expects to be executing in a terminal in such a way that it's STDIO can be arbitrarily connected-to remotely?
Specifically, I want to be able to launch gdb on one host and connect into it's terminal interface remotely, such that I can pause execution with CTRL+C, change the layout (e.g. layout regs), etc. The diagram below illustrates what I'm trying to accomplish.
So far, the closest I've gotten is to use socat on the remote host to create the pty and start gdb:
$ socat PTY,link=$HOME/somedev,rawer, SYSTEM:"gdb 2>&1",pty
Then pipe that PTY to/from a netcat listener:
$ cat ~/somedev | nc -l 5556 > ~/somedev
And on the workstation, start netcat:
$ nc <remote_host> 5556
What I have at this point is close to what I want, but the terminal interaction is a bit wonky (e.g., if I change gdb's layout, it looks okay at first, but new lines coming in mess up alignment of the windows, etc.), and CTRL+C does not get forwarded through to the gdb process to suspend the process.
I admit, some of this behavior is probably due to limitations with netcat - I'm open to other programs to make the connection to the tcp listener on the remote host.
Some other constraints for a solution:
- The gdb process must begin independently of a remote connection being established (in other words, I can't use socat to start the gdb process, as in
socat TCP-LISTEN:5556,reuseaddr,fork EXEC:"gdb"). This also eliminates solutions that involve running gdb on the workstation rather than the remote host. - CTRL+C entered on the workstation terminal must cause
SIGINTto be sent to the gdb process.
