
Gdbserver
Encyclopedia
gdbserver is a computer program that makes it possible to remotely debug
other programs. Running on the same system as the program to be debugged, it allows the GNU Debugger
to connect from another system; that is, only the executable to be debugged needs to be resident on the target system, while the source code and a copy of the binary file to be debugged reside on the developer’s local computer. The connection can be either TCP or a serial line.
Example for debugging a program called
In this case, the program to be debugged is linked with a few special-purpose subroutines that implement the GDB remote serial protocol. The file containing these subroutines is called a debugging stub.
Debugging
Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected. Debugging tends to be harder when various subsystems are tightly coupled, as changes in one may cause bugs to emerge...
other programs. Running on the same system as the program to be debugged, it allows the GNU Debugger
GNU Debugger
The GNU Debugger, usually called just GDB and named gdb as an executable file, is the standard debugger for the GNU software system. It is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, C, C++, Objective-C, Free Pascal, Fortran, Java...
to connect from another system; that is, only the executable to be debugged needs to be resident on the target system, while the source code and a copy of the binary file to be debugged reside on the developer’s local computer. The connection can be either TCP or a serial line.
How it works
-
gdbserver
is launched on the target system, with the arguments:- Either a device name (to use a serial line) or a TCP hostname and portnumber, and
- The path and filename of the executable to be debugged
- It then waits passively for the host gdb to communicate with it.
-
gdb
is run on the host, with the arguments:- The path and filename of the executable (and any sources) on the host, and
- A device name (for a serial line) or the IP address and port number needed for connection to the target system.
Example for debugging a program called
hello_world
on a remote host using TCP ("2345" is the TCP port number):
remote$ gdbserver :2345 hello_world
Process hello_world created; pid = 2509
Listening on port 2345
local$ gdb -q hello_world
Reading symbols from /home/user/hello_world...done.
(gdb) target remote 192.168.0.11:2345
Remote debugging using 192.168.0.11:2345
0x002f3850 in ?? from /lib/ld-linux.so.2
(gdb) continue
Continuing.
Program received signal SIGSEGV, Segmentation fault.
0x08048414 in main at hello_world.c:10
10 printf("x[%d] = %g\n", i, x[i]);
(gdb)
Alternatives
Another technique for debugging programs remotely is to use a remote stub.In this case, the program to be debugged is linked with a few special-purpose subroutines that implement the GDB remote serial protocol. The file containing these subroutines is called a debugging stub.
External links
- GDB homepage
- gdbserver man page
- Debugging with GDB