VScode debugging linux kernel

VScode debugging linux kernel

The linux kernel debugged here is the kernel running through Linux+SD card (rootfs)

gdb command line debugging

edit /home/tyustli/.gdbinit text, reference [GDB] .gdbinit text

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

Create a new .gdbinit file in the root directory of the linux source project

target remote localhost:1234
b start_kernel
layout src
c

Start the linux kernel first and let it wait for GDB connection

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

Enter in the current path of compiling linux

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

If the /home/tyustli/.gdbinit file is not set, then the corresponding command is

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

specifies the .gdbinit file as the current path. It should be noted that if /home/tyustli/.gdbinit file is specified, cannot be added-x .gdbinit

Debugging interface information
Insert image description here

VScode debugging

Reference qemu basics - VSCode configuration GDB debugging

To debug the kernel, you only need to add another kernel configuration.

{
    
    
    "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",
        }
    ]
}

One thing to note is that if you use vscode to debug, you cannot specify the /home/tyustli/.gdbinit file or clear the contents of the /home/tyustli/code/open_source/kernel/linux-6.5.7/.gdbinit file

First set a breakpoint First start the linux kernel and let it wait for GDB connectionstart_kernel
Insert image description here

# 启动之后等待 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

Start debugging
Insert image description here

Guess you like

Origin blog.csdn.net/tyustli/article/details/134096376