Debugging 在VisualStudio代码和Delve调试器中使用标记进行调试
回答: 基于putus的回答,我想出了以下配置,只需单击一下即可构建和调试 首先,您需要添加一个任务来构建带有相应标记的二进制文件Debugging 在VisualStudio代码和Delve调试器中使用标记进行调试,debugging,go,visual-studio-code,Debugging,Go,Visual Studio Code,回答: 基于putus的回答,我想出了以下配置,只需单击一下即可构建和调试 首先,您需要添加一个任务来构建带有相应标记的二进制文件 { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "0.1.0", "command": "bash", "isShellCommand": true,
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args": [""],
"showOutput": "always",
"tasks": [
{
"taskName": "buildBinWithTag",
"command": "go",
"args": ["build", "-o", "BinaryName", "-tags", "THISISATAG"],
"isShellCommand": true
}
]
}
此任务应在调试器启动之前执行
{
"version": "0.2.0",
"configurations": [
{
"name": "DebugBinWithTag", //added config
"type": "go",
"request": "launch",
"mode": "exec",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}/BinaryName",
"env": {},
"args": [],
"showLog": true,
"preLaunchTask": "buildBinWithTag"
}
]
}
原始问题:我正在使用构建标记编译Go程序的不同版本,并使用“Go构建-标记THISISAFLAG”进行编译
这很好用。但是有没有办法告诉调试器使用这些标志呢。我尝试过使用如下的启动配置,但没有成功
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {},
"args": ["-flags THISISAFLAG"],
"showLog": true
}
]
}
您可以将预构建的二进制文件附加到调试器
go Build-o myapp.exe-tags THISISAFLAG
Launch Exe
添加到Launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Debug", //existing config
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {},
"args": [],
"showLog": true
},
{
"name": "Launch EXE", //added config
"type": "go",
"request": "launch",
"mode": "exec",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}/myapp.exe",
"env": {},
"args": [],
"showLog": true
}
]
}
-gcflags='-N-l'
,以禁用编译器优化
现在支持名为buildFlags
的launch.json
键,该键允许您使用相应的值“-tags Tag”
指定构建标记。(似乎有。)
相关:
如果您的构建需要构建标记(例如go build-tags which_tag),则添加参数buildFlags,内容为“-tags which_tag”
如果您有不同的构建配置,每个构建配置都需要自己的构建标记,那么您可以为每个构建配置创建单独的启动配置
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Debug", //existing config
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {},
"args": [],
"showLog": true
},
{
"name": "Launch EXE", //added config
"type": "go",
"request": "launch",
"mode": "exec",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}/myapp.exe",
"env": {},
"args": [],
"showLog": true
}
]
}