With gdbserver it is possible to debug files running on a remote system.
Remote system
In this example the remote system is a minimal server with shell access via ssh running Ubuntu 18.04. To perform the remote debugging we have to install the gdbserver
application. If the OS of the system is Ubuntu or Debian the software can be installed using apt-get
.
$ sudo apt-get install gdbserver
If the installation was successful the debug server can be started by using the following command.
$ gdbserver 0.0.0.0:1234 /opt/your/application
Local system
In this example the local system is a desktop PC with a GUI running Ubuntu 18.04. To access the remote debugging server we have to install gdb
or an other gdb frontend.
$ sudo apt-get install gdb
If the installation was successful the debugger can be started.
$ gdb
In the debugger interface we tell gdb
to connect to the remote system on IP 192.168.12.34 and port 1234. After this we set a breakpoint on the main function and tell gdb to continue. After a few moments the debugger should stop at the breakpoint.
(gdb) target remote 192.168.12.34:1234
(gdb) b main
Breakpoint 1 at 0x12345678: file source.c, line 123.
(gdb) continue
Breakpoint 1, main (argc=23, argv=0x45678) at source.c:123
(gdb)
If everything was successful we can start debugging our application.
Links
- Website: GDB: The GNU Project Debugger (english)
- Website: Ubuntu (english)
- Website: Debian (english)