A screencast demonstrating roughly the same thing is available at: http://blip.tv/file/586651
For iTunes users there's a videopodcast at: http://takis.blip.tv/rss/itunes/
Download the Linux kernel sourcecode from http://www.kernel.org/. For example, the current kernel version is 2.6.23, a direct link would be http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.23.9.tar.bz2
Extract the Linux kernel sourcecode:
cd /usr/local/src
tar xvjf linux-2.6.23.9.tar.bz2
We will build the Linux kernel in a different directory:
mkdir -p /mnt/build/linux-2.6
Then copy the provided kernel configuration into this directory giving it a new name ".config". The following commands will then use this as a base-configuration to start from.
Next, we'll configure the kernel. Just keep pressing enter to use the default answers to all the questions that the kernel configuration program will ask you.
cd /usr/local/src/linux-2.6.23
make oldconfig O=/mnt/build/linux-2.6
Next, make the kernel a bit easier to debug:
make menuconfig O=/mnt/build/linux-2.6
And enable the following options: In the "Kernel hacking" menu enable both "Compile the kernel with debug info" and "Compile the kernel with frame pointers".
Now, we'll fire up Eclipse with the CDT plugin. You can download Eclipse with the CDT plugin from http://www.eclipse.org/downloads/. You'll need to download "Eclipse IDE for C/C++ Developers".
Get rid of the intro screen.
You'll get an empty workspace as shown in the screenshot. First disable automatic building, by using the "Window->Preferences" menu, selecting "General->Workspace" and deselecting "Build automatically". Eclipse will perform a time consuming indexing operation which you can disable by using the "Window->Preferences" menu, selecting "C/C++->Indexer" and switching from "Fast C/C++ Indexer" to "No Indexer".
Start a new project, by using File->New->Project...
Then select "C Project", "Makefile project", "Empty Project".
Now enter a project name and specify a specific directory for the project sourcecode. To do this, first uncheck the "Use default location" checkbox.
Finally click "Finish".
If you hadn't disabled indexing, Eclipse will now start indexing the Linux kernel sourcecode. This will take a long time.
You'll see a progressbar which might give you an indication on how long it might take to complete.
Eclipse finished indexing the kernel sourcecode. Now, we're ready to configure our debugger. Right-click on the project-name in the left pane (Project explorer) and select "Properties".
We want to modify the default build command and the location where the build files should go.
Uncheck "Use default build command" and enter make CC=gcc-3.4 O=/mnt/build/linux-2.6
Modify the build location by clicking the "File system..." button and browsing to /mnt/build/linux-2.6
Through the menu-bar select "Project->Build all" or press "Ctrl-b".
After some time the Linux kernel build will be completed and you see "bzImage is ready" appear in the Eclipse Console output.
Next, we'll run our kernel binary using the Qemu system emulator. The nice thing about Qemu is that besides the normal virtual HD, floppy and ISO image booting, it can also boot Linux kernels directly. And, Qemu provides a GDB-stub to which we can connect from our Eclipse debugger. The "-s" switch activates this GDB-stub. The "-S" switch makes sure Qemu doesn't start running before we're ready (it freezes the CPU at startup).
Because the CPU is "frozen" at startup, the Qemu window won't show anything useful yet.
Through the menubar, select "Run->Debug Configurations...". Double-click "C/C++ Local Application". Modify the "C/C++ Application" textentry to point to the actual Linux kernel, being /mnt/build/linux-2.6/vmlinux
Click on the "Debugger" tab, and in the "Debugger" listbox select the "gdbserver Debugger". Next, modify the "Stop on startup at:" to "start_kernel". Below this, you'll notice a frame named "Debugger Options"; click the "Connection" tab in this frame and modify the "Type" to "TCP" and the "Port number" to 1234. Continue by clicking the "Debug" button.
Eclipse might compile and link a bit, but will finally launch the debugger and ask if you want to switch to the debugging perspective. Say yes.
The next screenshot shows the debugging perspective. Just like with normal applications, you'll see that the line it is about the execute is highlighted.
In the Qemu window, you'll notice some output already. This is the output which happened in functions preceding the start_kernel() function.
...
By using "Run->Step over" or pressing the "F6" key, you can execute the kernel code line by line and examine what's happening.
If you want to see the assembly instructions which are being executed, you can add a view which displays this by selecting "Windows->Show View->Disassembly".
There's a register view too, as can be seen in the next screenshot. Registers who's contents has been altered by the previous execution step are highlighted in yellow.
You can add breakpoints, inspect variables, inspect memory and much more, but as you keep running the kernel you'll run in trouble as we did not specify a true harddisk image for Qemu. So, you'll get the following output in the Qemu window, because the Linux kernel could not find a root filesystem on our fake harddisk image "/dev/zero".
That's it. Hopefully the above is useful (and fun) for anyone :)
分享到:
相关推荐
EclipseCDT+QEMU调试linux内核.pdf
1、调试相关参数配置好后就可以开始调试了,回到 Env 命令行界面输入 qemu-dbg.bat 2、点击 eclipse 调试配置界面的 “Debug” 按钮
调试linux内核用的虚拟机.把linux内核放在该平台下运行,然后在物理机下调试内核。
Ubuntu18.04+Qemu调试Linux内核实验记录 实验环境 操作系统:Ubuntu18.04 依赖项安装: sudo apt-get install texinfo sudo apt-get install libncurses5-dev sudo apt-get install m4 sudo apt-get install flex ...
本文章是关于Codeblocks+Qemu——在IDE里面实现U-boot指令级调试。
使用qemu调试linux5.10内核aarch64,并可以调试head.S,并使用sourceinsight添加linux内核实际使用的文件。总结网上的各个资料,实际应用了一遍,整理整个过程中的文档,以备查看
arm, x86 两个平台的qemu 模拟器的安装,gdb 的安装,内核的编译的核调试 ,包括根文件系统的制作,实测的启动参数
Linux 内核实验室 —— 基于 Docker/Qemu 的极速 Linux 内核学习、开发和测试环境。社区制作了多款免安装的随身Linux Lab系统盘,某宝检索”泰晓 Linux"快速体验。Linux Lab 是一个开源软件,不提供任何保证,请自行...
此配置文件.config是针对QEMU模拟器裁剪的linux-5.5.9内核源码配置,以减少编译时间。 https://blog.csdn.net/eidolon_foot/article/details/104905084。
Linux 内核实验室 —— 基于 Docker/Qemu 的极速 Linux 内核学习、开发和测试环境。社区制作了多款免安装的随身Linux Lab系统盘,某宝检索”泰晓 Linux"快速体验
这里说明下,本人调试的内核版本是2.6.11.12,为什么去调试这么“古老”的版本?原因不多说了,你手头也许正拿着ULK3,而它针对的内核版本正是2.6.11,有比这更好的理由吗?而且这个版本不算旧,已不算新,我认为还...
本文档详细介绍了:在windows10主机的vmware软件中安装ubuntu18.04系统,再基于x86架构的ubuntu18.04,搭建openEuler_aarch64架构的qemu虚拟机。
使用qemu虚拟机环境实现linux内核源码级的调试
QEMU+树莓派3B调试Linux-设备树以及原版内核文件
本文将为大家介绍两种Linux中用GDB与QEMU来调试内核分析的方法。
《【黑盒模糊测试】路由器固件漏洞挖掘实战--AFL++ qemu_mode》配套练习实例,每篇文章下方有我的练习方式,加我免费获取
RT-THREAD 文档中心上海睿赛德电子科技有限公司版权 @2019Friday 28th September, 2018目录目录本文的目的和结构本文的目的和
W命令行开关集成在AFL ++中,因此此存储库中的脚本是旧式的,但示例仍然有效一组使用AFL ++ QEMU模糊Win32二进制文件的帮助程序和示例要求要用AFL ++ QEMU模糊Win32 PE应用程序,必须确保Linux发行版能够在没有预...
27号是 MS-DOS 8.0 + QEMU 0.13.0,这个系统也不能在 PCE 上运行,只好用 QEMU 模拟器了,可惜,这个版本只有软盘版,无法制作成硬盘版,其格式化命令已去掉了 /S 参数,SYS 系统传输命令也已无用了,真是...
使用qemu模拟器学习linux内核编译内核,制作rootfs,配置qemu参数,主要用于使用gdb学习,分析调试Linux内核,uboot 如何使用 sudo apt-get install gdb-arm-none-eabi gcc-arm-linux-gnueabi ./scripts/download.sh...