The stub files provided with gdb implement the target side of the communication protocol, and the gdb side is implemented in the gdb source file remote.c. Normally, you can simply allow these subroutines to communicate, and ignore the details. (If you're implementing your own stub file, you can still ignore the details: start with one of the existing stub files. sparc-stub.c is the best organized, and therefore the easiest to read.)
To debug a program running on another machine (the debugging target machine), you must first arrange for all the usual prerequisites for the program to run by itself. For example, for a C program, you need:
The next step is to arrange for your program to use a serial port to communicate with the machine where gdb is running (the host machine). In general terms, the scheme looks like this:
On certain remote targets, you can use an auxiliary program
gdbserver instead of linking a stub into your program.
See Using the
gdbserver Program, for details.
The debugging stub is specific to the architecture of the remote machine; for example, use sparc-stub.c to debug programs on sparc boards.
These working remote stubs are distributed with gdb:
The README file in the gdb distribution may list other recently added stubs.