目录
Delve 是一个专门为调试 go 程序而生的调试工具,它比 GDB 更强大,尤其时调试多 goroutine 高并发的 go 程序。文章源自编程技术分享-https://mervyn.life/d4defc41.html
安装 Delve
go get -u github.com/derekparker/delve/cmd/dlv
断点调试
启动调试
Devle 是一个非常棒的 go 调试工具,支持多种调试方式,直接运行调试,或者 attach 到一个正在运行中的 go 程序,进行调试。文章源自编程技术分享-https://mervyn.life/d4defc41.html
- 直接调试
通过dlv debug
命令进入调试环境
➜ demo dlv debug demo.go
Type 'help' for list of commands.
(dlv)
- 通过
attach
调试
例:
go build main.go
./main
# 通过 ps 命令查看对应程序的 pid
ps aux|grep main
dlv attach 29260
可用的调试命令
➜ demo dlv debug demo.go
Type 'help' for list of commands.
(dlv) help
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.
disassemble (alias: disass) - Disassembler.
down ------------------------ Move the current frame down.
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.
Type help followed by a command for full documentation.
文章源自编程技术分享-https://mervyn.life/d4defc41.html 我的微信公众号
微信扫一扫
评论