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

相关推荐
EmbedLinX21 小时前
嵌入式之协议解析
linux·网络·c++·笔记·学习
vortex521 小时前
解密UUOC:Shell编程中“无用的cat使用”详解
linux·shell编程
wangjialelele21 小时前
Linux中的进程管理
java·linux·服务器·c语言·c++·个人开发
杜子不疼.21 小时前
【Linux】库制作与原理(二):动态库的制作与使用
linux·运维·服务器
森焱森21 小时前
嵌入式硬件工程师应知 白银快速分析报告
linux·c语言·arm开发·嵌入式硬件·去中心化
RisunJan1 天前
Linux命令-lpq(查看打印队列状态)
linux·运维·服务器
山君爱摸鱼1 天前
Linux-服务进程
linux·运维·服务器
阿乐艾官1 天前
【linux文件系统重要目录及命令解释】
linux·运维·服务器
blueSatchel1 天前
U-Boot启动后做的事情
linux·u-boot
senijusene1 天前
Linux软件编程: Linux 操作系统基础与shell脚本
linux·运维·chrome