gdbserver
Sounds like you're looking for gdbserver.
gdbserver is a control program for Unix-like systems, which allows you to connect your program with a remote GDB via target remote---but without linking in the usual debugging stub.
Example
On the target machine
You need to have a copy of the program you want to debug. gdbserver does not need your program's symbol table, so you can strip the program if necessary to save space. GDB on the host system does all the symbol handling.
target$ gdbserver host:2345 emacs foo.txt
NOTE: You can also attach to running processes like so:
target$ gdbserver comm --attach pid
One the GDB host machine
You need an unstripped copy of your program, since GDB needs symbols and debugging information. Start up GDB as usual, using the name of the local copy of your program as the first argument. (You may also need the --baud' option if the serial line is running at anything other than 9600bps.) After that, use target remote to establish communications with gdbserver. Its argument is either a device name (usually a serial device, like
/dev/ttyb'), or a TCP port descriptor in the form host:PORT. For example:
(gdb) target remote the-target:2345
GDB stub
There is another method discussed in the manuals, called "remote stub". The official manuals are located here, GDB Documentation, on the gnu.org website. Looking through the GDB Users Manual, section 20.5, Implementing a Remote Stub, explains how to use this feature instead of gdbserver
.
This method is described as follows in the docs:
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:
So you might be able to setup a serial port on both the VM host and the guest and debug the guest's kernel using this method.
References