VSCode Golang dlv调试数据截断问题及处理方法
怎么入门Golang编程?需要学习哪些知识点?这是新手们刚接触编程时常见的问题;下面golang学习网就来给大家整理分享一些知识点,希望能够给初学者一些帮助。本篇文章就来介绍《VSCode Golang dlv调试数据截断问题及处理方法》,涉及到vscode、数据、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指定断点: - 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 指定断点时,若该行号对应的代码内容为无具体语义的代码(括号、注释等),则会报错:
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调试数据截断问题及处理方法》的详细内容,更多关于golang的资料请关注golang学习网公众号!
Golang 限流器的使用和实现示例
- 上一篇
- Golang 限流器的使用和实现示例
- 下一篇
- 从go语言中找&和*区别详解
-
- 欢喜的泥猴桃
- 受益颇多,一直没懂这个问题,但其实工作中常常有遇到...不过今天到这,帮助很大,总算是懂了,感谢作者大大分享文章!
- 2023-02-12 09:00:31
-
- 悦耳的小猫咪
- 这篇博文出现的刚刚好,太详细了,写的不错,码起来,关注楼主了!希望楼主能多写Golang相关的文章。
- 2023-02-11 06:07:01
-
- 大气的花卷
- 写的不错,一直没懂这个问题,但其实工作中常常有遇到...不过今天到这,帮助很大,总算是懂了,感谢博主分享文章!
- 2023-02-07 23:46:47
-
- 天真的小鸭子
- 这篇文章内容真是及时雨啊,大佬加油!
- 2023-02-04 07:55:25
-
- 疯狂的夕阳
- 这篇博文出现的刚刚好,细节满满,赞 ??,码起来,关注作者大大了!希望作者大大能多写Golang相关的文章。
- 2023-02-04 00:46:29
-
- 热情的草莓
- 太细致了,mark,感谢up主的这篇文章内容,我会继续支持!
- 2023-01-29 09:02:57
-
- 舒适的芹菜
- 很详细,收藏了,感谢师傅的这篇文章,我会继续支持!
- 2023-01-21 08:44:18
-
- 沉静的睫毛
- 很好,一直没懂这个问题,但其实工作中常常有遇到...不过今天到这,帮助很大,总算是懂了,感谢师傅分享博文!
- 2023-01-16 15:25:34
-
- 幽默的狗
- 这篇技术贴真及时,好细啊,写的不错,收藏了,关注楼主了!希望楼主能多写Golang相关的文章。
- 2023-01-13 21:07:22
-
- 欣喜的柠檬
- 这篇文章内容出现的刚刚好,太细致了,赞 ??,收藏了,关注up主了!希望up主能多写Golang相关的文章。
- 2023-01-08 22:50:59
-
- Golang · Go教程 | 6小时前 | go · testing · CI · Go 1.26 testing.ArtifactDir 测试产物
- Go 1.26 testing.ArtifactDir 怎么留测试产物:-artifacts 与临时目录取舍
- 497浏览 收藏
-
- Golang · Go教程 | 7小时前 | Go教程 · 性能排查 · 运行时指标 · Go GOMAXPROCS runnable Go 1.26 runtime/metrics waiting
- Go 1.26 runtime/metrics 调度指标怎么选:runnable、waiting 与线程数的诊断边界
- 405浏览 收藏
-
- Golang · Go教程 | 8小时前 | go · 工程实践 · Go Modules · require go.mod Go 1.27 go mod tidy
- Go 1.27 go.mod 重复 require 怎么收口:direct 与 indirect 分组的可验证结果
- 331浏览 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 543次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 516次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 500次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 485次学习
-
- SuperCLUE
- SuperCLUE是权威的中文大语言模型综合评测基准,涵盖语言理解、知识应用、AI Agent智能体及安全性等12项核心能力。通过多轮对话与客观测试,定期发布榜单与技术报告,为模型研发、优化及行业选型提供科学依据。
- 125次使用
-
- C-Eval
- 深入了解C-Eval中文评估套件,涵盖52个学科与4级难度。本文详解其功能特点、Zero-shot/Few-shot使用方法及代码示例,助您全面评测LLM中文理解与泛化能力。
- 42次使用
-
- Google AI提示词库
- 探索Google Cloud官方生成式AI提示词库,提供免费、无需登录的中英双语Prompt模板。涵盖内容创作、代码优化、数据分析等场景,助您快速提升AI交互效率与质量。
- 19次使用
-
- Gradio
- Gradio是一个用于构建机器学习和数据科学Web应用的开源Python库。支持快速创建交互界面,获Google、Meta等大厂青睐,适合模型演示、部署反馈及调试。
- 125次使用
-
- AgentGPT
- 深入了解AgentGPT:一款基于浏览器的自主人工智能代理工具。本文解析其核心功能、技术栈、应用场景,并提供详细的在线使用及本地部署教程,助您高效利用AI自动化完成任务。
- 18次使用
-
- windows下使用vscode搭建golang环境并调试的过程
- 2022-12-28 194浏览
-
- Golang中map数据类型的使用方法
- 2022-12-30 443浏览
-
- 一文详解Golang中的切片数据类型
- 2022-12-31 171浏览
-
- Go 编程复杂数据类型 Map
- 2023-01-01 306浏览
-
- Go语言中的数据格式(json、xml 、msgpack、protobuf)使用总结
- 2022-12-28 264浏览

