当前位置:   article > 正文

VScode 调试 linux内核_vscode 调试 linux 内核

vscode 调试 linux 内核

VScode 调试 linux内核

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

gdb 命令行调试

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

set auto-load safe-path /home/tyustli/code/open_source/kernel/linux-6.5.7/.gdbinit
  • 1

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

target remote localhost:1234
b start_kernel
layout src
c
  • 1
  • 2
  • 3
  • 4

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

# 启动之后等待 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  指定设备树,否则会失败
  • 1
  • 2
  • 3
  • 4
  • 5

在编译 linux 的当前路径输入

arm-none-linux-gnueabihf-gdb vmlinux -se vmlinux
  • 1

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

arm-none-linux-gnueabihf-gdb vmlinux -se vmlinux -x .gdbinit
  • 1

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

调试界面信息
在这里插入图片描述

VScode 调试

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

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

{
    "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",
        }
    ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

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

先在 start_kernel打好断点
在这里插入图片描述
先启动 linux 内核,让其等待 GDB 连接

# 启动之后等待 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
  • 1
  • 2
  • 3

启动调试
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/239883?site
推荐阅读
相关标签
  

闽ICP备14008679号