qemu + gdb 调试内核

原文转载自 https://blog.csdn.net/hoppboy/article/details/16886515

参考文章:

http://blog.csdn.net/heli007/article/details/7187586  (比较推荐)

http://blog.chinaunix.net/uid-26009923-id-3825761.html (过程详细,但对于gdb7.4 安装可能存在问题) 

http://blog.csdn.net/sahusoft/article/details/8888613 (gdb bug 解决,可以用7.5 或者之上版本) 

http://blog.csdn.net/zxl1217/article/details/3450153(vmlinux 和 bzImge initrd-x.x.x.img 介绍)

http://hi.baidu.com/widebright/item/90a80f0a3dd6fb036c9048da (vmlinx 和bzimage 的形成)


1. 下载及安装qemu http://wiki.qemu.org/Testing 


test 链接下,可以下载到不同版本内核的img,可以测试qemu是否安装成功


2. 下载要调试的内核版本,如3.0.7  (本文中用到的)

编译内核 http://www.cyberciti.biz/tips/compiling-linux-kernel-26.html

make menuconfig 配置内核 (下次最好能够去掉无关的选项,减少编译时间和空间)

具体编译选项内容参考: http://lamp.linux.gov.cn/Linux/kernel_options.html来对配置文件进行裁剪

make 即可在arch/boot/x86_64/bzImage

3. gdb 安装和编译,自带的gdb 远程调试时会发生段溢出。修改见上面参考文章

4.  qemu 调试选项启动  qemu –S –kernel arch/x86/boot/bzImage –hda  ubuntu9.10_32.img –append “root=dev/hda”

具体关于qemu的选项,见 http://jianlee.ylinux.org/Computer/Software/kvm-qemu.html

比较重要的是调试选项,如-S ,-s是等待gdb连接到1234,写了之后就在启动qemu之后,不需要ctrl+alt+2中输入 gdbserver tcp:1234了 ,直接等待gdb连接即可。

linux 启动选项 :-kernel 指定内核启动,而不需要将其安装在硬盘镜像中

5. 用gdb 远程连接 qemu调试端口就可以调试了

gdb vmlinux (加载调试内核的符号表)

(gdb) target remote  localhost:1234 

然后调试即可。 





猜你喜欢

转载自blog.csdn.net/m0_37329910/article/details/85337167