vscode GDB 调试linux内核 head.S

遇到的问题

此前参考如下文章

https://zhuanlan.zhihu.com/p/510289859

已经完成了在ubuntu 虚拟机用vscode 调试linux 内核。但是美中不足的是,断点最早只能加在__primary_switched() 函数。无法停在更早的断点上,比如ENTRY(stext) 位置。参考《奔跑吧linux 内核(第2版)》卷2,3.1.5节如下位置,可以在gdb -tui 中从 ENTRY(stext) 开始单步调试,但是远不如vs code 方便。于是在vs code 官方文档中寻找方法。

解决方法

参考官方文档 https://code.visualstudio.com/docs/cpp/launch-json-reference,有stopAtConnect 参数。其作用是在connect 后立即停止。因此,修改launch.json如下:

json 复制代码
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "kernel debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/vmlinux",
            "cwd": "${workspaceFolder}",
            "MIMode": "gdb",
            "miDebuggerPath":"/usr/bin/gdb-multiarch",
            "miDebuggerServerAddress": "localhost:1234",
            "serverLaunchTimeout": 1,
            "stopAtConnect": true
        }
    ]
}

先运行如下qemu 启动命令,注意要有 -S 参数

bash 复制代码
qemu-system-aarch64 -m 512M -smp 1,sockets=1,cores=1 -cpu cortex-a57 -machine virt -kernel kernel/linux-5.4.220/arch/arm64/boot/Image -append "rdinit=/linuxrc nokaslr console=ttyAMA0 loglevel=8" -nographic -s -S

后在vs code 中执行add-symbol-file 等操作即可,如下

相关推荐
Crazy________28 分钟前
28Rsync免密传输与定时备份
linux·运维·服务器
阿巴~阿巴~1 小时前
信号产生机制全解析:从硬件异常到软件触发的深度探索
linux·运维·服务器
坐望云起1 小时前
Hyper-V + Centos stream 9 搭建K8s集群(一)
linux·kubernetes·centos
sky北城3 小时前
linux基本系统服务——DNS服务
linux·运维·服务器
带电的小王6 小时前
Windows中使用Qwen模型:VSCode+Cline
ide·vscode·ai编程·qwen
心一信息7 小时前
如何在Ubuntu上部署excalidraw
linux·运维·ubuntu
人生匆匆7 小时前
linux ext4缩容home,扩容根目录
linux·运维·服务器
Linux技术芯7 小时前
#Linux内存管理#缺页中断处理的核心函数是do_page_fault()的工作原理
linux
yuanzhengme8 小时前
Shell【脚本 02】离线安装配置Zookeeper及Kafka并添加service服务和开机启动(脚本分析)
linux·zookeeper·kafka·自动化·安装脚本
七月shi人8 小时前
【AI编程工具IDE/CLI/插件专栏】- 热门AI编程CLI初识与IDE对比
ide·人工智能·ai·ai编程