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 等操作即可,如下

相关推荐
python百炼成钢4 小时前
10.串口
linux·stm32·单片机·嵌入式硬件
Lzc7746 小时前
Linux网络的HTTPS
linux·https
我爱钱因此会努力7 小时前
ansible自动化运维入门篇
linux·运维·服务器·centos·自动化·ansible
better11208 小时前
IDE热键冲突的解决
ide
---学无止境---8 小时前
Linux中系统调用sys_symlink和sys_unlink函数的实现
linux
代码程序猿RIP8 小时前
【Etcd 】Etcd 详解以及安装教程
linux·数据库·etcd
tb_first9 小时前
Linux入门1(2/2)
linux
cellurw9 小时前
Day72 传感器分类、关键参数、工作原理与Linux驱动开发(GPIO/I²C/Platform/Misc框架)
linux·c语言·驱动开发
NextZeros9 小时前
基于CentOS安装LNMP
linux·centos
梁萌9 小时前
Linux安装mysql8.4.6
linux·运维·mysql安装·8.4.6