First, some background. I run a program by starting a process on a remote_host
using ssh
:
ssh -T remote_host "cd ~/mydir && ~/myprogram" < input.txt
The program, myprogram
, reads stdin, which is attached to a local file input.txt
.
Now, I need to remotely debug this program under gdb. If there was no stdin redirection, i.e. < input.txt
, I would be able to do this using gdb's target remote
, something like this (at gdb prompt):
(gdb) target remote | ssh -T remote_host gdbserver - myprogram
However, in the above example, I don't know how to attach myprogram
's stdin to input.txt
.
Is there something that would do the trick?
gdbserver
doesn't read from stdin, so the program it invokes will have unfettered access to stdin. You should be able to do this:
ssh -T remote_host "cd ~/mydir && gdbserver :1234 ~/myprogram" < input.txt
where 1234
is an unused port. Then,
(gdb) target remote remote_host:1234
A drawback with this is that the gdb-gdbserver
TCP connection won't be encrypted.