8

I want to debug a process running on a remote box from my host box (I built the code on the host machine). Both have linux type operating systems.

I seems I can only communicate to the remote box from the host box via ssh (I tested using telnet).

I have followed the following steps to set this up:

On the Remote box:

  1. Stop the firewall service:

    service firewall_service stop

  2. Attach the process to gdbserver

    --attach :remote_port process_id

On the Host box:

  1. Set up port forwarding via ssh

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

  2. Set up gdb to attach to a remote process:

    gdb file.debug

    (gdb) target remote remote_ip:remote_port

When I try to start the debugging on the host by running 'target remote remote_ip:remote_port' on the host box I get a 'Connection timedout' error.

Can you guys see anything I am doing wrong, anything to check or an alternative way to debug remotely over ssh I would be grateful. Thanks

Mulvihic
  • 295
  • 1
  • 2
  • 10

1 Answers1

8

This command:

sudo ssh remote_username@remote_ip -L host_port:localhost:remote_port ...

forwards local host_port to remote_port on remote_ip's localhost. This is useful only if you could not just connect to remote_ip:remote_port directly (for example, if that port is blocked by firewall).

This command:

(gdb) target remote remote_ip:remote_port

asks GDB to connect to remote_port on remote_ip. But you said that you can only reach remote_ip via ssh, so it's not surprising that GDB times out.

What you want:

ssh remote_username@remote_ip -L host_port:localhost:remote_port ...
(gdb) target remote :host_port

In other words, you connect to local host_port, and ssh forwards that local connection to remote_ip:remote_port, where gdbserver is listening for it.

Kevin Rak
  • 336
  • 2
  • 14
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Thanks- I'll give it a try but it looks like there is another firewall between the 2 boxes which is probally why I'm not connecting. – Mulvihic Nov 24 '14 at 17:32
  • 3
    First paragraph is wrong, "localhost" is evaluated on the ssh server, completely different from making a local connection to "localhost:remote_port". The option `-L host_port:localhost:remote_port` is very useful for accessing ports on the SSH server other than the SSH port itself, bypassing any firewalls that might block them. – Ben Voigt Mar 15 '16 at 18:17