在vscode中以root权限调试程序

简单记录

参考:How can I debug Go file in VS Code with root privileges?

贴一下自己的配置:

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
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch test function",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}/naming",
"env": {
//"key":value
},
"args": [
"-test.run",
"TestBlaBlaFunc" //修改为对应的单测函数名
]
},
{
"name": "Test/dbg pkg as root",
"type": "go",
"request": "launch",
"mode": "debug",
"env": {
//"key":value
},
"program": "${workspaceFolder}",
"console": "integratedTerminal",
"asRoot": true
}
]
}

启动时选择 Test/dbg pkg as root 就可以用 vscode 在 root 下调试项目了。

同时另附了调试单测的配置,选择 Launch test function 即可。