Thursday, 19 November 2009

Debugging with QEMU and gdb

QEMU is one very powerful tool - and combined with gdb this has allowed me to debug Intel based boot loaders. Here is a quick run down of the way I drive this:

Firstly, I recommend removing KVM as this has caused me some grief catching breakpoints. This means QEMU will run slower, but I want to remove any kind of grief I can to simplify my debugging environment.

Start QEMU and use the -s -S options to enable gdb debugging and halt the CPU to wait for gdb to attach:

$ qemu -s -S -bios bios-efi.bin -m 1024 karmic-efi-qcow2.img -serial stdio

..then in another terminal, attach gdb:

$ gdb
GNU gdb (GDB) 7.0-ubuntu
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.

(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x0000fff0 in ?? ()
(gdb)


..and start the boot process..

(gdb) c


..and get debugging!

1 comment:

  1. I wish I had seen this post about disabling kvm much earlier. I've been attempting to do some bootloader debugging as well, and I have hair-tearing issues with breakpoints. I came to the same conclusion, disabling KVM is just easier.

    My specific problem was setting a breakpoint on memory address 0x7c00 to break at the beginning of the bootloader code doesn't seem to work at all using kvm. The only way i can get breakpoints to work at all under kvm is to connect the debugger and set breakpoints after the bootloader has been loaded in to memory.

    There definitely seems to be a bug in qemu/kvm breakpoint handling. I've submitted a bug report to the qemu bugtracker. Feel free to comment on the report if you have any other insight into what may be causing the bug.

    https://bugs.launchpad.net/qemu/+bug/526653

    ReplyDelete