Chan Kim
Chan Kim

Reputation: 5919

debugging kernel with qemu and gdb, breakpoint not working?

To try debugging kernel using qemu and gdb (how nice it would be) for aarch64, I tried this.

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

Answers (1)

Chan Kim
Chan Kim

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

Related Questions