how to remote debug multiple process program using gdb
Remote debugging technique is usually used for program that runs on tiny machine (arm devices) because these resource lacking devices( mobile,smart tv,arm borad etc) does not have desktop like environment. remote debugging is achieved through a small program called gdbserver. gdbserver is a program that allows you to run GDB on a different machine than the one which is running the program being debugged. Here is the step by step instruction for setting up remote debugging environment along with how to debug a program remotely with c example.
- First, you need to have a copy of the program you want to debug put onto the target system.
- To use the server, you log on to the target system, and run the gdbserver program.
#gdbserver host:2345 ( here host is ip address )
- Now find the process id of running program ( or if not running execute it) . by issuing ps command we can find the process id of running program.
- Now attach the process with gdbserver using below command
<span style="color: #181818;"> gdbserver --attach <host:2345> <pid></span>
Usage (host side):
You need an unstripped copy of the target program on your host
system, since GDB needs to examine it's symbol tables and such.
Start up GDB as you normally would, with the target program as the
first argument. (You may need to use the <b style="color: #502000;">--baud </b>option if the serial
line is running at anything except 9600 baud.) That is "gdb
TARGET-PROG", or "gdb --baud BAUD TARGET-PROG". After that, the only
new command you need to know about is "target remote" (or "target
extended-remote"). Its argument is either a device name (usually a
serial device, like <i style="color: #006000;">/dev/ttyb</i>), or a "HOST:PORT" descriptor. For
(gdb) target remote /dev/ttyb
communicates with the server via serial line <i style="color: #006000;">/dev/ttyb</i>, and:
(gdb) target remote the-target:2345
communicates via a TCP connection to port 2345 on host `the-target',
where you previously started up <b style="color: #502000;">gdbserver </b>with the same port number.
Note that for TCP connections, you must start up <b style="color: #502000;">gdbserver </b>prior to
using the `target remote' command, otherwise you may get an error
that looks something like `Connection refused'.