我想从我的主机盒调试远程盒子上运行的进程(我在主机上构建了代码)。 两者都有linux类型的操作系统。
我似乎只能通过ssh(我使用telnet测试)从主机盒与远程盒通信。
我已按照以下步骤进行设置:
在远程框中:
停止防火墙服务:
service firewall_service stop
将流程附加到gdbserver
- attach:remote_port process_id
在主机框中:
通过ssh设置端口转发
sudo ssh remote_username @ remote_ip -L host_port:localhost:remote_port -f睡60米
设置gdb以附加到远程进程:
gdb file.debug
(gdb)target remote remote_ip:remote_port
当我尝试通过运行目标远程remote_ip:remote_port'来尝试在主机上启动调试时在主机上我得到一个连接时间限制'错误。
你们可以看到我做错了什么,要检查什么或者通过ssh远程调试的替代方法我将不胜感激。 感谢
答案 0 :(得分:5)
此命令:
sudo ssh remote_username@remote_ip -L host_port:localhost:remote_port ...
将本地 host_port转发到localhost上的remote_port。它没用:你可以直接连接到localhost: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:remote_ip:remote_port ...
(gdb) target remote :host_port
换句话说,您连接到 local host_port,ssh将该本地连接转发到remote_ip:remote_port,gdbserver正在侦听它。