使用gdb和虚拟机调试内核

调试内核很麻烦,即使是有了虚拟机的帮助。在这里记下一些关键的东西,以备忘 。

#  编译内核后, 用新内核启动系统失败,报错 “unable to mount fs ….” 之类.

需要用 update-initramfs 生成initram。

# 对于grub2,我增加了一个自定义的grub开机启动项用来调试内核,如下:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
echo "Add Debugging entry"
cat << EOF
menuentry "Debian debug 3.7.4"{
set root=(hd0,1)
linux /boot/vmlinuz-3.7.4 root=/dev/vda1 ro quiet kgdboc=ttyS0,115200 kgdbwait
initrd /boot/initrd.img-3.7.4
}
EOF

/////////

the above grub configuration file resides in /etc/grub.d/

# client在虚拟机里启动后在内核调试断点处停下。这时在host机用gdb调试.

# gdb vmlinux

set remotebaud 115200

target remote /dev/pts/0

此时gdb输入continue命令让客户机的系统继续运行。如果想断下正在运行的client内核,在client机中使用magic SysR:  echo "g" > /proc/sysrq-trigger