Loading

go使用root用户进行调试

需求

本地调试go程序,但涉及硬件操作需要用root用户执行。
需要sudo的同时支持端点调试。

方法

修改launch.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": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}",
            "args": [],
            "asRoot": true,
            "console": "integratedTerminal"
        }
    ]
}

注意:参数asRoot需要和console配合使用。

参考

Option for launch.json to debug as sudo. · Issue #2302 · golang/vscode-go

posted @ 2025-10-10 16:58  azureology  阅读(5)  评论(0)    收藏  举报