3
votes

I am trying to debug the Linux kernel using kgdb. I am using qemu as target machine. Ubuntu 12.04 is my host OS. I tried this command

cyborg@skynet:~$ qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.img.gz -append "root=/dev/ram rdinit=/bin/sh kgdboc=ttyAMA0,115200 kgdbwait"

It will boot and wait displaying

kgdb: Waiting for connection from remote gdb

And when I try to debug using gdb on linux host using the commands

cyborg@skynet: arm-none-linux-gnueabi-gdb vmlinux

(gdb): set remotebaud 115200

(gdb) target remote /dev/ttyS0 Remote debugging using /dev/ttyS0 Ignoring packet error, continuing...

warning: unrecognized item "timeout" in "qSupported" response

Ignoring packet error, continuing...

Ignoring packet error, continuing...

Ignoring packet error, continuing...

Ignoring packet error, continuing...

Malformed response to offset query, timeout

I am not really getting what I am missing !

P.S. I compiled the linux kernel 2.6.39.4 with KGDB options enabled. And I followed these instructions to run kernel on qemu.

2

2 Answers

3
votes

If you reference /dev/ttyS0 on the host gdb will try to use the physical serial port present. You have to connect qemu's emulated serial port to gdb instead. Reading the qemu manual, apparently you can redirect the emulated port to tcp networking, by adding something like: -serial tcp::1234,server to the qemu command line. In gdb you can then connect using target remote :1234.

1
votes

There is no real reason to use kgdb when your running within Qemu. You can simply specify something like "-gdb tcp::8888" on the Qemu command line and activate the GDB stub. You can then connect to the stub with an ARM aware GDB:

 target remote:8888

And debug away. You may find the following gdb helper scripts useful