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

相关推荐
ltl7 小时前
存储性能建模:IOPS、吞吐与延迟
linux
刘某的Cloud8 小时前
ceph osd 导入导出 rbd volume 卷
linux·运维·ceph·volume
酸菜。10 小时前
dw_axi_dmac总结
linux
神奇霸王龙10 小时前
Agent 准入门控屠夫:5 旗舰 4 维度评估
linux·运维·数据库·ai·ai作画·agent·ai编程
小绫网络安全13 小时前
Kali Linux渗透测试入门教程:从零搭建到实战攻防
linux·运维·服务器
allforgood13 小时前
控制启动过程
linux·运维·服务器
西安景驰电子13 小时前
《PTP精确时间协议系列》第一篇:从原理到应用,全面解读IEEE 1588
linux·运维·服务器·开发语言·网络·windows·php
猫吃了源码14 小时前
k9s简介和安装
linux·docker·kubernetes
小马同学-15 小时前
高可用-Keepalived全解析
linux·运维
Forever Nore16 小时前
LeetCode 13 罗马数字转整数 - 按规则处理
linux·服务器·leetcode