Sunday, January 30, 2011

Remote debugging using gdbserver

Remote debugging is rather straightforward:

On the target platform, launch the application with GDBserver, while specifying the host and port for listening to an incoming TCP connection:

gdbserver HOST:PORT PROG [ARGS ...]
gdbserver test_rsh_sw.bin r

On the development workstation, launch the cross-target GDB:

arm-none-linux-gnueabi-gdb PROG

Be sure to specify the non-stripped executable. At the GDB console, type:

target remote HOST:PORT

break main

These commands will connect GDB to the GDBserver running on the target platform, set a breakpoint at the start of the program, and let it run until it reaches that first breakpoint.

You can also attach GDBserver to a process that's already running:

gdbserver HOST:PORT --attach PID

The process is then stopped, and you can then debug it with a remote GDB.