go_vscode_debug

89 阅读1分钟

调试配置

  1. go 源代码

//调试

{
	"name": "Debug ***",
	"type": "go",
	"request": "launch",
	"mode": "debug", // 调试模式(自动检测或指定)
	"program": "${workspaceFolder}/apps/eapd/main.go", // 可执行文件路径
	"args": [ // 命令行参数(需拆分为数组元素)
		"-service-hostname=127.0.0.1",
		"-port=9502",
		"-etcd-endpoints=http://127.0.0.1:9597",
		"-etcd-user=***",
		"-etcd-password=*****",
		"-database-driver=PostgreSQL Unicode(x64)",
		"-affinity-label=",
		"-anti-affinity-label=",
		"-redirect-stderr=yes",
		"--debug=yes"
	],
	"env": {}, // 如需环境变量,可在此添加(如 ETCD 配置可能依赖环境变量)
	"cwd": "${workspaceFolder}", // 工作目录
	"buildFlags": "", // 编译选项(如需要优化或调试符号)
	"showLog": true // 显示调试日志(可选)
}
  1. go 二进制

//前提:带调试信息

go build -gcflags="-N -l" -o D:/path/to/**.exe

//调试二进制

{
    "name": "Debug ** (Binary)",
    "type": "go",
    "request": "launch",
    "mode": "exec", // 指定调试已编译的二进制
    "program": "${workspaceFolder}/bin/**.exe", // 绝对路径(注意转义)
    "args": [ // 命令行参数(拆分为数组元素)
        "-service-hostname=127.0.0.1",
        "-port=9502",
        "-etcd-endpoints=http://127.0.0.1:9597",
        "-etcd-user=caxaplm",
        "-etcd-password=***",
        "-database-driver=PostgreSQL Unicode(x64)",
        "-affinity-label=",
        "-anti-affinity-label=",
        "-redirect-stderr=yes",
        "--debug=yes"
    ],
    "cwd": "${workspaceFolder}",
    "dlvFlags": ["--check-go-version=false"], // 忽略版本检查(可选)
    "buildFlags": "" // 无需编译,直接调试
}
  1. 附加

//前提:带调试信息

go build -gcflags="-N -l" -o D:/path/to/**.exe
 {
    "name": "Attach to Process",
    "type": "go",
    "request": "attach",
    "mode": "local",
    "processId": "${command:pickProcess}",   //弹出进程搜索框
 },

vscode 调试速度优化

  1. Search:Follow Symlinks 去掉勾选

image.png

  1. 去掉 git svn Git:Autorefresh

image.png

(25 封私信) vscode中debug过慢问题 - 知乎

调试错误

  1. Couldn't start dhv dap
"debugAdapter": "legacy",

错误:Couldn't start dhv dap:
Error: timed out while waiting for DAp server to start

vscode 更新后报错 Couldn‘t start dlv dap_couldn't start dlv dap-CSDN博客