问题
Can I debug a program running on a remote target to which I have ssh access, using local source files?
Say I've got a program called hello.c, in directory /home/jla/hello
on my home machine.
And on the remote machine I put this same file in a directory /hello, and compile it with
$ gcc -g -o hello hello.c
, and then delete the remote hello.c, but leave the executable.
Can I then run gdb locally, get it to ssh in to the remote machine to run the executable, but use the local sources as reference?
Notes:
Annoyingly, the remote machine is very stripped down and can't be altered. It has gdb, but it doesn't have gdbserver
Note that the local and the remote machine have different architectures. In this particular case 64bit and 32bit intel
What I really want to do is run it under emacs/gud. But this would be a great start.
回答1:
The architectures of remote and local machines matter very little. What matters is how hello
, gdb
and gdbserver
are built.
It sounds from your description that hello
is built (on remote machine) for x86_64-linux-gnu
That means you need x86_64-linux-gnu
gdbserver
, and also a 32-bit GDB that is capable of debugging x86_64
binaries. You should be able to build both, copy gdbserver
to the remote machine, and debug "normally".
来源:https://stackoverflow.com/questions/7787179/is-it-possible-to-use-gdb-to-debug-remotely-over-ssh