http://fengye110.72pines.com/archives/62
http://blog.csdn.net/gdt_a20/article/details/7231652
1.内核
cd linuxmkdir build
“CONFIG_DEBUG_INFO=y”
“CONFIG_KGDB=y”
“CONFIG_KGDB_SERIAL_CONSOLE=y” this one is optional
make -C $(pwd)/../ O=$(pwd) defconfig
cd build
make bzImage -j8
3.用 qemu 运行调试内核
直接运行
/home/richard/git/qemu/i386-softmmu/qemu-system-i386 -drive file=ubuntu.img -boot dc -monitor stdio -kernel /home/richard/git/linux-2.6/build/arch/x86/boot/bzImage -append "root=/dev/sda1 rw console=ttyS0,115200n8" -enable-kvm -netdev user,id=usernet -device rtl8139,netdev=usernet -serial telnet:localhost:4321,server,nowait
调试模式
/home/richard/git/qemu/i386-softmmu/qemu-system-i386 -drive file=ubuntu.img -boot dc -monitor stdio -kernel /home/richard/git/linux-2.6/build/arch/x86/boot/bzImage -append "root=/dev/sda1 rw console=ttyS0,115200n8" -S -s
其中:
bzImage -- 生成的内核镜像。
rootfs.gz -- 上面制作的 rootfs ramdisk
-hda -- 是虚拟机的硬盘,没什么用
-S -- 让 qemu 在系统启动前停止,等待 gdb 的连接
-s -- 让gdbserver 通过 tcp:1234 于 gdb 连接
qemu 运行后会有一个黑框这是在等待 gdb 的链接.
$ gdb /kernel/vmliux # 获取内核符号表
(gdb) target remote localhost:1234 #连接到qemu 里的 gdbserver
(gdb) b start_kernel #在 start_kernel处设断点
(gdb) c #运行内核
可在中途 按 ^c 中断内核