I am trying to debug a kernel running on QEMU with GDB.
The kernel has been compiled with these options:
CONFIG_DEBUG_INFO=y
CONFIG_GDB_SCRIPTS=y
I launch the kernel in qemu with the following command:
qemu-system-x86_64 -s -S -kernel arch/x86_64/boot/bzImage
In a separate terminal, I launch GDB from the same path and issue these commands in sequence:
gdb ./vmlinux
(gdb) target remote localhost:1234
(gdb) hbreak start_kernel
(gdb) c
I did not provide a rootfs, as I am not interested in a full working system as of now, just the kernel. I also tried combinations of hbreak/break.
The kernel just boots and reaches a kernel panic as rootfs cannot be found... expected. I want it to stop at start_kernel and then step through the code.
observation: if I set an immediate breakpoint, it works and stops, but not on start_kernel / startup_64 / main
Is it possible that qemu is not calling all these functions, or is it being masked in some way?
Kernel: 4.13.4
GDB: GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.3) 7.7.1
GCC: gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
system: ubuntu 14.04 LTS
NOTE: This exact same procedure worked with kernel 3.2.93, but does not work with 4.13.4, so I guess some more configurations are needed. I could not find resources online which enabled this debug procedure for kernel 4.0 and up, so as of now I am continuing with 3.2, any and all inputs on this are welcome.