Debug QEMU/KVM with gdb via a serial port

Viewed 345

I tried to set-up QEMU/KVM to for GDB debuggin with a serial port and couldn't managed to make it work.

According to QEMU GDB documentation

If you want to specify which TCP port to use or to use something other than TCP for the gdbstub connection, use the -gdb dev option instead of -s.

Here are my attempts:

I. I looked at available tty devices and picked up the first one /dev/ttyS0

sudo qemu-system-x86_64 -gdb /dev/ttyS0 -S

In GDB I tried

(gdb) target remote /dev/ttyS0
get_tty_state failed: Input/output error
set_tty_state failed: Input/output error
Remote debugging using /dev/ttyS0
Remote communication error.  Target disconnected.: Input/output error.

II. Create a chardev and pass it to -gdb option

sudo qemu-system-x86_64 -chardev serial,id=ser0,path=/dev/ttyS0 -gdb /dev/ttyS0 -S

GDB responds with the same error msg:

(gdb) target remote /dev/ttyS0
get_tty_state failed: Input/output error
set_tty_state failed: Input/output error
Remote debugging using /dev/ttyS0
Remote communication error.  Target disconnected.: Input/output error.

III. Pass a chardev id to the -gdb option

$ sudo qemu-system-x86_64 -chardev serial,id=ser0,path=/dev/ttyS0 -gdb ser0 -S  
qemu-system-x86_64: -gdb ser0: 'ser0' is not a valid char driver

This way QEMU does not start at all.

QUESTION: What is the correct way to set-up QEMU GDB debugging via a serial port?

0 Answers
Related