Reputation: 5919
To try debugging kernel using qemu and gdb (how nice it would be) for aarch64, I tried this.
build kernel with CONFIG_DEBUG_INFO
build qemu with 'configure --target-list=aarch64-softmmu --enable-debug' and 'make' and 'make install'.
then I ran,
qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 2048 -kernel arch/arm64/boot/Image -append "earlyprintk console=ttyAMA0 rootwait root=/dev/vda2" -drive if=none,file=/home/ckim/N1SDP/arm-reference-platforms/output/n1sdp/grub-ubuntu.img,id=disk1 -device virtio-blk-device,drive=disk1 -s -S
and ran in another shell, 'gdb-multiarch vmlinux -x gdbcmd'. gdbcmd contains
set architecture aarch64 set serial baud 115200 target remote :1234
Without -S option, qemu proceeds with linux booting. (it starts with
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x411fd070]
[ 0.000000] Linux version 5.4.21 (ckim@chan-ubuntu) (gcc version 9.2.1 20191025 (GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10))) #6 SMP PREEMPT Fri Jan 22 11:43:52 JST 2021
[ 0.000000] Machine model: linux,dummy-virt
[ 0.000000] efi: Getting EFI parameters from FDT:
[ 0.000000] efi: UEFI not found.
....
but with -S, it stops and waits for the debugger to give continue command.
inside the debugger, I can set break point like b start_kernel
and it responds. But if I type in 'cont', qemu start booting, without stopping at 'start_kernel'. I don't know what is wrong with this.
And I also don't know how to boot without giving the disk image above. how can I run it with vanilla linux kernel? (I used it but with the disk and disk image above, I tried it without them but it doesn't start).
Please help.
Upvotes: 3
Views: 3212
Reputation: 5919
This was solve not long after my posting the question and I forgot to put an answer.
It was because of the KASLR (kernel address space location randomization). You should disable it in the kernel configuration, or give option in the boot parameter. (without it, the kernel image is located in random location, causing mismach between debug symbol location and actual code location). This KASLR is turned on by default for aarch64.
In my case I did it with :
${QEMU_DIR}/qemu-system-aarch64 -M ${QMACHINE} -cpu cortex-a72 -kernel ${LINUX_DIR}/arch/arm64/boot/Image -initrd ${BUSYBOX_DIR}/initramfs.cpio.gz --append "root=/dev/ram init=/init nokaslr" -m 2048M -nographic
And I had to use 'hb'(or hbreak (hardware break)) instead of 'b'(or break).
Upvotes: 6