3

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 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Okay thanks. But is it not possible to redirect my qemu serial port to my host's ttyS0 so that I could use /dev/ttyS0 from my gdb.
I don't understand: what would be the added value of using /dev/ttyS0?
You would only want to redirect QEMU to the host's /dev/ttyS0 if you wanted to use an actual cable to connect to a different physical machine running the debugger. If you just want to debug from the same machine, you use local virtual method like TCP on the loopback interface or a unix domain socket.
1

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

2 Comments

Yes I know! But I want to emulate it as a remote machine so that I would get some hands on before I try on actual target machine. And is it possible to redirect my emulated serial port /dev/ttyAMA0 to host's serial port /dev/ttyS0 ?
@GeekFactory: sure, you can redirect the serial port. For example "-serial telnet:127.0.0.1:4444" will redirect it to a tcp socket.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.