When messing around with a linux kernel module I needed to have a debuggable kernel with symbols. It was a roller coaster ride from there to what I got working because of multiple reasons that I will try to outline here.
start_kernelhas same address (/proc/kallsyms) in booted kernel as your vmlinux file.
Let us run a working CentOS 7 with debug symbols in qemu and debug with gdb.
Start up a simple vagrant box with the minimal centos image.
$ vagrant init centos/7 $ vagrant up
SSH into the vm and do whatever permanant modifications (like installing packages etc..) are necessary.
$ vagrant ssh
This step is very distro dependent. Download debug info for running kernel either using package manager or direct download. Get those debug packages onto host and extract them.
$ uname -r 3.10.0-957.12.1.el7.x86_64 $ debuginfo-install --downloadonly 3.10.0-957.12.1.el7
Remove all unnecessary systemd units that you don't need. Make the kernel boot into console mode, disable kaslr and enable kgdb by adding following line to kernel parameters.
# Add this to default parameters in /etc/default/grub # console=ttyS0,115200 kgdboc=ttyS0,115200 nokaslr $ grub2-mkconfig -o /boot/grub2/grub.cfg
Use vagrant snapshots at this stage to keep it easy to revert if necessary.
Start the kernel with qemu.
-enable-kvmto use linux kvm
-hdato specify hd0 for vm
-nographicto start console only mode of qemu
-sto start gdbserver of qemu on :1234 (check help)
-mto specify memory which we set as 3 gigs here.
$ qemu-system-x86_64 -enable-kvm -hda path_to_virtualmachine_disk.vmdk -nographic -s -m 3072
On host, from the directory where debug rpms were extracted let us start gdb and point it to source
$ cat kerinit.gdb dir usr/src/debug/kernel-3.10.0-957.12.1.el7/linux-3.10.0-957.12.1.el7.x86_64 target remote :1234 $ gdb -x kerninit.gdb usr/lib/debug/lib/modules/3.10.0-957.12.1.el7.x86_64/vmlinux
Following is a breakpoint hit at