GDB Debugging
Debug Linux kernel with GDB
Compile a correct Linux kernel
Clone a Linux tree and run make ARCH=arm defconfig
to make a generic kernel configuration suited for qemu. Now edit the kernel configuration (.config
) and add the following lines at the bottom:
Now run 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 (arch/arm/boot/zImage
) to efi/boot/bootarm.efi
on your EFI partition folder in your qemu directory.
Prepare GDB for debugging
Install
Run sudo apt-get install gdb-multiarch
to install GDB on Ubuntu. gdb-mutliarch
is required because normal gdb
package doesn't have support for ARM.
Run
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.
Run qemu
Go to the directory where your qemu files are located, start qemu as described in Qemu emulation, only change is that you need to add a -s
parameter, this lets qemu know that it starts a GDB server.
Last updated