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
gdbserver --attach <host:2345> <pid>
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 --baud 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 /dev/ttyb), or a "HOST:PORT" descriptor. For example: (gdb) target remote /dev/ttyb communicates with the server via serial line /dev/ttyb, and: (gdb) target remote the-target:2345 communicates via a TCP connection to port 2345 on host `the-target', where you previously started up gdbserver with the same port number. Note that for TCP connections, you must start up gdbserver prior to using the `target remote' command, otherwise you may get an error that looks something like `Connection refused'.