6.1.10 Remote Debugging with gdbserver

On platforms that support gdbserver, you can use this tool to debug your application remotely. This can be useful in situations where the program needs to be run on a target host that is different from the host used for development, particularly when the target has a limited amount of resources (either CPU and/or memory).

To do so, start your program using gdbserver on the target machine. gdbserver automatically suspends the execution of your program at its entry point, waiting for a debugger to connect to it. You use the following commands to start an application and tell gdbserver to wait for a connection with the debugger on localhost port 4444.

$ gdbserver localhost:4444 program
Process program created; pid = 5685
Listening on port 4444

Once gdbserver has started listening, you can tell the debugger to establish a connection with this gdbserver, and then start a debugging session as if the program was being debugged on the same host, directly under the control of GDB.

$ gdb program
(gdb) target remote targethost:4444
Remote debugging using targethost:4444
0x00007f29936d0af0 in ?? () from /lib64/ld-linux-x86-64.so.
(gdb) b foo.adb:3
Breakpoint 1 at 0x401f0c: file foo.adb, line 3.
(gdb) continue
Continuing.

Breakpoint 1, foo () at foo.adb:4
4       end foo;

You can also use gdbserver to attach to an already running program, in which case the execution of that program is suspended until you have established the connection between the debugger and gdbserver.

For more information on how to use gdbserver, see the ‘Using the gdbserver Program’ section in Debugging with GDB. GNAT provides support for gdbserver on x86-linux, x86-windows and x86_64-linux.