Gavare's eXperimental Emulator: GDB remote serial protocol connection

Back to the index

## GDB remote serial protocol connection

- Introduction
- Prerequisites
- Example session

### Introduction:

Starting with release 0.4.0, GXemul has (very rudimentary) GDB serial protocol support. This means that you can start up GDB, or a front-end program which in turn uses GDB, and connect it to a running GXemul instance.

The GDB front-end I use in this example is the Data Display Debugger (DDD).

The screenshot above shows DDD connected to GXemul, running the Hello World demo program compiled for mips64-unknown-elf, on a FreeBSD/amd64 host.

### Prerequisites:

- Build and install GDB for your target. You should use the same configuration as you did when you compiled your compiler (e.g. mips64-unknown-elf). Assuming you use `~/crossdev` for all your cross-development tools:

      	# wget http://ftp.gnu.org/gnu/gdb/gdb-6.4.tar.gz
      	# tar zxf gdb-6.4.tar.gz
      	# cd gdb-6.4
      	# ./configure --prefix=$HOME/crossdev --target=mips64-unknown-elf
      	# gmake install

  Remember to include `~/crossdev/bin` in your PATH.

- Optionally, but highly recommended: Install a front-end for GDB, such as DDD. In FreeBSD, this is done by:

      	# pkg_add -r ddd

  Other operating systems that have DDD available as a pre-compiled package have similar methods of installing it; otherwise you could try compiling DDD from source.

You can still run a bare GDB session without a GUI front-end if you like.

### Example session:

1. Start up GXemul, and tell it to wait for an incoming GDB connection on a certain port:

       	# gxemul -x -E testmips -G 10000 hello_mips

2. Start the DDD, using a GDB configured for this specific target, and also give the name of the binary/kernel. (This binary should have been compiled with `-g`.)

       	# ddd --debugger mips64-unknown-elf-gdb hello_mips

3. At the `(gdb)` prompt in DDD, type:

       	(gdb) target remote localhost:10000

4. Press F9 (Continue) to start. Press ESC when you wish to interrupt. You can also use F5 (Step) to single-step one instruction at a time.

Notes:

- The remote GDB functionality in GXemul is quite hack-ish, very unstable, very slow, and does not support any fancy features such as breakpoints or watchpoints yet.
- For 64-bit MIPS targets, you might have to fiddle with MIPS-related GDB settings, to make GDB send correct commands to GXemul. Otherwise, GDB only sends the lowest 32 bits of memory addresses, which is incorrect.
- When remote-debugging PowerPC targets using DDD, you might have to press F9 twice to get it to start. I am not sure why.