VSCode Golang dlv调试数据截断问题及处理方法

 更新时间:2020年06月24日 14:12:51   作者:FanZheng''s Debug Blog  
这篇文章主要介绍了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
    }
  },

需要改的主要是maxStringLenmaxArrayValuesmaxVariableRecurse这三个字段。

参考:https://stackoverflow.com/questions/52416263/how-do-i-print-the-full-value-of-a-string-variable-in-delve

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调试数据截断内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • 详解如何修改Go结构体的私有字段

    详解如何修改Go结构体的私有字段

    在 Go 语言中,结构体字段的访问权限是由字段名的首字母决定的:首字母大写表示公共字段(public),首字母小写表示私有字段(private),本文给大家介绍了如何修改Go结构体的私有字段,需要的朋友可以参考下
    2025-01-01
  • Go实现set类型的示例代码

    Go实现set类型的示例代码

    本文主要介绍了Go实现set类型的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-01-01
  • 详解Go语言中如何高效地处理集合

    详解Go语言中如何高效地处理集合

    在 Go 语言中,虽然没有像 Java 或 Python 那样的传统集合框架,但也可以非常高效地处理集合操作,下面小编就来和大家讲讲具体处理方法吧
    2025-01-01
  • golang去除多余的空格与换行符示例代码

    golang去除多余的空格与换行符示例代码

    Golang是一种强大的编程语言,提供了丰富的字符串处理功能,这篇文章主要给大家介绍了关于golang去除多余的空格与换行符的相关资料,需要的朋友可以参考下
    2023-10-10
  • VSCode1.4 搭建Golang的开发调试环境(遇到很多问题)

    VSCode1.4 搭建Golang的开发调试环境(遇到很多问题)

    这篇文章主要介绍了VSCode1.4 搭建Golang的开发调试环境(遇到很多问题),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-04-04
  • go语言实现LRU缓存的示例代码

    go语言实现LRU缓存的示例代码

    LRU是一种常见的缓存淘汰策略,用于管理缓存中的数据,本文主要介绍了go语言实现LRU缓存的示例代码,具有一定的参考价值,感兴趣的可以了解一下
    2024-02-02
  • go语言实现一个简单的http客户端抓取远程url的方法

    go语言实现一个简单的http客户端抓取远程url的方法

    这篇文章主要介绍了go语言实现一个简单的http客户端抓取远程url的方法,实例分析了Go语言http操作技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-03-03
  • Golang生成Excel文档的方法步骤

    Golang生成Excel文档的方法步骤

    生成Excel是一个很常见的需求,本文将介绍如何使用Go的 Excelize库去生成Excel文档,以及一些具体场景下的代码实现,感兴趣的可以参考一下
    2021-06-06
  • GoFrame gmap遍历hashmap listmap treemap使用技巧

    GoFrame gmap遍历hashmap listmap treemap使用技巧

    这篇文章主要为大家介绍了GoFrame gmap遍历hashmap listmap treemap使用技巧的示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-06-06
  • Go log库的使用示例详解

    Go log库的使用示例详解

    Go语言内置的log库提供了基本的日志记录功能,支持日志的格式化输出、设置日志前缀、配置输出位置等,可以通过标准logger或创建新的Logger对象来使用,log库简单易用,但功能有限,可能需要配合第三方日志库如logrus、zap等来满足复杂需求
    2024-09-09

最新评论