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语言fmt.Sprintf格式化输出的语法与实例

    Go语言fmt.Sprintf格式化输出的语法与实例

    Go 可以使用 fmt.Sprintf 来格式化字符串,下面这篇文章主要给大家介绍了关于Go语言fmt.Sprintf格式化输出的语法与实例,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-07-07
  • gin自定义中间件解决requestBody不可重复读问题(最新推荐)

    gin自定义中间件解决requestBody不可重复读问题(最新推荐)

    这篇文章主要介绍了gin自定义中间件解决requestBody不可重复读问题,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-04-04
  • Golang信号量设计实现示例详解

    Golang信号量设计实现示例详解

    这篇文章主要为大家介绍了Golang信号量设计实现示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-08-08
  • golang中json的omitempty使用操作

    golang中json的omitempty使用操作

    这篇文章主要介绍了golang中json的omitempty使用操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-12-12
  • Go语言深度拷贝工具deepcopy的使用教程

    Go语言深度拷贝工具deepcopy的使用教程

    今天给大家推荐的工具是deepcopy,一个可以对指针、接口、切片、结构体、Map都能进行深拷贝的工具,感兴趣的小伙伴快跟随小编一起学习学习
    2022-09-09
  • Golang嵌入资源文件实现步骤详解

    Golang嵌入资源文件实现步骤详解

    在应用程序中附带代码以外的其他资源可能会很有用,常用的实现方法是嵌入对象或数据。在数据库中存储数据应用中,需要定义schema,在应用启动时创建表,但如果找不到schema文件呢?Go1.16提供embed包让实现变得简单,之前很多第三方包实现类似功能
    2023-01-01
  • 详解Go语言微服务开发框架之Go chassis

    详解Go语言微服务开发框架之Go chassis

    分布式系统中每个进程的动态配置管理及运行时热加载就成为了一个亟待解决的问题。go chassis汲取了netflix的archaius框架经验,并做出来自己的创新特性。
    2021-05-05
  • Go语言针对Map的11问你知道几个?

    Go语言针对Map的11问你知道几个?

    Go Map 的 11 连问,你顶得了嘛?这篇文章小编为大家准备了 Go 语言 Map 的 11 连问,相信大家看完肯定会有帮助的,感兴趣的小伙伴可以收藏一波
    2023-05-05
  • golang sync.Cond同步机制运用及实现

    golang sync.Cond同步机制运用及实现

    在 Go 里有专门为同步通信而生的 channel,所以较少看到 sync.Cond 的使用,不过它也是并发控制手段里的一种,今天我们就来认识下它的相关实现,加深对同步机制的运用
    2023-09-09
  • Golang 函数执行时间统计装饰器的一个实现详解

    Golang 函数执行时间统计装饰器的一个实现详解

    这篇文章主要介绍了Golang 函数执行时间统计装饰器的一个实现详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-03-03

最新评论