QEMU + GDB 内核调试环境

QEMU + GDB 内核调试环境

基于ubuntu14.04

安装依赖库

apt-get install aptitude libssl-dev libpixman-1-dev flex bison m4 libncurses5-dev libssl-dev
apt-get upgrade

编译内核

编译内核共两条命令:

make menuconfig

此时需要注意两个选项:

kernel hacking –> kernel debugging –> compile the kernel with debug info
Processor type and features -> Randomize the address of the kernel image

而后

make bzImage -j4

这样就生成了bzImage和vmlinux
bzImage 位于Linux-4.20.4/arch/x86/boot/bzImage
vmlinux 位于linux-4.20.4/vmlinux

编译QEMU

下载2.12.0版本
https://download.qemu.org/

为了调出QEMU窗口,需安装所需要的SDL库

apt-get install libsdl1.2-dev

对于QEMU,需要重新配置

./configure --target-list=x86_64-softmmu

执行以上指令后,可以从输出中看到:SDL support: yes
而后编译

make & make install

编译GDB

下载7.8版本
http://ftp.gnu.org/gnu/gdb/

修改remote.c

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;  
      }  
   }  

而后编译安装

make & make install

Busybox建立最小文件系统

编译busybox
下载1.25版本
https://busybox.net/

编译

cd busybox-1.25.0
make defconfig
make menuconfig

选中
Busybox Settings -> Build Options -> Build BusyBox as a static binary (no shared libs)

而后编译安装
make & make install

之后的操作按照博客https://blog.csdn.net/jasonLee_lijiaqi/article/details/80967912即可

调试

起一个Terminal

qemu-system-x86_64 -kernel arch/x86/boot/bzImage -initrd ../initramfs.img -append "console=ttyS0" -S -s -nographic 

另起一个Terminal

gdb /home/pany/Desktop/linux-4.20.4/vmlinux

进入gdb之后
target remote:1234

即可调试

问题:
4.15以上版本出现的问题
在gdb里边设置断点后,断点不起作用,qemu里运行的系统没有在相应的断点处stop,直接运行到挂接文件系统。
取消选项:
Process type and features
-[ ] Randomize the address of the kernel image (KASLR)

在这里插入图片描述

参考文档:
https://blog.csdn.net/jasonLee_lijiaqi/article/details/80967912
https://blog.csdn.net/barry283049/article/details/42970739
https://www.phoronix.com/scan.php?page=news_item&px=Linux-4.8-ASLR-Kernel-Mem-Sects

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值