VScode 调试 linux内核

VScode 调试 linux内核

这里调试的 linux 内核是通过 Linux+SD卡(rootfs)运行的内核

gdb 命令行调试

编辑 /home/tyustli/.gdbinit 文件,参考 【GDB】 .gdbinit 文件

c 复制代码
set auto-load safe-path /home/tyustli/code/open_source/kernel/linux-6.5.7/.gdbinit

在 linux 源码项目的根目录新建 .gdbinit 文件

c 复制代码
target remote localhost:1234
b start_kernel
layout src
c

先启动 linux 内核,让其等待 GDB 连接

c 复制代码
# 启动之后等待 GDB 连接
sudo qemu-system-arm -M vexpress-a9 -m 512M -kernel arch/arm/boot/zImage -dtb arch/arm/boot/dts/arm/vexpress-v2p-ca9.dtb -nographic \
-append "root=/dev/mmcblk0 rw console=ttyAMA0" -sd /home/tyustli/code/open_source/busybox/rootfs.ext3 -s -S

# -dtb  指定设备树,否则会失败

在编译 linux 的当前路径输入

c 复制代码
arm-none-linux-gnueabihf-gdb vmlinux -se vmlinux

如果没有设置 /home/tyustli/.gdbinit 文件,那么对应的命令为

c 复制代码
arm-none-linux-gnueabihf-gdb vmlinux -se vmlinux -x .gdbinit

即指定 .gdbinit 的文件为当前路径。需要注意的是,如果指定了 /home/tyustli/.gdbinit 文件,就不能加 -x .gdbinit

调试界面信息

VScode 调试

参考 qemu基础篇------VSCode 配置 GDB 调试

要想调试 kernel 只需要再添加一个 kernel 的配置即可

c 复制代码
{
    "version": "0.2.0",
    "configurations": [
        {
            // qemu 裸机调试配置
            "name": "qemu_bare",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/qemu_code/bare/example/0020_mmu/bsp.elf",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}/qemu_code/bare",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/home/tyustli/cross_tool/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gdb",
            "miDebuggerServerAddress": "localhost:1234",
        },
        {   // u-boot 调试配置
            "name": "u-boot",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/open_source/u-boot/u-boot",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}/open_source/u-boot",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/home/tyustli/cross_tool/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gdb",
            "miDebuggerServerAddress": "localhost:1234",
        },
        {   // linux kernel 调试配置
        "name": "linux_kernel",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/open_source/kernel/linux-6.5.7/vmlinux",
        "args": [],
        "stopAtEntry": true,
        "cwd": "${workspaceFolder}/open_source/kernel/linux-6.5.7",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "/home/tyustli/cross_tool/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gdb",
        "miDebuggerServerAddress": "localhost:1234",
        }
    ]
}

有一点需要注意,如果使用 vscode 调试,就不能指定 /home/tyustli/.gdbinit 文件,或者将 /home/tyustli/code/open_source/kernel/linux-6.5.7/.gdbinit 文件的内容清空

先在 start_kernel打好断点

先启动 linux 内核,让其等待 GDB 连接

c 复制代码
# 启动之后等待 GDB 连接
sudo qemu-system-arm -M vexpress-a9 -m 512M -kernel arch/arm/boot/zImage -dtb arch/arm/boot/dts/arm/vexpress-v2p-ca9.dtb -nographic \
-append "root=/dev/mmcblk0 rw console=ttyAMA0" -sd /home/tyustli/code/open_source/busybox/rootfs.ext3 -s -S

启动调试

相关推荐
寄存器漫游者17 分钟前
Linux 软件编程 - IO 编程
linux·运维·spring
_别来无恙_34 分钟前
TFTP的使用Linux
linux·服务器
Zaralike44 分钟前
Linux 服务器网络不通排查 SOP(标准操作流程)
linux·服务器·网络
getapi1 小时前
注塑件的费用构成
linux·服务器·ubuntu
郝学胜-神的一滴2 小时前
深入解析C/S模型下的TCP通信流程:从握手到挥手的技术之旅
linux·服务器·c语言·网络·网络协议·tcp/ip
释怀不想释怀2 小时前
Linux网络基础(ip,域名)
linux·网络·tcp/ip
初願致夕霞2 小时前
Linux_进程
linux·c++
开开心心就好2 小时前
AI人声伴奏分离工具,离线提取伴奏K歌用
java·linux·开发语言·网络·人工智能·电脑·blender
lucky-billy2 小时前
Ubuntu 下一键部署 ROS2
linux·ubuntu·ros2
Thera7772 小时前
【Linux C++】彻底解决僵尸进程:waitpid(WNOHANG) 与 SA_NOCLDWAIT
linux·服务器·c++