VSCode Golang dlv調(diào)試數(shù)據(jù)截?cái)鄦?wèn)題及處理方法
使用VSCode對(duì)Golang程序進(jìn)行調(diào)試時(shí)會(huì)遇到數(shù)據(jù)截?cái)鄦?wèn)題,string只顯示前64個(gè)字符,array只顯示前64個(gè)數(shù)據(jù)。經(jīng)查dlv是支持以參數(shù)方式來(lái)控制的。
發(fā)現(xiàn)VSCode的Golang插件里面有個(gè)叫做go.delveConfig
的配置,是可以設(shè)置dlv參數(shù)的。分享一下我的整個(gè)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
這三個(gè)字段。
ps:下面看下Golang dlv 工具debug 調(diào)試注意項(xiàng)
總結(jié)一下關(guān)于Go 的調(diào)試工具dlv:https://github.com/derekparker/delve 的使用注意項(xiàng)。
安裝:
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服務(wù)為例:
dlv debug xxx.go
指定需要debug的文件- 進(jìn)入dlv交互式窗口后,
b <filename>:<line>
指定斷點(diǎn) - r arg 指定運(yùn)行參數(shù)
- n 執(zhí)行一行
- c 運(yùn)行至斷點(diǎn)或程序結(jié)束
dlv debug /home/xxx/server.go (dlv) b /home/xxx/server.go:258 (dlv) r 1 (dlv) n (dlv) c
注意: b <filename>:<line>
指定斷點(diǎn)時(shí),若該行號(hào)對(duì)應(yīng)的代碼內(nèi)容為無(wú)具體語(yǔ)義的代碼(括號(hào)、注釋等),則會(huì)報(bào)錯(cuò):
Command failed: could not find /home/xxx/server.go:258
此時(shí)可用list 命令先查看上下文代碼,避免將無(wú)具體語(yǔ)義的代碼設(shè)為斷點(diǎn)。
命令集
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.
總結(jié)
到此這篇關(guān)于VSCode Golang dlv調(diào)試數(shù)據(jù)截?cái)鄦?wèn)題及處理方法的文章就介紹到這了,更多相關(guān)VSCode Golang dlv調(diào)試數(shù)據(jù)截?cái)鄡?nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解Go語(yǔ)言中new和make關(guān)鍵字的區(qū)別
本篇文章來(lái)介紹一道非常常見的面試題,到底有多常見呢?可能很多面試的開場(chǎng)白就是由此開始的。那就是 new 和 make 這兩個(gè)內(nèi)置函數(shù)的區(qū)別,希望對(duì)大家有所幫助2023-03-03Go語(yǔ)言實(shí)現(xiàn)管理多個(gè)數(shù)據(jù)庫(kù)連接
在軟件開發(fā)過(guò)程中,使用?MySQL、PostgreSQL?或其他數(shù)據(jù)庫(kù)是很常見的,由于配置和要求不同,管理這些連接可能具有挑戰(zhàn)性,下面就來(lái)和大家聊聊如何在Go中管理多個(gè)數(shù)據(jù)庫(kù)連接吧2023-10-10GPT回答go語(yǔ)言和C語(yǔ)言map操作方法對(duì)比
這篇文章主要為大家介紹了GPT回答go語(yǔ)言和C語(yǔ)言map操作方法對(duì)比,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10Go語(yǔ)言操作MySql數(shù)據(jù)庫(kù)的詳細(xì)指南
數(shù)據(jù)的持久化是程序中必不可少的,所以編程語(yǔ)言中對(duì)數(shù)據(jù)庫(kù)的操作是非常重要的一塊,這篇文章主要給大家介紹了關(guān)于Go語(yǔ)言操作MySql數(shù)據(jù)庫(kù)的相關(guān)資料,需要的朋友可以參考下2023-10-10go local history本地歷史恢復(fù)代碼神器
這篇文章主要為大家介紹了go local history本地歷史恢復(fù)代碼神器的使用功能詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01Go錯(cuò)誤和異常CGO?fallthrough處理教程詳解
這篇文章主要為大家介紹了Go錯(cuò)誤和異常CGO?fallthrough使用教程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08Go 語(yǔ)言入門學(xué)習(xí)之正則表達(dá)式
這篇文章主要介紹了Go 語(yǔ)言入門學(xué)習(xí)之正則表達(dá)式,文章基于GO語(yǔ)言的相關(guān)資料展開詳細(xì)內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-04-04Golang?動(dòng)態(tài)腳本調(diào)研詳解
這篇文章主要為大家介紹了Golang?動(dòng)態(tài)腳本調(diào)研詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09