tisdag 28 januari 2014

ARM debugging with Qemu and gdb

To set up a pty to capture the serial port info, use socat
socat -d -d pty  pty
which prints out which pty to connect Qemu's virtual serial port to, for instance /dev/pts/1, and the other pty, for instance /dev/pty/6, to which one may for instance attach a GNU Screen
screen /dev/pty/6
Now run Qemu
QEMU_AUDIO_DRV=none qemu-system-arm \
-cpu cortex-a15 -machine vexpress-a15 \
-kernel /tmp/vmlinuz-3.10 -append "earlyprintk console=tty1 console=ttyAMA0" \
-nographic \
-gdb tcp:localhost:1234 -S -serial /dev/pts/1

which tells Qemu to start a gdb-server at port 1234 and wait (-S) until a gdb server attaches.

Make sure to have a gdb configured for arm targets, compiled with
./configure --target=arm-linux-gnueabi
make
and run it.  Connect to the qemu gdb-server with
target remote :1234 
To see the machine code, type
C-x a
to enable the terminal interface that shows code cursor, and enable asm with
layout asm