我想调试从主机箱在远程箱上运行的进程(我在主机上构建了代码)。两者都有linux类型的操作系统。
我似乎只能通过ssh从主机箱与远程箱进行通信(我使用telnet进行了测试)。
我已经按照以下步骤进行了设置:
在“远程”框上:
停止防火墙服务:
服务防火墙_服务停止
将进程附加到gdbserver
-attach:remote_port process_id
在主机箱上:
通过ssh设置端口转发
sudo ssh remote_username @ remote_ip -L host_port:localhost:remote_port-f sleep 60m
设置gdb以附加到远程进程:
gdb file.debug
((gdb)目标远程remote_ip:remote_port
[当我尝试通过在主机上运行'target remote remote_ip:remote_port'在主机上启动调试时,出现'连接超时'错误。
你们能看到我做错的任何事情,要检查的任何事情或通过ssh进行远程调试的另一种方法,我将不胜感激。谢谢
此命令:
sudo ssh remote_username@remote_ip -L host_port:localhost:remote_port ...
转发本地 host_port到remote_ip的localhost上的remote_port。仅当您不能直接连接到remote_ip:remote_port时(例如,如果该端口被防火墙阻止),此功能才有用。
此命令:
(gdb) target remote remote_ip:remote_port
要求GDB在remote_ip上连接到remote_port。但是您说过只能通过ssh到达remote_ip,因此GDB超时也就不足为奇了。
您想要什么:
ssh remote_username@remote_ip -L host_port:localhost:remote_port ...
(gdb) target remote :host_port
换句话说,您连接到local host_port,并且ssh将本地连接转发到remote_ip:remote_port,gdbserver正在其中监听它。