使用VSCode对Golang程序进行调试时会遇到数据截断问题,string只显示前64个字符,array只显示前64个数据。经查dlv是支持以参数方式来控制的。
发现VSCode的Golang插件里面有个叫做go.delveConfig的配置,是可以设置dlv参数的。分享一下我的整个Golang配置:
"go.buildOnSave": "off",
"go.formatTool": "goimports",
"go.lintTool": "golangci-lint", //go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
"go.autocompleteUnimportedPackages": true,
"go.gotoSymbol.includeImports": true,
"go.useLanguageServer": true,
"go.delveConfig": {
"dlvLoadConfig": {
"followPointers": true,
"maxVariableRecurse": 3,
"maxStringLen": 1024,
"maxArrayValues": 1024,
"maxStructFields": -1
},
},
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
需要改的主要是maxStringLen、maxArrayValues、maxVariableRecurse这三个字段。
参考:https://www.easck.com/d/file/200624/191120200624180009
ps:下面看下Golang dlv 工具debug 调试注意项
总结一下关于Go 的调试工具dlv:https://www.easck.com/d/file/200624/191820200624180011 的使用注意项。
安装:
go get -u github.com/go-delve/delve/cmd/dlv
配置:
以Centos为例
export GOROOT=/usr/lib/golang export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin
使用
以某go服务为例:
dlv debug xxx.go 指定需要debug的文件
进入dlv交互式窗口后,b <filename>:<line> 指定断点
r arg 指定运行参数
n 执行一行
c 运行至断点或程序结束
dlv debug /home/xxx/server.go (dlv) b /home/xxx/server.go:258 (dlv) r 1 (dlv) n (dlv) c
注意: b <filename>:<line> 指定断点时,若该行号对应的代码内容为无具体语义的代码(括号、注释等),则会报错:
Command failed: could not find /home/xxx/server.go:258
此时可用list 命令先查看上下文代码,避免将无具体语义的代码设为断点。
命令集
The following commands are available:
args ------------------------ Print function arguments.
break (alias: b) ------------ Sets a breakpoint.
breakpoints (alias: bp) ----- Print out info for active breakpoints.
call ------------------------ Resumes process, injecting a function call (EXPERIMENTAL!!!)
clear ----------------------- Deletes breakpoint.
clearall -------------------- Deletes multiple breakpoints.
condition (alias: cond) ----- Set breakpoint condition.
config ---------------------- Changes configuration parameters.










