In This article we will discuss, how to do remote debugging a C++ application using gdb debugger.

What is Remote Debugging

Remote Debugging allows the application to run on a Target machine and user can debug it on a Host Machine.

 

Suppose, you have a application “Dummy” , with Remote Debugging you can run this application on MACHINE 1 (Target Machine) and can debug it through MACHINE 2 (Host Machine).

How to do Remote Debugging using gdb

It involves 2 steps,

1.) Start a gdbserver:

On Host Machine start gdbserver with application to debug on a specified IP and Port i.e.

gdbserver <IP>:<PORT> <APPLICATION>

e.g.
gdbserver 192.168.1.8:8082 Debug/Dummy

Output:
Process Debug/Dummy created; pid = 3523
Listening on port 8082

It will start the gdbserver for application “Dummy” on port 8082 and will wait for a host to connect to this on port 8082.

2.) Connect gdb from Host Machine to remote gdbserver

From the Host Machine start gdb and execute following command on gdb command prompt

target remote <TARGET MACHINE IP>:<GDBSERVER PORT>

e.g.
(gdb) target remote 192.168.1.8:8082

It will connect this gdb from Host Machine to remote gdbserver running on Target Machine. Now on Host Machine it will show a gdb command prompt.
Remote debugging using 192.168.1.8:8082
warning: Could not load vsyscall page because no executable was specified
try using the "file" command first.
0x00007ffff7dd9cd0 in ?? ()
(gdb)

Now gdb from Host Machine is connected to target Machine’s gdbserver. Press “c” to continue debugging,
(gdb) c