Go 调试插件
Go 调试插件
Go 插件调试
Go允许使用--buildmode=plugin
在unix系统上编译插件,得到.so文件。
此时如果直接在VSCode中调用Delve调试插件,会报错:plugin.Open failed: plugin was built with a different version of package
。
查阅VsCode-go的调试指南,发现local debug模式要求”The binary must be built with go build -gcflags=all=”-N -l” to disable inlining and optimizations that can interfere with debugging.”
故而我们需要在编译插件时,添加-gcflags=all="-N -l"
参数(可通过launch config中的prelaunchTask调用编译任务实现)。
VSCode配置
launch.json和tasks.json的配置如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch main",
"type": "go",
"request": "launch",
"program": "${workspaceFolder}/main.go",
"args": [],
"preLaunchTask": "build plugin"
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
{
"tasks": [
{
"label": "build plugin",
"type": "shell",
"command": "go build -gcflags=all=\"-N -l\" -o plugin.so -buildmode=plugin .",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
This post is licensed under CC BY 4.0 by the author.