linux下qemu调试linux内核
来源:互联网 发布:网络棋牌交流群 编辑:程序博客网 时间:2024/06/03 13:38
编译内核
- 下载kernel源码
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.gitcd linux-stable/
-配置内核
make menuconfig:
在kernel hacking下的选项中选中(实用空格键,星号*代表选选中)compile the kernel with debug info
注意【记得提前安装libncurses5-dev】,或者其他编译内核需要的依赖包
│ │ [*] 64-bit kernel │ │
│ │ General setup —> │ │
│ │ [*] Enable loadable module support —> │ │
│ │ -*- Enable the block layer —> │ │
│ │ Processor type and features —> │ │
│ │ Power management and ACPI options —> │ │
│ │ Bus options (PCI etc.) —> │ │
│ │ Executable file formats / Emulations —> │ │
│ │ [*] Networking support —> │ │
│ │ Device Drivers —> │ │
│ │ Firmware Drivers —> │ │
│ │ File systems —> │ │
│ │ Kernel hacking —> │ │
│ │ Security options —> │ │
│ │ -*- Cryptographic API —> │ │
│ │ [*] Virtualization —> │ │
│ │ Library routines —> │ │
按K键选中Kernel hacking之后按enter键进入子选项,按K键选移动到 Kernel debugging选项并按空格键选中为星号*(如下)
│ │
[*] Magic SysRq key │ │
│ │ (0x1) Enable magic SysRq key functions by default │ │
│ │ [*] Enable magic SysRq key over serial │ │
│ │ [*] Kernel debugging │ │
│ │ Memory Debugging —> │ │
│ │ [ ] Code coverage for fuzzing │ │
│ │ [ ] Debug shared IRQ handlers │ │
│ │ Debug Lockups and Hangs —>
进入kernel debuging 选中compile the kernel with debug info选项
保存退出
- 执行编译
make -j16
编译内核
编译完成之后生成bzImage和vmlinux二进制内核镜像就可以用来调试。
linux-stable$ ls arch/x86_64/boot/bzImage -lhlrwxrwxrwx 1 emindsoft emindsoft 22 10月 22 14:32 arch/x86_64/boot/bzImage -> ../../x86/boot/bzImagelinux-stable$ ls -lh-rwxrwxr-x 1 emindsoft emindsoft 443M 10月 21 11:52 vmlinux
更新gdb
详细信息可以查看这里修改方法这里写代码片
由gdb-7.8.tar.gz下载最新的gdb(7.8)到/opt目录下【目录随意选】
解压缩:tar zxvf gdb-7.8.tar.gz
修改代码【否则调试内核会出现remote ‘g’ packet reply is too long的问题】
cd gdb-7.8/gdb
vim remote.c
按照如图所示修改代码【针对7.8版本】:
代码如下:
if (buf_len > 2 * rsa->sizeof_g_packet) { rsa->sizeof_g_packet = buf_len ; for (i = 0; i < gdbarch_num_regs (gdbarch); i++) { if (rsa->regs->pnum == -1) continue; if (rsa->regs->offset >= rsa->sizeof_g_packet) rsa->regs->in_g_packet = 0; else rsa->regs->in_g_packet = 1; } }
安装gdb
在主目录gdb-7.8下依次运行命令(你也可以选择自己想要的version):
./configuremakemake install
启动qemu
- 在启动之前,我们需要initrd.img文件,至于该文件的作用大家可自行百度。这里我们直接从宿主ubuntu系统中cp过来:
cd linux-stable/
cp /boot/initrd.img-4.4.0-97-generic ./ - 开始启动
cd linux-stable/
qemu-system-x86_64 -S -kernel arch/x86_64/boot/bzImage -initrd ./initrd.img-4.4.0-97-generic -m 1024
// -m表示非配内存大小为128Mb, -S表示以调试模式启动,暂定在启动界面
// -S表示“冷冻”虚拟机,等待调试器发出继续运行命令;
// -kernel表示要调试的内核镜像
注: 这里并没有制作文件系统,大家可以更具自己的需求添加
同时摁ctrl+alt+2进入qemu命令行界面, 输入gdbserver tcp::1234
,建立并等待gdb连接(如下图)
- 摁ctrl+alt+1返回qemu
另外开一个终端到linux-stable主目录下,输入命令:gdb vmlinux
在gdb下输入:target remote localhost:1234
连接qemu中开启的gdbserver(如下图)
设置断点【举例:b do_fork】
输入命令c开始执行到断点处
输入命令n执行下一个语句
参考链接:
ubuntu14.04 下qemu调试linux内核
- linux下qemu调试linux内核
- Qemu调试Linux内核
- ubuntu14.04下qemu调试linux内核
- ubuntu14.04下qemu调试linux内核
- 使用qemu调试linux内核
- 用qemu调试linux内核
- linux内核调试+qemu+eclipse
- linux内核调试+qemu+eclipse
- 在Linux下运行Qemu模拟AArch64硬件调试内核
- linux工具---用qemu调试linux内核
- linux工具---用qemu调试linux内核
- 使用Qemu来调试linux内核
- eclipse + qemu 编译调试Linux内核
- ubuntu--qemu调试linux内核环境搭建
- Eclipse CDT + QEMU 调试linux内核
- eclipse + qemu 编译调试Linux内核
- linux内核调试: qemu + eclipse 组合
- qemu + eclipse 组合:linux内核调试
- C++ 类的const成员函数
- 四大组件--Service
- Hadoop显示调试信息以及关闭
- js策略模式
- 在Django中使用memcached缓存
- linux下qemu调试linux内核
- matlab的padarray函数
- Struts 2访问Servlet API
- NEERC 17 H. Palindromic Cut 暴力(回文)
- MySQL学习(0) 安装MySql(windows)
- [刷题]UVA11248
- 颜色模式
- 泛型的作用及其基本概念
- leetcode-121. Best Time to Buy and Sell Stock