VSCode Golang dlv调试数据截断问题及处理方法
使用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
这三个字段。
参考:
ps:下面看下golang dlv 工具debug 调试注意项
总结一下关于go 的调试工具dlv:https://github.com/derekparker/delve 的使用注意项。
安装:
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.
continue (alias: c) --------- run until breakpoint or program termination.
deferred -------------------- executes command in the context of a deferred call.
disassemble (alias: disass) - disassembler.
down ------------------------ move the current frame down.
edit (alias: ed) ------------ open where you are in $delve_editor or $editor
exit (alias: quit | q) ------ exit the debugger.
frame ----------------------- set the current frame, or execute command on a different frame.
funcs ----------------------- print list of functions.
goroutine ------------------- shows or changes current goroutine
goroutines ------------------ list program goroutines.
help (alias: h) ------------- prints the help message.
list (alias: ls | l) -------- show source code.
locals ---------------------- print local variables.
next (alias: n) ------------- step over to next source line.
on -------------------------- executes a command when a breakpoint is hit.
print (alias: p) ------------ evaluate an expression.
regs ------------------------ print contents of cpu registers.
restart (alias: r) ---------- restart process.
set ------------------------- changes the value of a variable.
source ---------------------- executes a file containing a list of delve commands
sources --------------------- print list of source files.
stack (alias: bt) ----------- print stack trace.
step (alias: s) ------------- single step through program.
step-instruction (alias: si) single step a single cpu instruction.
stepout --------------------- step out of the current function.
thread (alias: tr) ---------- switch to the specified thread.
threads --------------------- print out info for every traced thread.
trace (alias: t) ------------ set tracepoint.
types ----------------------- print list of types
up -------------------------- move the current frame up.
vars ------------------------ print package variables.
whatis ---------------------- prints type of an expression.
总结
到此这篇关于vscode golang dlv调试数据截断问题及处理方法的文章就介绍到这了,更多相关vscode golang dlv调试数据截断内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
下一篇: Python命名空间及作用域原理实例解析