Debug Linux kernel with GDB
Clone a Linux tree and run
make ARCH=arm defconfigto make a generic kernel configuration suited for qemu. Now edit the kernel configuration (
.config) and add the following lines at the bottom:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j$(nproc)to compile the kernel. If you get asked about anything, just press enter to use the standard value.
Copy the output zImage (
efi/boot/bootarm.efion your EFI partition folder in your qemu directory.
sudo apt-get install gdb-multiarchto install GDB on Ubuntu.
gdb-mutliarchis required because normal
gdbpackage doesn't have support for ARM.
Open up the terminal you want GDB to run in, and change directory to your Linux compilation directory. Then run
gdb-multiarch vmlinux., it will open GDB you and you can now connect to a target with
target remote localhost:1234. At this point GDB will wait for qemu to start. After that you can now debug with qemu, there are tutorials online to show you how to do this.