- 论坛徽章:
- 0
|
背景:
调试FreeBSD内核时:
我们的内核代码存放的路径为/kerndebug/sys
我们要调试的内核的配置文件为/kerndebug/sys/i386/conf/KERNDEBUG
已经在QEMU中装好的FreeBSD的硬盘文件为/kerndebug/freebsd.img
具体步骤:
1.编译内核注意在/kerndebug/sys/i386/conf/KERNDEBUG中需要选项
makeoptions DEBUG=-g
[prime@localhost]$cd /kerndebug/sys/i386/conf
[prime@localhost]$config KERNDEBUG
[prime@localhost]$cd ../compile/KERNDEBUG
[prime@localhost]$make cleandepend
[prime@localhost]$make depend NO_MODULES=1
[prime@localhost]$make NO_MODULES=1
OK,现在我们得到两个文件kernel与kernel.debug
2.把kernel复制到/kerndebug/freebsd.img
[root@localhost]#mdconfig -a -t vnode -f /kerndebug/freebsd.img
md0
[root@localhost]#mount /dev/md0s1a /mnt
#保存从前的内核,也许并不需要保存
[root@localhost]#mv /mnt/boot/kernel /mnt/boot/kernel.old
[root@localhost]#mkdir /mnt/boot/kernel
[root@localhost]#cp /kerndebug/sys/i386/compile/kernel
> /mnt/boot/kernel/
[root@localhost]#umount /mnt
[root@localhost]#mdconfig -d -u 0
3.开始调试内核
[prime@localhost]$qemu -hda /kerndebug/freebsd.img -s&
[prime@localhost]$cd /kerndebug/sys/i386/compile/KERNDEBUG
[prime@localhost]$gdb kernel.debug
(gdb)target remote localhost:1234
同样的道理,我们也可以调试Linux kernel。
背景:
新下载解压后的内核代码在/linux-2.6.15,基本系统使已经用Gentoo的base,
qemu的硬盘文件为/linux.img,gentoo的安装盘为gentoo.iso
1.编译内核
[prime@localhost]$cd /linux-2.6.15/
[prime@localhost]$make menuconfig
注意打开内核调试选项,把符号表编译进内核
[prime@localhost]$make
如果有modules,安装modules,注意不要覆盖了现在使用的modules。
[prime@localhost]$make modules_install
现在在/lib/modules/2.6.15/已经那装了关于modules的文件,并且得到了
两个文件,/linux-2.6.15/vmlinux /linux-2.6.15/arch/i386/boot/bzImge
2.把modules文件安装到硬盘文件linux.img
[prime@localhost]$qemu -cdrom gentoo.iso -hda linux.img -boot d&
在host机上起动sshd,在qemu中,挂载硬盘文件
[root@localhost]#mount -t ext3 /dev/hda2 /mnt/gentoo
[root@localhost]#mkdir /mnt/gentoo/lib/modules/2.6.15
[root@localhost]#scp prime@xxx.xxx.xxx.xxx:/lib/modules/2.6.15/*
>/mnt/gentoo/lib/modules/2.6.15/
[root@localhost]#umount /mnt/gentoo
[root@localhost]#shutdown -h now
3.现在开始调试
[prime@localhost]$qemu -kernel
>/linux-2.6.15/arch/i386/boot/bzImage -append root=/dev/hda2
>-hda linux.img -s &
[prime@localhost]$cd /linux-2.6.15/
[prime@localhost]$gdb vmlinux
(gdb)target remote localhost:1234
OK,现在可以用gdb调试内核了,enjoy it!
=====================================
本来在blog上的,没时间维护就关掉了,帖过来吧. |
|