使用qemu调试arm内核

参考书籍《奔跑吧Linux内核》--笨叔

下载Linux-5.0源码

bash 复制代码
https://benshushu.coding.net/public/runninglinuxkernel_5.0/runninglinuxkernel_5.0/git/files

或者直接git源码

bash 复制代码
git clone https://e.coding.net/benshushu/runninglinuxkernel_5.0/runninglinuxkernel_5.0.git

安装必要的包

bash 复制代码
sudo apt-get install qemu libncurses5-dev gcc-aarch64-linux-gnu build-essential bison flex libssl-dev qemu-system-arm

切换到rlk_5.0分支

bash 复制代码
git checkout rlk_5.0

编译内核

bash 复制代码
~/kernel/runninglinuxkernel_5.0$ ./run_debian_arm64.sh build_kernel

编译文件系统

bash 复制代码
~/kernel/runninglinuxkernel_5.0$ sudo ./run_debian_arm64.sh build_rootfs

使用qemu运行Debian系统

bash 复制代码
/kernel/runninglinuxkernel_5.0$ ./run_debian_arm64.sh run

running:

或者使用:

bash 复制代码
qemu-system-aarch64 -m 1024 -cpu max,sve=on,sve256=on -M virt,gic-version=3,its=on,iommu=smmuv3 -nographic -smp 4 -kernel arch/arm64/boot/Image -append "noinitrd nokaslr loglevel=8 sched_debug root=/dev/vda rootfstype=ext4 rw crashkernel=256M vfio.dyndbg=+pflmt irq_gic_v3_its.dyndbg=+pflmt iommu.dyndbg=+pflmt irqdomain.dyndbg=+pflmt" -drive if=none,file=/home/book/kernel/runninglinuxkernel_5.0/rootfs_debian_arm64.ext4,id=hd0 -device virtio-blk-device,drive=hd0 --fsdev local,id=kmod_dev,path=./kmodules,security_model=none -device virtio-9p-pci,fsdev=kmod_dev,mount_tag=kmod_mount

进入虚拟机界面

登录

用户名:root或benshushu

密码:123

成功进入qemu

bash 复制代码
benshushu:~# ifconfig
bash 复制代码
benshushu:~# gcc -v

如果没有可以在线安装

在qemu和Ubuntu之间共享文件

:~/kernel$ cp test.txt runninglinuxkernel_5.0/kmodules/

benshushu:~# ls /mnt/

README arm64_virt.dts rlk_lab test.txt

benshushu:~# vi /mnt/test.txt

退出qemu

bash 复制代码
Ctrl +a  x

或者之间结束qemu

bash 复制代码
ps -e | grep qemu
 kill -9 48977

使用GDB调试

安装支持不同处理器架构的gdb

bash 复制代码
 sudo apt install gdb-multiarch

运行脚本启动qemu和GDB

bash 复制代码
:~/kernel/runninglinuxkernel_5.0$ ./run_debian_arm64.sh run debug

开启另外一个终端:

远程调用GDB调试

bash 复制代码
:~/kernel/runninglinuxkernel_5.0$ gdb-multiarch --tui  vmlinux

设置 aarch64架构

bash 复制代码
(gdb)set architecture aarch64

通过1234端口远程连接到qemu虚拟机。

bash 复制代码
(gdb)target remote localhost:1234

在内核的start_kernel 处设置断点

bash 复制代码
(gdb)b start_kernel

运行测试

bash 复制代码
(gdb)c 

将跳转到断点 start_kernelchu

退出 GDB

bash 复制代码
(gdb)q/quit

方法二:图形化界面调试工具

安装 Eclipse-CDT插件

下载Eclipse-CDT插件

bash 复制代码
https://projects.eclipse.org/projects/tools.cdt

Download Packages

bash 复制代码
https://projects.eclipse.org/projects/iot.embed-cdt

下载x86_64 Linux安装包

Download

Linux x86_64 | AArch64

https://www.eclipse.org/downloads/download.php?file=/oomph/epp/2023-09/R/eclipse-inst-jre-linux64.tar.gz

安装java运行环境。

bash 复制代码
sudo apt-get install openjdk-13-jre

安装

bash 复制代码
hudahua@VirtualBox:~/workspace/tools$ tar xzf eclipse-inst-jre-linux64.tar.gz
hudahua@VirtualBox:~/workspace/tools/eclipse-installer$ ./eclipse-inst

安装 Eclipse IDE for C/C++ Developer

图形界面下载和调试较慢,后期不使用了。

相关推荐
m0_6371469313 分钟前
嵌入式全栈面试指南:TCP/IP、C 语言基础、STM32 外设与 RT‑Thread
arm开发
satadriver2 天前
Qemu arm操作系统开发环境
arm开发
待什么青丝3 天前
【TMS570LC4357】之相关驱动开发学习记录1
c语言·arm开发·驱动开发·学习
南玖yy4 天前
x86 汇编逻辑运算全解析:从【位操作】到实际应用(AND,OR,NOT,XOR,TEST)
开发语言·汇编·arm开发·后端·架构·策略模式
菜只因C5 天前
嵌入式系统:从技术原理到未来趋势(驱动程序篇)
arm开发
!chen7 天前
鲲鹏Arm+麒麟V10 K8s 离线部署教程
java·arm开发·kubernetes
ScilogyHunter7 天前
ARM P15协处理器指令详解:架构、编程与应用实践
arm开发·协处理器指令·cp15
apolloyhl8 天前
1-Wire 一线式总线:从原理到实战,玩转 DS18B20 温度采集
arm开发·stm32·单片机·嵌入式硬件
二进制coder8 天前
芯片:数字时代的算力引擎——鲲鹏、升腾、海光、Intel 全景解析
arm开发·架构·硬件架构
荆楚闲人9 天前
Keil MDK5.37或更高版本不再预装ARM Compiler Version5导致编译错误的解决方法
arm开发