Technology
 

Kernel Debugging

From Ace OS Wiki

Debugging Ace can be done using two types of debuggers - Monitors that is included with emulator and GDB.

Contents

[edit] Emulators

[edit] QEMU monitor

QEMU comes with a internal debugger which can be used to debug kernel in the early stages. To start debugging start QEMU and press ctl+alt+2 to switch to qemu monitor screen. Using the monitor commands, kernel debugging can be done. [1]

[edit] Bochs internal debugger

Bochs has a internal debugger which is more powerful than QEMU. For some reason, the binary bochsdbg.exe is not running under cygwin. To avoid any problem, the internal debugger should be recompiled under cygwin. [2]

To build bochs with internal debugger support, download bochs source code from http://bochs.sourceforge.net/

  mkdir -p /usr/src/build-bochs
  cd /usr/src/build-bochs
  mkdir -p /usr/debugger/bochs
  ../bochs-2.3.7/configure --prefix=/usr/debugger/bochs --enable-vbe=yes --with-win32 --enable-smp --enable-cpu-level=6 --enable-apic --enable-ne2000 --enable-acpi
      --enable-pci --enable-global-pages --enable-vme --enable-sep --enable-cdrom --enable-all-optimizations --enable-debugger=yes
  make
  make install

If you get error "bochs.ico is not found", open the Makefile and find win32res.o and change it to look like the following.

  # for win32 gui
  win32res.o: win32res.rc
       $(RC_CMD) $@ $(srcdir)/win32res.rc --include-dir=$(srcdir)

[edit] GDB

GDB can be used debug an kernel by using the remote debug option of GDB. However to use GDB, gdb-stub or gdb server should run on the remote machine on which the kernel is running.

[edit] Using two machines

To use GDB as a remote serial debugger, two real machies are required and they should connected through a NULL modem cable. In one machine setup, grub to run Ace kernel. By default, the kernel wont wait for gdb server, to debug using serial port, the serial port's IO port number has to pass to the kernel as kernel parameter.

An example menu.lst which will make the ace kernel to wait for gdb server on serial port 0x3f8.

  title Ace OS 3.0.0 (DEBUG)
  kernel /kernel.sys /gdb_port 0x3f8 
  boot

In the other development machine, run gdb and type the following commands.

  set remoteaddresssize 32
  set remotebaud 115200
  target remote /dev/com3

Replace /dev/com3 with the correct serial port which is connected with the test machine.

[edit] Using emulator

By using virtual serial ports, gdb can be used for debugging without using extra machine.

virtual serial port - http://en.wikipedia.org/wiki/COM_port_redirector com0com - http://com0com.sourceforge.net/

Create two serial ports with a virtual serial port software and pair them. For example: COM6 and COM7

Note: bochs - Raw mode serial emulation for windows is under construction. So cant used with windows. qemu - Download windows specific qemu (http://www1.interq.or.jp/t-takeda/qemu/qemu-0.9.0-windows.zip) to emulate serial port.

Run qemu with the following option -serial COM6. In the serial port property dialog select 115200 bits per second and hardware flow control Run gdb and type target remote /dev/com7.

[edit] Using emulator gdb-stub

Qemu has built-in gdb-stub. To make use of it, add the following switches -s -S.


Cite error: <ref> tags exist, but no <references/> tag was found