Debugging the kernel with GDB and bochs

It is possible to use GDB (the GNU debugger) as an external debugger to bochs. If this feature is compiled into bochs (the "--enable-gdb-stub" option is given to the configure script before compilation), then it is possible to debug a program running in bochs via gdb. Also, if the executable object file for the program has debugging symbols (i.e. has been compiled with the "-g" flag to gcc), then it is possible to debug the code at source code (i.e. C or assembly) level. This can be very convenient, as one now can easily set breakpoints in terms of the C code, examine the contents of variables on the stack by name, and so on.

A short description of how to use this feature is given below. This description assumes that you either are at IFI and that your PATH variable includes /store/bin as a component or you have configured bochs on your machine with the "--enable-gdb-stub" option and that you have called this binary "bochsd" (see Configuring and compiling bochs).

Using bochs with GDB

  1. Compile your code with debugging symbols

    Use the "-g" switch with gcc. You can enable this for your code by adding it to the appropriate Makefile variable.

  2. Run bochsd

    Run bochsd. The old ".bochsrc" file should work without modification. Bochs should display a message that it is waiting for gdb.

  3. Run gdb (or a front-end like ddd)

    Run gdb or a suitable front-end (e.g. ddd) with the executable object file for the program (e.g. "kernel") as argument.

  4. Let gdb attach itself to bochs

    Give the command "target remote localhost:1234" to GDB.

  5. Set breakpoints

    Set (e.g.) a breakpoint where you want start debugging. This may require that you open the appropriate source file. In gdb, this is done with the command "b".

  6. Continue execution

    Bochs is already running, so you need to continue the execution. This is done with the command "c" in gdb.

Last modified: Tue Nov 2 11:29:40 CET 2004