设为首页收藏本站
网站公告 | 这是第一条公告
     

 找回密码
 立即注册
缓存时间15 现在时间15 缓存数据 一个人挺好的

一个人挺好的 -- 一个

查看: 1332|回复: 3

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

[复制链接]

  离线 

TA的专栏

  • 打卡等级:热心大叔
  • 打卡总天数:226
  • 打卡月天数:0
  • 打卡总奖励:3430
  • 最近打卡:2025-03-31 16:22:49
等级头衔

等級:晓枫资讯-上等兵

在线时间
0 小时

积分成就
威望
0
贡献
384
主题
365
精华
0
金钱
4613
积分
807
注册时间
2023-1-9
最后登录
2025-3-31

发表于 2023-6-13 09:58:37 | 显示全部楼层 |阅读模式
使用VSCode对Golang程序进行调试时会遇到数据截断问题,string只显示前64个字符,array只显示前64个数据。经查dlv是支持以参数方式来控制的。
发现VSCode的Golang插件里面有个叫做
  1. go.delveConfig
复制代码
的配置,是可以设置dlv参数的。分享一下我的整个Golang配置:
  1. "go.buildOnSave": "off",
  2.   "go.formatTool": "goimports",
  3.   "go.lintTool": "golangci-lint", //go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
  4.   "go.autocompleteUnimportedPackages": true,
  5.   "go.gotoSymbol.includeImports": true,
  6.   "go.useLanguageServer": true,
  7.   "go.delveConfig": {
  8.     "dlvLoadConfig": {
  9.       "followPointers": true,
  10.       "maxVariableRecurse": 3,
  11.       "maxStringLen": 1024,
  12.       "maxArrayValues": 1024,
  13.       "maxStructFields": -1
  14.     },
  15.   },
  16.   "[go]": {
  17.     "editor.formatOnSave": true,
  18.     "editor.codeActionsOnSave": {
  19.       "source.organizeImports": true
  20.     }
  21.   },
复制代码
需要改的主要是
  1. maxStringLen
复制代码
  1. maxArrayValues
复制代码
  1. maxVariableRecurse
复制代码
这三个字段。
参考: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 的使用注意项。
安装:
  1. go get -u github.com/go-delve/delve/cmd/dlv
复制代码
配置:
以Centos为例
  1. export GOROOT=/usr/lib/golang
  2. export GOPATH=$HOME/go
  3. export PATH=$PATH:$GOPATH/bin
复制代码
使用
以某go服务为例:
      
    1. dlv debug xxx.go
    复制代码
    指定需要debug的文件  
  • 进入dlv交互式窗口后,
    1. b <filename>:<line>
    复制代码
    指定断点  
  • r arg 指定运行参数  
  • n 执行一行  
  • c 运行至断点或程序结束
  1. dlv debug /home/xxx/server.go
  2. (dlv) b /home/xxx/server.go:258
  3. (dlv) r 1
  4. (dlv) n
  5. (dlv) c
复制代码
注意:
  1. b <filename>:<line>
复制代码
指定断点时,若该行号对应的代码内容为无具体语义的代码(括号、注释等),则会报错:
  1. 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调试数据截断内容请搜索晓枫资讯以前的文章或继续浏览下面的相关文章希望大家以后多多支持晓枫资讯!

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
晓枫资讯-科技资讯社区-免责声明
免责声明:以上内容为本网站转自其它媒体,相关信息仅为传递更多信息之目的,不代表本网观点,亦不代表本网站赞同其观点或证实其内容的真实性。
      1、注册用户在本社区发表、转载的任何作品仅代表其个人观点,不代表本社区认同其观点。
      2、管理员及版主有权在不事先通知或不经作者准许的情况下删除其在本社区所发表的文章。
      3、本社区的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,举报反馈:点击这里给我发消息进行删除处理。
      4、本社区一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
      5、以上声明内容的最终解释权归《晓枫资讯-科技资讯社区》所有。
http://bbs.yzwlo.com 晓枫资讯--游戏IT新闻资讯~~~

  离线 

TA的专栏

等级头衔

等級:晓枫资讯-列兵

在线时间
0 小时

积分成就
威望
0
贡献
0
主题
0
精华
0
金钱
38
积分
20
注册时间
2022-12-24
最后登录
2022-12-25

发表于 2024-12-9 19:35:29 | 显示全部楼层
顶顶更健康!!!
http://bbs.yzwlo.com 晓枫资讯--游戏IT新闻资讯~~~

  离线 

TA的专栏

  • 打卡等级:无名新人
  • 打卡总天数:1
  • 打卡月天数:0
  • 打卡总奖励:9
  • 最近打卡:2025-03-19 04:09:40
等级头衔

等級:晓枫资讯-列兵

在线时间
0 小时

积分成就
威望
0
贡献
0
主题
0
精华
0
金钱
23
积分
8
注册时间
2023-10-31
最后登录
2025-3-19

发表于 2024-12-21 21:27:53 | 显示全部楼层
感谢楼主分享。
http://bbs.yzwlo.com 晓枫资讯--游戏IT新闻资讯~~~

  离线 

TA的专栏

等级头衔

等級:晓枫资讯-列兵

在线时间
0 小时

积分成就
威望
0
贡献
0
主题
0
精华
0
金钱
21
积分
22
注册时间
2022-12-27
最后登录
2022-12-27

发表于 2025-4-20 00:09:38 | 显示全部楼层
感谢楼主,顶。
http://bbs.yzwlo.com 晓枫资讯--游戏IT新闻资讯~~~
严禁发布广告,淫秽、色情、赌博、暴力、凶杀、恐怖、间谍及其他违反国家法律法规的内容。!晓枫资讯-社区
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1楼
2楼
3楼
4楼

手机版|晓枫资讯--科技资讯社区 本站已运行

CopyRight © 2022-2025 晓枫资讯--科技资讯社区 ( BBS.yzwlo.com ) . All Rights Reserved .

晓枫资讯--科技资讯社区

本站内容由用户自主分享和转载自互联网,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。

如有侵权、违反国家法律政策行为,请联系我们,我们会第一时间及时清除和处理! 举报反馈邮箱:点击这里给我发消息

Powered by Discuz! X3.5

快速回复 返回顶部 返回列表