Linux内核调试环境搭建
参考《奔跑吧Linux内核》第6章踩坑记录
-
直接安装aarch64-linux-gnu-gcc,manjaro下不要折腾arm-linux-gnueabi,安装很复杂。
-
使用5.15.x内核,编译时需要打开DEBUG_FS和hotplug,不然启动会有错误日志
DEBUGS_FS配置搜索:
│ -> Kernel hacking │ │ -> Generic Kernel Debugging Instruments │ │ -> Debug Filesystem (DEBUG_FS [=y])
hotplug配置,搜索
│ -> Device Drivers │ │ -> Generic Driver Options │ │ (2) -> Support for uevent helper (UEVENT_HELPER [=y])
-
使用O0编译kernel
修改根目录下Makefile,将O2替换为O0。
O2以上优化掉的代码,在O0未被优化报链接找不到实现,注释相关报错代码即可。
-
qemu启动命令
qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -m 2048 -smp 2 -kernel arch/arm64/boot/Image --append "rdinit=/linuxrc console=ttyAMA0" -S -s
-
Qt中配置debug client。
Attaching to running gdb server.
kit: aarch64-linux-gnu
本地执行档:linux-5.15.39/vmlinux
override server channel: localhost:1234
-
clangd查看代码问题
clangd日志报错:
E[00:51:43.425] Failed to prepare a compiler instance: unknown target ABI 'lp64' I[00:51:43.425] --> reply:textDocument/codeAction(33) 7 ms, error: invalid AST V[00:51:43.425] >>> {"error":{"code":-32001,"message":"invalid AST"},"id":33,"jsonrpc":"2.0"}
解决办法:删除compile_comands.json中所有的一下字段:
"-fno-allow-store-data-races", "-mabi=lp64", "-fconserve-stack",
评论区