vscode添加RISC-V调试支持

vscode 前置

  1. 安装C/C++插件
  2. 开启Allow Breakpoints Everywhere Vscode 在汇编文件中添加调试断点
  3. Makefile中添加ASFLAGS = -g

    vscode文件设置

    在workspace下.vscode下新建启动文件与任务文件launch.json, tasks.json

    launch.json

    miDebuggerPath 填riscv-gdb绝对路径,program填要调的程序

    {
    // 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": "Debug RISC-V",
            "type": "cppdbg",
            "request": "launch",
            "program":"${workspaceFolder}/demo.elf",
            "cwd": "${workspaceFolder}",
            "miDebuggerPath": "/opt/toolchains/riscv/bin/riscv64-unknown-elf-gdb",
            "miDebuggerServerAddress": "localhost:1234",
            "stopOnEntry": true,
            "preLaunchTask": "Run QEMU"
        }
    ]
    }

    tasks.json

command中修改调试器启动参数,修改对应启动elf文件。不要删除前面的一条命令echo 'QEMU started',这个是为了让vscode结束启动等待用

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build",
            "type": "shell",
            "command": "make",
            "args": [
                ""
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "label": "Run QEMU",
            "type": "shell",
            "command": "echo 'QEMU started';qemu-system-riscv64 -s -S -machine virt -bios none -kernel demo.elf -m 128M -serial mon:stdio -device bochs-display",
            "dependsOn": ["Build"],
            "args": [],
            "group": {
                "kind": "test",
                "isDefault": true
            },
            "isBackground": true,
            "problemMatcher": [
                {
                    "pattern": [
                        {
                            "regexp": ".",
                            "file": 1,
                            "location": 2,
                            "message": 3
                        }
                    ],
                    "background": {
                        "activeOnStart": true,
                        "beginsPattern": ".",
                        "endsPattern": ".",
                    }
                }
            ]
        }
    ]
}

Leave a Reply

Your email address will not be published. Required fields are marked *