|
安装 QEMU 参考:http://www.groad.net/bbs/read.php?tid-3071.html
在运行 QEMU 开始要调试时出现 ”VNC server running on`127.0.0.1:5900'“ 的提示,解决办法参考:http://www.groad.net/bbs/read.php?tid-3161.html
先下载 Linux 内核,在 make menuconfig 时,将 kernel hacking 选项中,将绝大部分都勾选,然后 make bzImage 编译内核,不用 make modules_install 和 make install 这些步骤了,我们的目的只是获取 bzImage 和 vmlinux 两个文件。
编译好内核后,将这 bzImage 和 vmlinux 拷贝到随意一个工作目录。
接着从 http://wiki.qemu.org/Download 下载 linux-0.2.img.bz2 磁盘镜像文件,解压缩后得到的文件是 linux-0.2.img ,也将它拷贝到和 bzImage 及 vmlinux 一块。
运行下面用 qemu 命令进行调试: $ qemu -S -kernel bzImage -hda linux-0.2.img -append "root=/dev/hda" 这时会弹出一个黑色的窗口:
![]()
在上面的命令中:
-S 参数表示在启动时CPU 停止(见上图的标题栏中的 stopped) 并等待 GDB 连接。
-kernel bzImage 表示指定 bzImage 作为内核镜像文件。
-hda linux-0.2.img 表示 linux-0.2.img 中的文件系统都放在 hda 中。
-append "root=/dev/hda" :-append 后接命令行参数,这里表示根文件系统设备使用 hda 。
使用 Ctrl + Alt + 2 组合键切换到 QEMU 终端,即上面的黑色窗口中,然后输入 gdbserver ,启动 gdbserver 服务:
![]()
这时启动另外一个终端窗口,输入 gdb vmlinux 命令进行调试:
beyes@debian:~/kernel$ gdb vmlinux
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb)
给内核函数下一个断点,比如是 start_kernel() ,然后运行,看是否能成功断下来:beyes@debian:~/kernel$ gdb vmlinux
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) b start_kernel
Breakpoint 1 at 0xc13f05a6: file init/main.c, line 517.
(gdb) target remote localhost:1234 /*使用 gdbserver 进行调试命令*/
Remote debugging using localhost:1234
[New Thread 1]
0x0000fff0 in ?? ()
(gdb) c
Continuing.
Breakpoint 1, start_kernel () at init/main.c:517
517 smp_setup_processor_id();
(gdb) 已经可以调试了,但这只是整个调试工作中的第一步。 |
|