Remote Debugging using gdbserver

There are several flavors of debugging an application with gdb such as - print debugging, post mortem / core-dump analysis, live debugging and remote debugging. Out of all these methods of debugging - remote debugging is the trickiest one. In general, you will always have your source code files on the same machine on which you are debugging. With the source code on the same machine, your debugger ie. gdb will be able to map each instruction to the files on the disk and provide seamless stepping through the code being debugged. But at times, when you are debugging some live setup where the source code is not available it becomes very difficult to understand the flow of the program while debugging.

Don't worry, 'remote debugging' can help you survive. Remote debugging is a two-step process:

  1. Start gdbserver on the machine where the process to debug is running.

    Gdbserver is a utility that that allows  remote connections over TCP using standard gdb remote serial protocol. You need to specify a free port where gdbserver can listen, e.g.            

    pankaj@ubuntu:~$ gdbserver :1111 <executable path> <command line arguments>

  2. Run gdb remotely from client

    Now use gdb from the other machine where you have the source code:

    pankaj@ubuntu:~$ gdb <executable path>

    Once you get the gdb prompt, use the ip address and port of the machine where gdbserver is running to connect to it and start interactive debugging session:

    (gdb) target machine <ip_address>:<port>

That's it !! Now you can easily do all the cool stuff from a remote machine, which you used to do during normal live debugging session using gdb.

To know more about such programming practices followed in industry, do grab a copy of my book - "Hello World: Student to Software Professional” published by Partridge (A Penguin Random House Company). Now available worldwide on all the MAJOR ONLINE Stores - Amazon, Google Play, Flipkart, Barnes & Noble and many others.
comments powered by Disqus