Basic config
- install delve
- use debug config template in vscode
Debug with stdin input
The default delve debug mod doesn’t support stdin input. To tackle this issue, use the method of launching a delve debug server and attach program to debug server instead.
tasks.json
{
"tasks": [
{
"label": "Delve debug server",
"type": "shell",
"command": "cd \"${fileDirname}\" && source /etc/profile && ~/go/bin/dlv debug --headless --listen=:2346 --api-version=2",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": false
}
}
],
"version": "2.0.0"
}
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": "Go: Connect to dlv server",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "${workspaceFolder}",
"port": 2346,
"host": "127.0.0.1",
"internalConsoleOptions": "neverOpen"
}
]
}