通过ssh使用gdbserver进行远程调试

Mul*_*hic 5 ssh gdb remote-debugging gdbserver

我想从我的主机盒调试远程盒子上运行的进程(我在主机上构建了代码).两者都有linux类型的操作系统.

我似乎只能通过ssh(我使用telnet测试)从主机盒与远程盒通信.

我已按照以下步骤进行设置:

在远程框上:

  1. 停止防火墙服务:

    service firewall_service stop

  2. 将进程附加到gdbserver

    --attach:remote_port process_id

在主机框上:

  1. 通过ssh设置端口转发

    sudo ssh remote_username @ remote_ip -L host_port:localhost:remote_port -f sleep 60m

  2. 设置gdb以附加到远程进程:

    gdb file.debug

    (gdb)target remote remote_ip:remote_port

当我尝试通过在主机框上运行'target remote remote_ip:remote_port'来启动主机上的调试时,我收到"连接超时"错误.

你们可以看到我做错了什么,要检查什么或者通过ssh远程调试的替代方法我将不胜感激.谢谢

Emp*_*ian 6

这个命令:

sudo ssh remote_username@remote_ip -L host_port:localhost:remote_port ...
Run Code Online (Sandbox Code Playgroud)

本地 host_port 转发到localhost上的remote_port.它没用:你可以直接连接到localhost:remote_port.

这个命令:

(gdb) target remote remote_ip:remote_port
Run Code Online (Sandbox Code Playgroud)

要求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
Run Code Online (Sandbox Code Playgroud)

换句话说,您连接到本地 host_port,并且ssh将该本地连接转发到remote_ip:remote_port,其中gdbserver正在侦听它.

  • 第一段是错误的,"localhost" 是在 ssh 服务器上评估的,与本地连接到 "localhost:remote_port" 完全不同。选项 `-L host_port:localhost:remote_port` 对于访问 SSH 服务器上的端口而不是 SSH 端口本身非常有用,可以绕过任何可能阻止它们的防火墙。 (3认同)